1
votes

A computed field in a tree view is not updating after returning from editing values for the line using a form view pop-up. (after the child has been saved/returning from the pop-up, but before the parent record is saved)

To give an example: add a new computed field to Sales Order Lines and then add the computed field into the Sale Order's 'ORDER LINES' tab (which itself is a tree view within the Sale Order Form). Then adjust the Sale Order Form so that editing of the Sale Order Lines is done via a form (i.e. pop-up) (rather than editing the lines within the tree, disable editable='bottom')

After testing it appears that the computed fields method is being run within the form view, the value should be updating.

The display on the line (tree view) should display the new value after returning from the pop-up, however it is not (still displays old value). (this does correctly update after the parent is saved)

This is working for other existing fields (e.g. price) which is displaying the new value on the line (tree view) after editing that value within the pop-up (before the parent is saved).

Why is the computed field showing the old value?

2

2 Answers

1
votes

Try to add @api.depends('any_field_name') above compute function, it should solve your issue.

Odoo has bug about computed fields described in this issue that it doesn't computes computed fields without dependencies.

Let me know if my solution will work for you.

1
votes

It appears that because the computed field was not on the form view (pop-up), even though the compute function was executing, the value on the line view after returning from the form was not updating (before a parent save).

After I added the computed field (invisible=1) to the form view (pop-up), the line view was successfully updated on return.

I do not know why, but am guessing that this is to do with cache or api. It may be possible that the line values are being updated by value returns from the form view (unsure about this), and therefore if the field in question is not on the form view then it is not being returned, and the line is remaining with the previous value.