1

我正在尝试覆盖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

4

1 回答 1

2

你应该失去装饰器。在 Odoo 13 中,默认情况下所有记录都是多模型的。

这也是为什么您应该始终迭代self以确保不会像单例那样访问记录集的原因。

  def write(self, vals):
    res = super(SaleOrder, self).write(vals)
    for rec in res:
      _logger.info(rec.id)
    return res
于 2020-02-12T09:26:39.677 回答