diff --git a/l10n_br_account/models/account_move_line.py b/l10n_br_account/models/account_move_line.py index 52fb5fe332e6..78d930447078 100644 --- a/l10n_br_account/models/account_move_line.py +++ b/l10n_br_account/models/account_move_line.py @@ -208,6 +208,7 @@ def create(self, vals_list): amount_tax_not_included=values.get( "amount_tax_not_included", 0 ), + amount_tax_withholding=values.get("amount_tax_withholding", 0), amount_total=fiscal_line.amount_total, currency_id=move_id.currency_id, company_id=move_id.company_id, @@ -301,6 +302,7 @@ def write(self, values): exclude_from_invoice_tab=line.exclude_from_invoice_tab, amount_tax_included=line.amount_tax_included, amount_tax_not_included=line.amount_tax_not_included, + amount_tax_withholding=line.amount_tax_withholding, amount_total=line.amount_total, currency_id=line.currency_id, company_id=line.company_id, @@ -590,6 +592,7 @@ def _get_amount_credit_debit( exclude_from_invoice_tab=None, amount_tax_included=None, amount_tax_not_included=None, + amount_tax_withholding=None, amount_total=None, currency_id=None, company_id=None, @@ -611,6 +614,9 @@ def _get_amount_credit_debit( amount_tax_not_included=self.amount_tax_not_included if amount_tax_not_included is None else amount_tax_not_included, + amount_tax_withholding=self.amount_tax_withholding + if amount_tax_withholding is None + else amount_tax_withholding, amount_total=self.amount_total if amount_total is None else amount_total, currency_id=self.currency_id if currency_id is None else currency_id, company_id=self.company_id if company_id is None else company_id, @@ -626,6 +632,7 @@ def _get_amount_credit_debit_model( exclude_from_invoice_tab, amount_tax_included, amount_tax_not_included, + amount_tax_withholding, amount_total, currency_id, company_id, @@ -644,10 +651,13 @@ def _get_amount_credit_debit_model( amount_currency = 0 else: if move_id.fiscal_operation_id.deductible_taxes: - amount_currency = amount_total + amount_currency = amount_total + amount_tax_withholding else: + amount_total = amount_total + amount_tax_withholding amount_currency = ( - amount_total - amount_tax_included - amount_tax_not_included + amount_total + - (amount_tax_included - amount_tax_withholding) + - amount_tax_not_included ) amount_currency = amount_currency * sign diff --git a/l10n_br_account/tests/test_account_move_lc.py b/l10n_br_account/tests/test_account_move_lc.py index bcc790e2aab4..0ac71e96704b 100644 --- a/l10n_br_account/tests/test_account_move_lc.py +++ b/l10n_br_account/tests/test_account_move_lc.py @@ -1,4 +1,5 @@ # Copyright 2023 - TODAY Akretion - Raphael Valyi +# Copyright 2024 - TODAY, Marcel Savegnago # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import fields @@ -12,7 +13,8 @@ class AccountMoveLucroPresumido(AccountMoveBRCommon): @classmethod def setUpClass(cls): super().setUpClass() - cls.fol_sale_with_icms_reduction = cls.env[ + + cls.fo_sale_with_icms_reduction = cls.env[ "l10n_br_fiscal.operation.line" ].create( { @@ -57,7 +59,7 @@ def setUpClass(cls): } ) - cls.cofins_tax_definition_empresa_lc_icms_reduction = cls.env[ + cls.icms_tax_definition_empresa_lc_icms_reduction = cls.env[ "l10n_br_fiscal.tax.definition" ].create( { @@ -69,7 +71,36 @@ def setUpClass(cls): "tax_id": cls.env.ref("l10n_br_fiscal.tax_icms_12_red_26_57").id, "cst_id": cls.env.ref("l10n_br_fiscal.cst_icms_20").id, "state": "approved", - "fiscal_operation_line_id": cls.fol_sale_with_icms_reduction.id, + "fiscal_operation_line_id": cls.fo_sale_with_icms_reduction.id, + } + ) + + # Tax Definition for PIS and COFINS Withholding + cls.pis_wh_tax_definition_empresa_lc = cls.env[ + "l10n_br_fiscal.tax.definition" + ].create( + { + "company_id": cls.company_data["company"].id, + "tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_pis_wh").id, + "is_taxed": True, + "is_debit_credit": True, + "custom_tax": True, + "tax_id": cls.env.ref("l10n_br_fiscal.tax_pis_wh_0_65").id, + "state": "expired", + } + ) + + cls.cofins_wh_tax_definition_empresa_lc = cls.env[ + "l10n_br_fiscal.tax.definition" + ].create( + { + "company_id": cls.company_data["company"].id, + "tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_cofins_wh").id, + "is_taxed": True, + "is_debit_credit": True, + "custom_tax": True, + "tax_id": cls.env.ref("l10n_br_fiscal.tax_cofins_wh_3").id, + "state": "expired", } ) @@ -99,7 +130,7 @@ def setUpClass(cls): document_type=cls.env.ref("l10n_br_fiscal.document_55"), document_serie_id=cls.empresa_lc_document_55_serie_1, fiscal_operation=cls.env.ref("l10n_br_fiscal.fo_venda"), - fiscal_operation_lines=[cls.fol_sale_with_icms_reduction], + fiscal_operation_lines=[cls.fo_sale_with_icms_reduction], ) cls.move_out_simples_remessa = cls.init_invoice( @@ -126,6 +157,51 @@ def setUpClass(cls): document_number="42", ) + # Account Moves With Tax Withholding + cls.pis_tax_definition_empresa_lc.state = "expired" + cls.cofins_tax_definition_empresa_lc.state = "expired" + cls.pis_wh_tax_definition_empresa_lc.action_approve() + cls.cofins_wh_tax_definition_empresa_lc.action_approve() + + cls.move_out_venda_tax_withholding = cls.init_invoice( + "out_invoice", + products=[cls.product_a], + document_type=cls.env.ref("l10n_br_fiscal.document_55"), + document_serie_id=cls.empresa_lc_document_55_serie_1, + fiscal_operation=cls.env.ref("l10n_br_fiscal.fo_venda"), + fiscal_operation_lines=[cls.env.ref("l10n_br_fiscal.fo_venda_venda")], + ) + + cls.move_out_simples_remessa_tax_withholding = cls.init_invoice( + "out_invoice", + products=[cls.product_a], + document_type=cls.env.ref("l10n_br_fiscal.document_55"), + document_serie_id=cls.empresa_lc_document_55_serie_1, + fiscal_operation=cls.env.ref("l10n_br_fiscal.fo_simples_remessa"), + fiscal_operation_lines=[ + cls.env.ref("l10n_br_fiscal.fo_simples_remessa_simples_remessa") + ], + ) + + cls.env.ref("l10n_br_fiscal.fo_compras").deductible_taxes = True + cls.move_in_compra_para_revenda_tax_withholding = cls.init_invoice( + "in_invoice", + products=[cls.product_a], + document_type=cls.env.ref("l10n_br_fiscal.document_55"), + fiscal_operation=cls.env.ref("l10n_br_fiscal.fo_compras"), + fiscal_operation_lines=[ + cls.env.ref("l10n_br_fiscal.fo_compras_compras_comercializacao") + ], + document_serie="1", + document_number="44", + ) + + # Set default values for the tax definitions + cls.pis_tax_definition_empresa_lc.action_approve() + cls.cofins_tax_definition_empresa_lc.action_approve() + cls.pis_wh_tax_definition_empresa_lc.state = "expired" + cls.cofins_wh_tax_definition_empresa_lc.state = "expired" + @classmethod def setup_company_data(cls, company_name, chart_template=None, **kwargs): if company_name == "company_1_data": @@ -1116,6 +1192,552 @@ def test_compra_para_revenda(self): # TODO test effect of ind_final? # ver aqui https://github.com/OCA/l10n-brazil/pull/2347#issuecomment-1548345563 + # Tax Withholding Tests + def test_venda_tax_withholding(self): + product_line_vals_1 = { + "name": self.product_a.name, + "product_id": self.product_a.id, + "account_id": self.product_a.property_account_income_id.id, + "partner_id": self.partner_a.id, + "product_uom_id": self.product_a.uom_id.id, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 1000.0, + "price_subtotal": 1000.0, + "price_total": 1050.0, + "tax_line_id": False, + "currency_id": self.company_data["currency"].id, + "amount_currency": -880.0, + "debit": 0.0, + "credit": 880.0, + "date_maturity": False, + } + + tax_line_vals_cofins = { + "name": "COFINS WH Saida", + "product_id": False, + "account_id": self.product_a.property_account_income_id.id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -30.0, + "price_subtotal": -30.0, + "price_total": -30.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "COFINS WH Saida")], order="id DESC", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": 30.0, + "debit": 30.0, + "credit": 0.0, + "date_maturity": False, + } + + tax_line_vals_icms = { + "name": "ICMS Saida", + "product_id": False, + "account_id": self.env["account.account"] + .search([("name", "=", "ICMS a Recolher")], order="id DESC", limit=1) + .id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 120.0, + "price_subtotal": 120.0, + "price_total": 120.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "ICMS Saida")], order="id desc", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": -120.0, + "debit": 0.0, + "credit": 120.0, + "date_maturity": False, + } + + tax_line_vals_ipi = { + "name": "IPI Saída", + "product_id": False, + "account_id": self.env["account.account"] + .search( + [ + ("name", "=", "IPI a Recolher"), + ("company_id", "=", self.company_data["company"].id), + ], + order="id ASC", + limit=1, + ) + .id, # TODO find our why this complex domain is required for IPI + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 50.0, + "price_subtotal": 50.0, + "price_total": 50.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "IPI Saída")], order="id desc", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": -50.0, + "debit": 0.0, + "credit": 50.0, + "date_maturity": False, + } + + tax_line_vals_pis = { + "name": "PIS WH Saida", + "product_id": False, + "account_id": self.product_a.property_account_income_id.id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -6.5, + "price_subtotal": -6.5, + "price_total": -6.5, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "PIS WH Saida")], order="id desc", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": 6.5, + "debit": 6.5, + "credit": 0.0, + "date_maturity": False, + } + + term_line_vals_1 = { + "name": "", + "product_id": False, + "account_id": self.company_data["default_account_receivable"].id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -1013.5, + "price_subtotal": -1013.5, + "price_total": -1013.5, + "tax_ids": [], + "tax_line_id": False, + "currency_id": self.company_data["currency"].id, + "amount_currency": 1013.5, + "debit": 1013.5, + "credit": 0.0, + "date_maturity": fields.Date.from_string("2019-01-01"), + } + + move_vals = { + "partner_id": self.partner_a.id, + "currency_id": self.company_data["currency"].id, + "journal_id": self.company_data["default_journal_sale"].id, + "date": fields.Date.from_string("2019-01-01"), + "fiscal_position_id": False, + "payment_reference": "", + "invoice_payment_term_id": self.pay_terms_a.id, + "amount_untaxed": 1000.0, + "amount_tax": 50.0, + "amount_total": 1013.5, + } + + self.assertInvoiceValues( + self.move_out_venda_tax_withholding, + [ + product_line_vals_1, + tax_line_vals_cofins, + tax_line_vals_icms, + tax_line_vals_ipi, + tax_line_vals_pis, + term_line_vals_1, + ], + move_vals, + ) + + def test_simples_remessa_tax_withholding(self): + product_line_vals_1 = { + "name": self.product_a.name, + "product_id": self.product_a.id, + "account_id": self.product_a.property_account_income_id.id, + "partner_id": self.partner_a.id, + "product_uom_id": self.product_a.uom_id.id, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 1000.0, + "price_subtotal": 1000.0, + "price_total": 1050.0, + "tax_line_id": False, + "currency_id": self.company_data["currency"].id, + "amount_currency": 0.0, + "debit": 0.0, + "credit": 0.0, + "date_maturity": False, + } + + tax_line_vals_cofins = { + "name": "COFINS WH Saida", + "product_id": False, + "account_id": self.product_a.property_account_income_id.id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -30.0, + "price_subtotal": -30.0, + "price_total": -30.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "COFINS WH Saida")], order="id DESC", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": 30.0, + "debit": 30.0, + "credit": 0.0, + "date_maturity": False, + } + + tax_line_vals_icms = { + "name": "ICMS Saida", + "product_id": False, + "account_id": self.env["account.account"] + .search([("name", "=", "ICMS a Recolher")], order="id DESC", limit=1) + .id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 120.0, + "price_subtotal": 120.0, + "price_total": 120.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "ICMS Saida")], order="id desc", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": -120.0, + "debit": 0.0, + "credit": 120.0, + "date_maturity": False, + } + + tax_line_vals_ipi = { + "name": "IPI Saída", + "product_id": False, + "account_id": self.env["account.account"] + .search( + [ + ("name", "=", "IPI a Recolher"), + ("company_id", "=", self.company_data["company"].id), + ], + order="id ASC", + limit=1, + ) + .id, # TODO find our why this complex domain is required for IPI + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 50.0, + "price_subtotal": 50.0, + "price_total": 50.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "IPI Saída")], order="id desc", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": -50.0, + "debit": 0.0, + "credit": 50.0, + "date_maturity": False, + } + + tax_line_vals_pis = { + "name": "PIS WH Saida", + "product_id": False, + "account_id": self.product_a.property_account_income_id.id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -6.5, + "price_subtotal": -6.5, + "price_total": -6.5, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "PIS WH Saida")], order="id desc", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": 6.5, + "debit": 6.5, + "credit": 0.0, + "date_maturity": False, + } + + term_line_vals_1 = { + "name": "", + "product_id": False, + "account_id": self.company_data["default_account_receivable"].id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -133.5, + "price_subtotal": -133.5, + "price_total": -133.5, + "tax_ids": [], + "tax_line_id": False, + "currency_id": self.company_data["currency"].id, + "amount_currency": 133.5, + "debit": 133.5, + "credit": 0.0, + "date_maturity": fields.Date.from_string("2019-01-01"), + } + + move_vals = { + "partner_id": self.partner_a.id, + "currency_id": self.company_data["currency"].id, + "journal_id": self.company_data["default_journal_sale"].id, + "date": fields.Date.from_string("2019-01-01"), + "fiscal_position_id": False, + "payment_reference": "", + "invoice_payment_term_id": self.pay_terms_a.id, + "amount_untaxed": 1000.0, # FIXME is this correct for a simples remessa?? + "amount_tax": 50.0, + "amount_total": 133.5, + } + + self.assertInvoiceValues( + self.move_out_simples_remessa_tax_withholding, + [ + product_line_vals_1, + tax_line_vals_cofins, + tax_line_vals_icms, + tax_line_vals_ipi, + tax_line_vals_pis, + term_line_vals_1, + ], + move_vals, + ) + + def test_compra_para_revenda_tax_withholding(self): + """ + Test move with deductible taxes and tax withholding + """ + product_line_vals_1 = { + "name": self.product_a.name, + "product_id": self.product_a.id, + "account_id": self.product_a.property_account_expense_id.id, + "partner_id": self.partner_a.id, + "product_uom_id": self.product_a.uom_id.id, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 1000.0, + "price_subtotal": 1000.0, + "price_total": 1050.0, + "tax_line_id": False, + "currency_id": self.company_data["currency"].id, + "amount_currency": 1050.0, + "debit": 1050.0, + "credit": 0.0, + "date_maturity": False, + } + + tax_line_vals_cofins = { + "name": "COFINS WH Entrada", + "product_id": False, + "account_id": self.env["account.account"] + .search([("name", "=", "COFINS a Recolher")], order="id DESC", limit=1) + .id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -30.0, + "price_subtotal": -30.0, + "price_total": -30.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "COFINS WH Entrada")], order="id DESC", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": -30.0, + "debit": 0.0, + "credit": 30.0, + "date_maturity": False, + } + + tax_line_vals_icms = { + "name": "ICMS Entrada", + "product_id": False, + "account_id": self.env["account.account"] + .search([("name", "=", "ICMS a Compensar")], order="id DESC", limit=1) + .id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 120.0, + "price_subtotal": 120.0, + "price_total": 120.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "ICMS Entrada")], order="id DESC", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": 120.0, + "debit": 120.0, + "credit": 0.0, + "date_maturity": False, + } + + tax_line_vals_icms_comp = { + "name": "ICMS Entrada Dedutível", + "product_id": False, + "account_id": self.env["account.account"] + .search([("name", "=", "ICMS s/ Vendas")], order="id DESC", limit=1) + .id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -120.0, + "price_subtotal": -120.0, + "price_total": -120.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "ICMS Entrada Dedutível")], order="id desc", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": -120.0, + "debit": 0.0, + "credit": 120.0, + "date_maturity": False, + } + + tax_line_vals_ipi = { + "name": "IPI Entrada", + "product_id": False, + "account_id": self.env["account.account"] + .search([("name", "=", "IPI a Compensar")], order="id DESC", limit=1) + .id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 50.0, + "price_subtotal": 50.0, + "price_total": 50.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "IPI Entrada")], order="id desc", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": 50.0, + "debit": 50.0, + "credit": 0.0, + "date_maturity": False, + } + + tax_line_vals_ipi_comp = { + "name": "IPI Entrada Dedutível", + "product_id": False, + "account_id": self.env["account.account"] + .search([("name", "=", "IPI s/ Vendas")], order="id DESC", limit=1) + .id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -50.0, + "price_subtotal": -50.0, + "price_total": -50.0, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "IPI Entrada Dedutível")], order="id desc", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": -50.0, + "debit": 0.0, + "credit": 50.0, + "date_maturity": False, + } + + tax_line_vals_pis = { + "name": "PIS WH Entrada", + "product_id": False, + "account_id": self.env["account.account"] + .search([("name", "=", "PIS a Recolher")], order="id DESC", limit=1) + .id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -6.5, + "price_subtotal": -6.5, + "price_total": -6.5, + "tax_ids": [], + "tax_line_id": self.env["account.tax"] + .search([("name", "=", "PIS WH Entrada")], order="id desc", limit=1) + .id, + "currency_id": self.company_data["currency"].id, + "amount_currency": -6.5, + "debit": 0.0, + "credit": 6.5, + "date_maturity": False, + } + + term_line_vals_1 = { + "name": "44/1-1", + "product_id": False, + "account_id": self.company_data["default_account_payable"].id, + "partner_id": self.partner_a.id, + "product_uom_id": False, + "quantity": 1.0, + "discount": 0.0, + "price_unit": -1013.5, + "price_subtotal": -1013.5, + "price_total": -1013.5, + "tax_ids": [], + "tax_line_id": False, + "currency_id": self.company_data["currency"].id, + "amount_currency": -1013.5, + "debit": 0.0, + "credit": 1013.5, + "date_maturity": fields.Date.from_string("2019-01-01"), + } + + move_vals = { + "partner_id": self.partner_a.id, + "currency_id": self.company_data["currency"].id, + "journal_id": self.company_data["default_journal_purchase"].id, + "date": fields.Date.from_string("2019-01-01"), + "fiscal_position_id": False, + "payment_reference": "", + "invoice_payment_term_id": self.pay_terms_a.id, + "amount_untaxed": 1000.0, + "amount_tax": 50.0, + "amount_total": 1013.5, + } + + self.assertInvoiceValues( + self.move_in_compra_para_revenda_tax_withholding, + [ + product_line_vals_1, + tax_line_vals_cofins, + tax_line_vals_icms, + tax_line_vals_icms_comp, + tax_line_vals_ipi, + tax_line_vals_ipi_comp, + tax_line_vals_pis, + term_line_vals_1, + ], + move_vals, + ) + def test_composite_move(self): # first we make a few assertions about an existing vendor bill: self.assertEqual(len(self.move_in_compra_para_revenda.invoice_line_ids), 1) diff --git a/l10n_br_account/views/account_invoice_view.xml b/l10n_br_account/views/account_invoice_view.xml index 000d93fc2ee6..98d3bee2f2b4 100644 --- a/l10n_br_account/views/account_invoice_view.xml +++ b/l10n_br_account/views/account_invoice_view.xml @@ -505,6 +505,7 @@ + diff --git a/l10n_br_fiscal/models/document_fiscal_line_mixin_methods.py b/l10n_br_fiscal/models/document_fiscal_line_mixin_methods.py index 812c1304fc33..f30018439885 100644 --- a/l10n_br_fiscal/models/document_fiscal_line_mixin_methods.py +++ b/l10n_br_fiscal/models/document_fiscal_line_mixin_methods.py @@ -146,15 +146,19 @@ def _compute_amounts(self): for record in self: round_curr = record.currency_id or self.env.ref("base.BRL") # Valor dos produtos - record.price_gross = round_curr.round(record.price_unit * record.quantity) - record.amount_untaxed = record.price_gross - record.discount_value + amount_subtotal = round_curr.round(record.price_unit * record.quantity) - record.amount_fiscal = ( - round_curr.round(record.fiscal_price * record.fiscal_quantity) - - record.discount_value + record.price_gross = ( + amount_subtotal + + record.amount_tax_not_included + - record.amount_tax_withholding ) + record.amount_untaxed = amount_subtotal - record.discount_value + + record.amount_fiscal = amount_subtotal - record.discount_value + record.amount_tax = record.amount_tax_not_included add_to_amount = sum(record[a] for a in record._add_fields_to_amount()) @@ -168,6 +172,9 @@ def _compute_amounts(self): # Valor Liquido (TOTAL + IMPOSTOS - RETENÇÕES) record.amount_taxed = record.amount_total - record.amount_tax_withholding + # Valor do documento (NF) - RETENÇÕES + record.amount_total = record.amount_taxed + # Valor financeiro if ( record.fiscal_operation_line_id diff --git a/l10n_br_fiscal/models/tax_definition.py b/l10n_br_fiscal/models/tax_definition.py index 948cac2a8efe..0fdb67d49314 100644 --- a/l10n_br_fiscal/models/tax_definition.py +++ b/l10n_br_fiscal/models/tax_definition.py @@ -371,6 +371,7 @@ def map_tax_definition( cest = product.cest_id domain = [ + ("state", "!=", "expired"), ("id", "in", self.ids), "|", ("state_to_ids", "=", False), diff --git a/l10n_br_purchase/models/purchase_order_line.py b/l10n_br_purchase/models/purchase_order_line.py index 17f5a34ca38a..ef0adcae3192 100644 --- a/l10n_br_purchase/models/purchase_order_line.py +++ b/l10n_br_purchase/models/purchase_order_line.py @@ -102,9 +102,7 @@ def _compute_amount(self): # Update record line.update( { - "price_subtotal": line.amount_untaxed, "price_tax": line.amount_tax, - "price_gross": line.amount_untaxed + line.discount_value, "price_total": line.amount_total, } ) diff --git a/l10n_br_sale/models/sale_order_line.py b/l10n_br_sale/models/sale_order_line.py index 28127a7816dc..95f43ddf162e 100644 --- a/l10n_br_sale/models/sale_order_line.py +++ b/l10n_br_sale/models/sale_order_line.py @@ -184,9 +184,7 @@ def _compute_amount(self): # Update record line.update( { - "price_subtotal": line.amount_untaxed, "price_tax": line.amount_tax, - "price_gross": line.amount_untaxed + line.discount_value, "price_total": line.amount_total, } )