[FIX] account: fix error when delete the SO on form view

Reproduction steps:

- disable any debugger parameter that would on in the url
- create a new sale order
- add a sale order line with a tax
- save (and don't leave the record!)
- delete the sale order

Regarding the bug, there are several issues happening at the same time:

- Business code issue:
	- Our code wasn't defensive and we were assuming the computed value
would always be set to the computed value.
- Framework JS issue: (not OWL itself but its integration into Odoo)
	- When the record is deleted, a re-rendering gets triggered.
	- As we deleted the record in the back, the browsed record in the
front-end gets its data reset to the default values a field could have.
Because the default value of a binary field is False, tax_totals gets
set to false for the reset record.

Now, we have a bunch of race conditions going on.

In the invoicing view, it doesn't happen because the rendering is slower
and it gets cancelled before being done. Thus the field tax_totals
hasn't the chance to re-render itself and thus, to call
TaxTotalsComponent.formatData through the call of onWillRender.
In the case of the sale order view, the field has the time to gets
rendered, the method gets called and the traceback happens.

closes odoo/odoo#159018

Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
Tran Truong Son
2024-04-03 22:17:53 +00:00
committed by Soncrits
parent 13dd9c827e
commit e721ed146d
@@ -150,6 +150,9 @@ export class TaxTotalsComponent extends Component {
formatData(props) {
let totals = JSON.parse(JSON.stringify(toRaw(props.record.data[this.props.name])));
if (!totals) {
return;
}
const currencyFmtOpts = { currencyId: props.record.data.currency_id && props.record.data.currency_id[0] };
let amount_untaxed = totals.amount_untaxed;