如何找出用户更改字段和字段从Onchange函数中的表中自动填充的何时自动填充的区别?
我有一个许多2ONE字段作为A_Details A_Details在A上具有过滤器基础,
A = fields.Many2one(comodel_name="headertable")
A_details = fields.One2many(comodel_name="detailtable")
并且在XML中,我将A_Detail中的上下文传递给A_Detail中的A_Details,
<field name="A_detail" context="{'parent_id': A,}"/>
现在我想在用户更改A_Detail的记录中,然后将用户更改A_Detail的记录。因此,我在这样的字段上使用OnChange Decorator:
@api.onchange('A')
def _delete_selected_records(self):
for rec in self.A_details:
self.A_details = [(3, rec.id, 0)]
此功能正常工作以创建模式,但是当我从树视图打开记录时发生问题,而当一个字段从模型上获得值,请从模型上获得值删除所有a_detail的记录,这就是为什么我要检查此功能,如果用户更改a,请删除a_detail的记录,如果系统设置为字段的值无需执行 ...我该如何处理此问题?
I have a many2one field as A and one2many field as A_details that A_details has filter base on A,
A = fields.Many2one(comodel_name="headertable")
A_details = fields.One2many(comodel_name="detailtable")
and in the xml I pass the A value with context in A_detail to filter it
<field name="A_detail" context="{'parent_id': A,}"/>
now I want to delete A_detail's records when user changes the A value, so I use onchange decorator on A field like this:
@api.onchange('A')
def _delete_selected_records(self):
for rec in self.A_details:
self.A_details = [(3, rec.id, 0)]
this function workes correctly to create mode but the problem occurs when I open the record from tree view and while A field is getting value from model Onchanged decorator call the _delete_selected_records function and it delete all the A_detail's records, That's why I want to check in this function that if user change the A, delete the A_detail's records else if system sets value to field do nothing... how can I handle this???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果A被删除,则应添加检查 ,如果a是false ,则 do x :
即使函数是由功能触发的,即使假设用户意外地将光标放在视图中的场上,或者您不会冒险删除任何内容,除非满足正确的条件。
You should add a check if A is deleted or not meaning if A is False then do X:
This way even if the function is triggered by let's say a user accidentally putting cursor on the field in the view or something you won't risk deleting anything unless the correct condition is met.