我使用新的API,我想在点击向导按钮后更改状态,但每次点击按钮都会返回错误:
TypeError: write() got multiple values for keyword argument 'context'
回溯:
Traceback (most recent call last):
File "/home/workspace/odoo8/openerp/http.py", line 537, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/workspace/odoo8/openerp/http.py", line 574, in dispatch
result = self._call_function(**self.params)
File "/home/workspace/odoo8/openerp/http.py", line 310, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/workspace/odoo8/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/home/workspace/odoo8/openerp/http.py", line 307, in checked_call
return self.endpoint(*a, **kw)
File "/home/workspace/odoo8/openerp/http.py", line 803, in __call__
return self.method(*args, **kw)
File "/home/workspace/odoo8/openerp/http.py", line 403, in response_wrap
response = f(*args, **kw)
File "/home/workspace/odoo8/addons/web/controllers/main.py", line 948, in call_button
action = self._call_kw(model, method, args, {})
File "/home/workspace/odoo8/addons/web/controllers/main.py", line 936, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/home/workspace/odoo8/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/home/workspace/odoo8/openerp/api.py", line 399, in old_api
result = method(recs, *args, **kwargs)
File "/home/workspace/odoo8/custom_addons/my_module/models/test_module.py", line 14, in action_credit
sale_order.write(sale_id,{'state': 'order_confirm'})
File "/home/workspace/odoo8/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/home/workspace/odoo8/openerp/api.py", line 592, in new_api
result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)
TypeError: write() got multiple values for keyword argument 'context'
.py文件:
from openerp.osv import orm
from openerp import models, api, _
class TestOverride(models.TransientModel):
_name = 'test.override'
@api.multi
def action_override(self):
sale_order = self.env['sale.order']
sale_id = self._context['sale_id']
sale_order.write(sale_id,{'state': 'order_confirm'})
return True
class sale_order(models.Model):
_inherit = "sale.order"
@api.multi
def action_button_confirm(self):
for order_id in self:
#
if condition:
return {
'name': 'Test',
'view_mode': 'form',
'view_type': 'form',
'res_model': 'test.override',
'type': 'ir.actions.act_window',
'nodestroy': True,
'target': 'new',
'context': {'sale_id': order_id.id}
}
self.write(order_id, {'state': 'order_confirm'})
return True
答案 0 :(得分:2)
调用write方法时,不需要传递 order_id 。只需将值传递给它。
self.write({'state': 'order_confirm'})