From 9f53ddd66d3ade93ef7774995b882793e54b76ce Mon Sep 17 00:00:00 2001 From: Antonio Neto Date: Tue, 17 Dec 2024 10:41:28 -0300 Subject: [PATCH] [FIX] l10n_br_sale: compute fiscal taxes --- l10n_br_sale/models/sale_order_line.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/l10n_br_sale/models/sale_order_line.py b/l10n_br_sale/models/sale_order_line.py index 532399cf81bc..c7c383799702 100644 --- a/l10n_br_sale/models/sale_order_line.py +++ b/l10n_br_sale/models/sale_order_line.py @@ -304,3 +304,21 @@ def _get_fiscal_partner(self): partner = self.order_id.partner_invoice_id return partner + + @api.depends("product_id", "company_id", "fiscal_tax_ids") + def _compute_tax_id(self): + """Compute taxes based on fiscal operation or fallback to default behavior.""" + lines_with_fiscal_operation = self.filtered( + lambda line: line.fiscal_operation_line_id + ) + lines_without_fiscal_operation = self - lines_with_fiscal_operation + + for line in lines_with_fiscal_operation: + line.tax_id = line.fiscal_tax_ids.account_taxes( + user_type="sale", fiscal_operation=line.fiscal_operation_id + ) + + if lines_without_fiscal_operation: + return super( + SaleOrderLine, lines_without_fiscal_operation + )._compute_tax_id()