Skip to content

Commit

Permalink
Merge PR #3519 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by mileo
  • Loading branch information
OCA-git-bot committed Dec 9, 2024
2 parents ca193ec + 20ec309 commit 57e1496
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
41 changes: 41 additions & 0 deletions l10n_br_account_nfe/tests/test_nfe_with_ipi.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,44 @@ def test_nfe_with_ipi(self):
self.assertEqual(self.move_out_venda.nfe40_vIPI, 50.0)
self.assertEqual(self.move_out_venda.nfe40_vProd, 1000.00)
self.assertEqual(self.move_out_venda.nfe40_vNF, 1050.00)

def test_nfe_credit_note(self):
"""
Test fiscal document field: nfe40_impostoDevol (no demo)
"""
partner_a = self.env["res.partner"].create({"name": "Test partner A"})
fiscal_doc = self.env["l10n_br_fiscal.document"].create(
{
"fiscal_operation_id": self.env.ref(
"l10n_br_fiscal.fo_devolucao_venda"
).id,
"document_type_id": self.env.ref("l10n_br_fiscal.document_55").id,
"edoc_purpose": "4",
"issuer": "company",
"partner_id": partner_a.id,
"fiscal_operation_type": "in",
}
)
product_id = self.env.ref("product.product_product_10")
fiscal_doc_line = self.env["l10n_br_fiscal.document.line"].create(
{
"document_id": fiscal_doc.id,
"name": "Return - credit note",
"product_id": product_id.id,
"fiscal_operation_type": "in",
"fiscal_operation_id": self.env.ref(
"l10n_br_fiscal.fo_devolucao_venda"
).id,
"fiscal_operation_line_id": self.env.ref(
"l10n_br_fiscal.fo_devolucao_venda_devolucao_venda"
).id,
"p_devol": 50,
"ipi_devol_value": 1,
}
)
fiscal_doc_line._onchange_product_id_fiscal()

self.assertEqual(fiscal_doc_line.nfe40_impostoDevol.nfe40_pDevol, 50.00)
self.assertEqual(
fiscal_doc_line.nfe40_impostoDevol.nfe40_IPI.nfe40_vIPIDevol, 1.00
)
4 changes: 4 additions & 0 deletions l10n_br_fiscal/models/document_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ class DocumentLine(models.Model):
force_compute_delivery_costs_by_total = fields.Boolean(
related="document_id.force_compute_delivery_costs_by_total"
)

edoc_purpose = fields.Selection(
related="document_id.edoc_purpose",
)
10 changes: 10 additions & 0 deletions l10n_br_fiscal/models/document_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ def _operation_domain(self):
readonly=True,
)

operation_fiscal_type = fields.Selection(
related="fiscal_operation_id.fiscal_type",
readonly=True,
)

fiscal_operation_line_id = fields.Many2one(
comodel_name="l10n_br_fiscal.operation.line",
string="Operation Line",
Expand Down Expand Up @@ -568,6 +573,11 @@ def _operation_domain(self):
"('cst_out_id', '=', ipi_cst_id)]",
)

# IPI Devolvido Fields
p_devol = fields.Float(string="Percentual de mercadoria devolvida")

ipi_devol_value = fields.Monetary(string="Valor do IPI devolvido")

# II Fields
ii_tax_id = fields.Many2one(
comodel_name="l10n_br_fiscal.tax",
Expand Down
8 changes: 8 additions & 0 deletions l10n_br_fiscal/views/document_fiscal_line_mixin_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<group name="fiscal_fields" invisible="1">
<field name="currency_id" force_save="1" invisible="1" />
<field name="fiscal_operation_type" force_save="1" invisible="1" />
<field name="operation_fiscal_type" force_save="1" invisible="1" />
<field name="company_id" force_save="1" invisible="1" />
<field name="partner_id" force_save="1" invisible="1" />
<field name="fiscal_type" force_save="1" invisible="1" />
Expand Down Expand Up @@ -496,6 +497,13 @@
/>
</group>
</group>
<group
string="Devolução do IPI"
attrs="{'invisible': [('operation_fiscal_type', 'in', ['purchase', 'sale'])]}"
>
<field name="p_devol" />
<field name="ipi_devol_value" />
</group>
</page>
<page
name="ii"
Expand Down
41 changes: 40 additions & 1 deletion l10n_br_nfe/models/document_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from odoo.addons.l10n_br_fiscal.constants.fiscal import (
CFOP_DESTINATION_EXTERNAL,
EDOC_PURPOSE_COMPLEMENTAR,
EDOC_PURPOSE_DEVOLUCAO,
FINAL_CUSTOMER_NO,
)
from odoo.addons.l10n_br_fiscal.constants.icms import ICMS_CST, ICMS_SN_CST
Expand Down Expand Up @@ -957,7 +959,44 @@ def _export_fields_nfe_40_cofinsnt(self, xsd_fields, class_obj, export_dict):
# Grupo UA. Tributos Devolvidos (para o item da NF-e)
#####################################################

# TODO
nfe40_impostoDevol = fields.Many2one(
comodel_name="nfe.40.impostodevol",
string="impostoDevol",
compute="_compute_nfe40_impostoDevol",
store=True,
)

##########################
# NF-e tag: impostoDevol
# Compute Methods
##########################

@api.depends("p_devol", "ipi_devol_value")
def _compute_nfe40_impostoDevol(self):
for record in self:
if record.nfe40_impostoDevol:
if record.nfe40_impostoDevol.nfe40_IPI:
record.nfe40_impostoDevol.nfe40_IPI.unlink()
record.nfe40_impostoDevol.unlink()
if (
record.document_id.edoc_purpose
in (
EDOC_PURPOSE_DEVOLUCAO,
EDOC_PURPOSE_COMPLEMENTAR,
)
and record.p_devol
and record.ipi_devol_value
):
ipi_devol = self.env["nfe.40.ipi"].create(
{"nfe40_vIPIDevol": record.ipi_devol_value}
)
impostoDevol = record.nfe40_impostoDevol.create(
{
"nfe40_pDevol": record.p_devol,
"nfe40_IPI": ipi_devol.id,
}
)
record.nfe40_impostoDevol = impostoDevol

########################
# NF-e tag: total
Expand Down

0 comments on commit 57e1496

Please sign in to comment.