预计单身人士:stock.move - Odoo v9社区

时间:2017-03-05 21:22:22

标签: python openerp odoo-9

我正在使用此方法从stock.picking创建fleet_vehicle_log_services

@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

它在fields上声明如下:

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

我的观点:

    <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>

当我点击创建选择时,它会抛出这个:

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)

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

One2many字段需要特殊的插入命令。在你的情况下:

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

请阅读this post了解更多解释