如何解决使用 Onchange 更新 one2many 字段奥多14
由于未保存字段“tax_ids_after_fiscal_position”的问题,我尝试使用在 pos.order.line 模型中调用的以下函数更新 One2many 字段 这是我的代码:
class PosOrderLine(models.Model):
_inherit = "pos.order.line"
@api.onchange('product_id')
def _onchange_product_id(self):
self.tax_ids_after_fiscal_position = self.product_id.taxes_id
self.write({'tax_ids_after_fiscal_position': [(4,self.product_id.taxes_id)]})
我收到以下错误:
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/http.py",line 639,in _handle_exception
return super(JsonRequest,self)._handle_exception(exception)
File "/usr/lib/python3/dist-packages/odoo/http.py",line 315,in _handle_exception
raise exception.with_traceback(None) from new_cause
AttributeError: 'account.tax' object has no attribute 'ref'
请问怎么了? 有什么帮助吗? 谢谢。
解决方法
请不要在 onchange 内使用 write。
@api.onchange('product_id')
def _onchange_product_id(self):
self.tax_ids_after_fiscal_position = [(6,self.product_id.taxes_id.ids)]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。