问题
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?
回答1:
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://stackoverflow.com/questions/42614194/expected-singleton-stock-move-odoo-v9-community