我们如何将数据传递到one2many字段,其中我的数据来自另一个模型。 我写的是这些,但错误显示出来。
我通过按钮访问这些功能。
@api.multi
def action_order(self):
rec= self.env['purchase.order'].create({
'partner_id' : self.vendors.id,
'store_id' : self.store_id.id,
'purchase_order_type' : self.order_type,
'date_order' : self.date_order,
'date_planned' : self.date_order,
'type' : self.type,
'order_line' : (0, 0, [{'brand_id' : self.product_brand_id,
'product_id' : self.purchase_product_id,
'part_number' : self.product_part_number,
'name' : self.desc,
'date_planned' : self.date_order,
'product_qty' : self.quantity_no,
'price_unit' : self.product_price_unit,
'product_uom' : self.product_measure.id,
}])
})
我的错误日志就像这些
服务器错误
Traceback (most recent call last): File "/opt/ 9/ /openerp/http.py", line 643, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception) File "/opt/ 9/ /openerp/http.py", line 680, in dispatch
result = self._call_function(**self.params) File "/opt/ 9/ /openerp/http.py", line 316, in _call_function
return checked_call(self.db, *args, **kwargs) File "/opt/ 9/ /openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs) File "/opt/ 9/ /openerp/http.py", line 309, in checked_call
result = self.endpoint(*a, **kw) File "/opt/ 9/ /openerp/http.py", line 959, in __call__
return self.method(*args, **kw) File "/opt/ 9/ /openerp/http.py", line 509, in response_wrap
response = f(*args, **kw) File "/opt/ 9/ /addons/web/controllers/main.py", line 896, in call_button
action = self._call_kw(model, method, args, {}) File "/opt/ 9/ /addons/web/controllers/main.py", line 884, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "/opt/ 9/ /openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs) File "/opt/ 9/ /openerp/api.py", line 381, in old_api
result = method(recs, *args, **kwargs) File "/opt/ 9/custom/trunk/floating_purchase_order/models/floating.py", line 57, in action_purchase_order
if self.action_order(): File "/opt/ 9/ /openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs) File "/opt/ 9/custom/trunk/floating_purchase_order/models/floating.py", line 99, in action_order
'product_uom' : self.product_measure.id, File "/opt/ 9/ /openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs) File "/opt/ 9/ /addons/purchase/purchase.py", line 180, in create
return super(PurchaseOrder, self).create(vals) File "/opt/ 9/ /openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs) File "/opt/ 9/ /addons/mail/models/mail_thread.py", line 232, in create
thread = super(MailThread, self).create(values) File "/opt/ 9/ /openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs) File "/opt/ 9/ /openerp/models.py", line 4151, in create
record = self.browse(self._create(old_vals)) File "/opt/ 9/ /openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs) File "/opt/ 9/ /openerp/api.py", line 490, in new_api
result = method(self._model, cr, uid, *args, **old_kwargs) File "/opt/ 9/ /openerp/models.py", line 4336, in _create
result += self._columns[field].set(cr, self, id_new, field, vals[field], user, rel_context) or [] File "/opt/ 9/ /openerp/osv/fields.py", line 823, in set
if act[0] == 0: TypeError: 'int' object has no attribute '__getitem__'
答案 0 :(得分:0)
order_line
的值必须是三元组列表。要创建新条目,您需要格式为(0, 0, value_dictionary)
所以将代码更改为:
'order_line' : [(0, 0, {
'brand_id' : self.product_brand_id,
'product_id' : self.purchase_product_id,
'part_number' : self.product_part_number,
'name' : self.desc,
'date_planned' : self.date_order,
'product_qty' : self.quantity_no,
'price_unit' : self.product_price_unit,
'product_uom' : self.product_measure.id,
})]
答案 1 :(得分:0)
“ product_uom ”项似乎“ self.product_measure.id ”正在创建问题。它似乎是一个'Integer'字段,你试图从中获取'id'。