Hi all,
I have noticed a behavior on some of my computed fields that I can't understand. I have the following field (toy example):
field_x = fields.Boolean(string="Field X", compute="_compute_field_x", store=True)
Then function _compute_field_x is as follows:
@api.depends("field_y", "field_z") # none of these are computed def _compute_field_x(self):
for record in self:
print('hi')
if record.field_y = 'Something':
record.field_x = "A"
elif record.field_z = 'Something Else':
record.field_x = "B"
else:
record.field_x = "C"
For some reason, whenever I change either field_y or field_z on the model's form view, the message "hi" is printed twice: once before the write() method is called (to update field_y or field_z), and then once again after the write method is concluded. And even stranger, is that when the method is called AFTER the write method, it record.field_y or record.field_z still show the values pre-write.
In my case, this is a problem, because I wanted to send an email warning when field_x changes, but if I do it on the compute method it will end up sending the email twice.
If someone could clarify this behavior for me, I'd really appreciate it!