2017-03-05 52 views
0

我從fleet_vehicle_log_services創建stock.picking用這種方法:預計單:stock.move - Odoo V9社區

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

任何想法?

回答

2

One2many字段需要用於插入的特殊命令。你的情況:

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

請閱讀this post更多的解釋

+0

真棒!非常感謝你 – NeoVe

相關問題