我正在尝试覆盖sale.order的write()方法,但它无法正常工作
Error:
Odoo Server Error
Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/http.py", line 619, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/odoo/src/odoo/odoo/http.py", line 309, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/odoo/src/odoo/odoo/tools/pycompat.py", line 14, in reraise
raise value
File "/home/odoo/src/odoo/odoo/http.py", line 664, in dispatch
result = self._call_function(**self.params)
File "/home/odoo/src/odoo/odoo/http.py", line 345, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/odoo/src/odoo/odoo/service/model.py", line 93, in wrapper
return f(dbname, *args, **kwargs)
File "/home/odoo/src/odoo/odoo/http.py", line 338, in checked_call
result = self.endpoint(*a, **kw)
File "/home/odoo/src/odoo/odoo/http.py", line 909, in __call__
return self.method(*args, **kw)
File "/home/odoo/src/odoo/odoo/http.py", line 510, in response_wrap
response = f(*args, **kw)
File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1320, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1312, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 391, in call_kw
result = _call_kw_model(method, model, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 364, in _call_kw_model
result = method(recs, *args, **kwargs)
TypeError: write() takes 2 positional arguments but 3 were given
但是以相同的方式覆盖create()方法非常完美。
这是我必要的代码部分:
class insurance_sale(models.Model):
_inherit = 'sale.order'
_description = 'Insurance Sale'
creator_name = fields.Many2one('res.users', string="Hazırlayan adı", index=True, store=True)
@api.onchange('creator_name')
def _onchange_creator_name01(self):
if self.creator_name and self.creator_name.sale_team_id:
self.team_id = self.creator_name.sale_team_id
@api.onchange('creator_name')
def _onchange_creator_name02(self):
sales_members = self.env['crm.team'].search([]).mapped('member_ids')
if self.creator_name and self.creator_name not in sales_members:
self.write({'team_id': False})
@api.model
def create(self, vals):
record = super(insurance_sale, self).create(vals)
record._onchange_creator_name01()
record._onchange_creator_name02()
return record
@api.model
def write(self, vals):
record = super(insurance_sale, self).write(vals)
record._onchange_creator_name01()
record._onchange_creator_name02()
return record