Expected singleton: stock.move - Odoo v9 community

2024/10/15 23:25:48

I'm creating a stock.picking from fleet_vehicle_log_services with this method:

@api.multi
def create_picking(self):self.ensure_one()vals = {'move_lines': self.move_lines.id,'origin': self.name}picking = self.env['stock.picking'].create(vals)return picking

And it's declared on fields like this:

move_lines = fields.One2many('stock.move', 'picking_id', string="Stock Moves", copy=True)

And my view:

    <group string="Datos del picking"><button name="create_picking" string="Crear Picking" type="object" class="oe_highlight"/><tree><field name="move_lines" string="Lineas"/><field name="state" invisible="1"/></tree></group>

When I click on create the picking it throws me this:

Traceback (most recent call last):
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 648, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 321, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 314, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 964, in __call__
return self.method(*args, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 514, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/web/controllers/main.py", line 892, in call_button
action = self._call_kw(model, method, args, {})
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/web/controllers/main.py", line 880, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 381, in old_api
result = method(recs, *args, **kwargs)
File "/home/kristian/odoov9/danisan/fleet_stock/models/fleet_vehicle_services.py", line 215, in create_picking
'move_lines': self.move_lines.id,
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/fields.py", line 2030, in __get__
return record.ensure_one()._ids[0]
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/models.py", line 5420, in ensure_one
raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: stock.move(45, 68)

Any ideas?

Answer

One2many fields need special commands for inserting. In your case:

 vals = {'move_lines': [(6, 0, self.move_lines.ids)],'origin': self.name}

Please read this post for more explanations

https://en.xdnf.cn/q/117780.html

Related Q&A

Python Kivy screen manager wiget scope

I am trying to control a screen manager from buttons in a separate class, but I cannot figure out what to set on the button on_press: statements.Kivy file:<HeaderSection>:anchor_x: centeranchor_y…

How do the async and await keywords work, exactly? Whats at the end of the await chain?

I have this code:async def foo(x):yield xyield x + 1async def intermediary(y):await foo(y)def bar():c = intermediary(5)What do I put in bar to get the 5 and the 6 out of c?Im asking because the asynci…

Serial port writing style

I am using two libraries to connect with a port, and two of them uses different styles in writing these commands. I want to understand the difference because I want to use the second one, but it result…

matplotlib plot to fill figure only with data points, no borders, labels, axes,

I am after an extreme form of matplotlibs tight layout. I would like the data points to fill the figure from edge to edge without leaving any borders and without titles, axes, ticks, labels or any othe…

Chromedriver: FileNotFoundError: [WinError 2] The system cannot find the file specified Error

Have looked for an answer, but couldnt find anything. It seems insistent on saying it cant find the file specified and then checks PATH, but cant see it even then :/ Ive put the directory in PATH: http…

Python - mutable default arguments to functions

I was going through https://docs.python.org/3.5/tutorial/controlflow.html#default-argument-values. I modified the example there a little bit as below:x = [4,5] def f(a, L=x):L.append(a)return Lx = [8,9…

Python: remove duplicate items from a list while iterating

I have a list named results, I want to get rid of the duplicate items in the list, the expected result and my results does not match, I checked my code but cannot find what is the problem, what happene…

Python - SciPy Kernal Estimation Example - Density 1

Im currently working through this SciPy example on Kernal Estimation. In particular, the one labelled "Univariate estimation". As opposed to creating random data, I am using asset returns. …

PyQt QFileDialog custom proxy filter not working

This working code brings up a QFileDialog prompting the user to select a .csv file:def load(self,fileName=None):if not fileName:fileName=fileDialog.getOpenFileName(caption="Load Existing Radio Log…

If I have Pandas installed correctly, why wont my import statement recognize it?

Im working on a project to play around with a csv file, however, I cant get pandas to work. Everything I have researched so far has just told me to make sure that pandas is installed. Using pip I have …