From 4241648bbca8e4b0769db86751790bea8f6d27d7 Mon Sep 17 00:00:00 2001 From: Diego Paradeda Date: Mon, 25 Nov 2024 11:44:39 -0300 Subject: [PATCH] [FIX] l10n_br_fiscal: additional values inverse method --- .../models/document_mixin_methods.py | 69 +++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/l10n_br_fiscal/models/document_mixin_methods.py b/l10n_br_fiscal/models/document_mixin_methods.py index eec037c42543..d1b77070dd8c 100644 --- a/l10n_br_fiscal/models/document_mixin_methods.py +++ b/l10n_br_fiscal/models/document_mixin_methods.py @@ -159,14 +159,23 @@ def _inverse_amount_freight(self): for line in record._get_product_amount_lines(): line._onchange_fiscal_taxes() record._fields["amount_total"].compute_value(record) - record.write( - { - name: value - for name, value in record._cache.items() - if record._fields[name].compute == "_amount_all" + + # Case Sale, Purchase or POS + vals = {} + for name, value in record._cache.items(): + if ( + record._fields[name].compute == "_amount_all" and not record._fields[name].inverse - } - ) + ): + vals[name] = value + if vals: + record.write(vals) + else: + # Case invoice (account.move has not compute named '_amount_all') + record = record.with_context(check_move_validity=False) + record.move_ids.invoice_line_ids._onchange_price_subtotal() + record.move_ids.invoice_line_ids._onchange_mark_recompute_taxes() + record.move_ids._onchange_invoice_line_ids() def _inverse_amount_insurance(self): for record in self.filtered(lambda doc: doc._get_product_amount_lines()): @@ -209,14 +218,23 @@ def _inverse_amount_insurance(self): for line in record._get_product_amount_lines(): line._onchange_fiscal_taxes() record._fields["amount_total"].compute_value(record) - record.write( - { - name: value - for name, value in record._cache.items() - if record._fields[name].compute == "_amount_all" + + # Case Sale, Purchase or POS + vals = {} + for name, value in record._cache.items(): + if ( + record._fields[name].compute == "_amount_all" and not record._fields[name].inverse - } - ) + ): + vals[name] = value + if vals: + record.write(vals) + else: + # Case invoice (account.move has not compute named '_amount_all') + record = record.with_context(check_move_validity=False) + record.move_ids.invoice_line_ids._onchange_price_subtotal() + record.move_ids.invoice_line_ids._onchange_mark_recompute_taxes() + record.move_ids._onchange_invoice_line_ids() def _inverse_amount_other(self): for record in self.filtered(lambda doc: doc._get_product_amount_lines()): @@ -259,11 +277,20 @@ def _inverse_amount_other(self): for line in record._get_product_amount_lines(): line._onchange_fiscal_taxes() record._fields["amount_total"].compute_value(record) - record.write( - { - name: value - for name, value in record._cache.items() - if record._fields[name].compute == "_amount_all" + + # Case Sale, Purchase or POS + vals = {} + for name, value in record._cache.items(): + if ( + record._fields[name].compute == "_amount_all" and not record._fields[name].inverse - } - ) + ): + vals[name] = value + if vals: + record.write(vals) + else: + # Case invoice (account.move has not compute named '_amount_all') + record = record.with_context(check_move_validity=False) + record.move_ids.invoice_line_ids._onchange_price_subtotal() + record.move_ids.invoice_line_ids._onchange_mark_recompute_taxes() + record.move_ids._onchange_invoice_line_ids()