diff --git a/l10n_br_fiscal/__manifest__.py b/l10n_br_fiscal/__manifest__.py index 7a299b7b6989..0a82c71ea025 100644 --- a/l10n_br_fiscal/__manifest__.py +++ b/l10n_br_fiscal/__manifest__.py @@ -84,6 +84,9 @@ "views/invalidate_number_view.xml", "views/city_taxation_code.xml", "views/operation_dashboard_view.xml", + "views/benefit_code_view.xml", + # Wizards + "wizards/document_import_wizard_mixin.xml", # Actions "views/l10n_br_fiscal_action.xml", # Menus diff --git a/l10n_br_fiscal/data/l10n_br_fiscal_comment_data.xml b/l10n_br_fiscal/data/l10n_br_fiscal_comment_data.xml index f36815627ab5..e28a134fcfd3 100644 --- a/l10n_br_fiscal/data/l10n_br_fiscal_comment_data.xml +++ b/l10n_br_fiscal/data/l10n_br_fiscal_comment_data.xml @@ -42,4 +42,14 @@ fiscal l10n_br_fiscal.document.mixin + + + Código de benefício fiscal + cBenef: ${benefit_code} + fiscal + l10n_br_fiscal.document.line.mixin + diff --git a/l10n_br_fiscal/models/__init__.py b/l10n_br_fiscal/models/__init__.py index e0562968855e..b0fd5b8dd170 100644 --- a/l10n_br_fiscal/models/__init__.py +++ b/l10n_br_fiscal/models/__init__.py @@ -59,3 +59,4 @@ from . import document_email from . import city_taxation_code from . import document_supplement +from . import benefit diff --git a/l10n_br_fiscal/models/benefit.py b/l10n_br_fiscal/models/benefit.py new file mode 100644 index 000000000000..60ba16dd6303 --- /dev/null +++ b/l10n_br_fiscal/models/benefit.py @@ -0,0 +1,20 @@ +from odoo import api, fields, models + + +class Benefit(models.Model): + _name = "l10n_br_fiscal.benefit" + _inherit = "l10n_br_fiscal.data.abstract" + + benefit_code = fields.Char( + string="Concatenated Code and Name", + compute="_compute_benefit_code", + store=True, + ) + + @api.depends("code", "name") + def _compute_benefit_code(self): + for record in self: + if record.code and record.name: + record.benefit_code = f"{record.code}{record.name}" + else: + record.benefit_code = record.code or record.name or "" diff --git a/l10n_br_fiscal/models/document_line_mixin.py b/l10n_br_fiscal/models/document_line_mixin.py index ed1cd3ea2585..b0c89b7fcb95 100644 --- a/l10n_br_fiscal/models/document_line_mixin.py +++ b/l10n_br_fiscal/models/document_line_mixin.py @@ -894,3 +894,9 @@ def _operation_domain(self): comodel_name="l10n_br_fiscal.cnae", string="CNAE Code", ) + + benefit_code_ids = fields.Many2many( + string="Código de benefício fiscal", + comodel_name="l10n_br_fiscal.benefit", + related="icms_tax_id.benefit_code_ids", + ) diff --git a/l10n_br_fiscal/models/document_line_mixin_methods.py b/l10n_br_fiscal/models/document_line_mixin_methods.py index 902d55cc635d..dcf9cd63856f 100644 --- a/l10n_br_fiscal/models/document_line_mixin_methods.py +++ b/l10n_br_fiscal/models/document_line_mixin_methods.py @@ -340,6 +340,14 @@ def _get_product_price(self): self.price_unit = price.get(self.fiscal_operation_id.default_price_unit, 0.00) + def _get_benefit_code(self): + self.ensure_one() + return "|".join( + benefit.benefit_code + for benefit in self.benefit_code_ids + if benefit.benefit_code + ) + def __document_comment_vals(self): self.ensure_one() return { @@ -351,8 +359,13 @@ def __document_comment_vals(self): def _document_comment(self): for d in self: + benefit_code = d._get_benefit_code() + + comment_vals = d.__document_comment_vals() + comment_vals["benefit_code"] = benefit_code + d.additional_data = d.comment_ids.compute_message( - d.__document_comment_vals(), d.manual_additional_data + comment_vals, d.manual_additional_data ) def _get_fiscal_partner(self): diff --git a/l10n_br_fiscal/models/tax.py b/l10n_br_fiscal/models/tax.py index 1a583402aa80..15b348d9b389 100644 --- a/l10n_br_fiscal/models/tax.py +++ b/l10n_br_fiscal/models/tax.py @@ -167,6 +167,15 @@ class Tax(models.Model): string="PFC Value", digits="Fiscal Tax Value", required=True ) + # TODO: Criar um company id para definir a visibilidade do campo no form + # utilizando o state_id como parâmetro (DF, GO, PR, RJ, RS e SC). + # A visibilidade também pode ser controlada dependendo do + # cst/cson informado no imposto (apenas ICMS) + benefit_code_ids = fields.Many2many( + string="Código de benefício fiscal", + comodel_name="l10n_br_fiscal.benefit", + ) + _sql_constraints = [ ("fiscal_tax_code_uniq", "unique (name)", "Tax already exists with this name !") ] diff --git a/l10n_br_fiscal/security/ir.model.access.csv b/l10n_br_fiscal/security/ir.model.access.csv index 5242c8d02d2f..770bed62ce11 100644 --- a/l10n_br_fiscal/security/ir.model.access.csv +++ b/l10n_br_fiscal/security/ir.model.access.csv @@ -101,3 +101,6 @@ "l10n_br_fiscal_city_taxation_code_manager","Fiscal City Taxation Code for Manager","model_l10n_br_fiscal_city_taxation_code","l10n_br_fiscal.group_user",1,1,1,1 "l10n_br_fiscal_base_wizard_mixin_user",l10n_br_fiscal_base_wizard_mixin,model_l10n_br_fiscal_base_wizard_mixin,base.group_user,1,1,1,1 "l10n_br_fiscal_document_status_wizard_user",l10n_br_fiscal_document_status_wizard,model_l10n_br_fiscal_document_status_wizard,base.group_user,1,1,1,1 +"l10n_br_fiscal_document_import_wizard_mixin_user",l10n_br_fiscal_document_import_wizard_mixin_user,model_l10n_br_fiscal_document_import_wizard_mixin,base.group_user,1,1,1,1 +"l10n_br_fiscal_benefit_user","Benefit Code for User","model_l10n_br_fiscal_benefit","l10n_br_fiscal.group_user",1,0,0,0 +"l10n_br_fiscal_benefit_manager","Benefit Code for Manager","model_l10n_br_fiscal_benefit","l10n_br_fiscal.group_manager",1,1,1,1 diff --git a/l10n_br_fiscal/views/benefit_code_view.xml b/l10n_br_fiscal/views/benefit_code_view.xml new file mode 100644 index 000000000000..9b736ba2696a --- /dev/null +++ b/l10n_br_fiscal/views/benefit_code_view.xml @@ -0,0 +1,28 @@ + + + + l10n_br_fiscal.benefit.code.tree + l10n_br_fiscal.benefit + + + + + + + + + + l10n_br_fiscal.benefit.code.form + l10n_br_fiscal.benefit + + + + + + + + + + + + diff --git a/l10n_br_fiscal/views/document_fiscal_line_mixin_view.xml b/l10n_br_fiscal/views/document_fiscal_line_mixin_view.xml index 6786a14908c1..0d1ed9c189e5 100644 --- a/l10n_br_fiscal/views/document_fiscal_line_mixin_view.xml +++ b/l10n_br_fiscal/views/document_fiscal_line_mixin_view.xml @@ -179,6 +179,7 @@ force_save="1" attrs="{'readonly': ['|', ('icms_tax_id', '!=', False), ('icmssn_tax_id', '!=', False)]}" /> + diff --git a/l10n_br_fiscal/views/l10n_br_fiscal_action.xml b/l10n_br_fiscal/views/l10n_br_fiscal_action.xml index 388fd5d1cf62..f4e434b751df 100644 --- a/l10n_br_fiscal/views/l10n_br_fiscal_action.xml +++ b/l10n_br_fiscal/views/l10n_br_fiscal_action.xml @@ -100,6 +100,19 @@ + + Benefit Code + ir.actions.act_window + l10n_br_fiscal.benefit + tree,form + + + + Add a new Benefit Code + + + + ICMS Regulation diff --git a/l10n_br_fiscal/views/l10n_br_fiscal_menu.xml b/l10n_br_fiscal/views/l10n_br_fiscal_menu.xml index 12cf90f909aa..9acaf86ba8ed 100644 --- a/l10n_br_fiscal/views/l10n_br_fiscal_menu.xml +++ b/l10n_br_fiscal/views/l10n_br_fiscal_menu.xml @@ -362,6 +362,23 @@ sequence="20" /> + + + + + + diff --git a/l10n_br_nfe/models/document_line.py b/l10n_br_nfe/models/document_line.py index 6f20b551cb85..0cf266444a1d 100644 --- a/l10n_br_nfe/models/document_line.py +++ b/l10n_br_nfe/models/document_line.py @@ -143,7 +143,9 @@ class NFeLine(spec_models.StackedModel): # CNPJFab TODO - nfe40_cBenef = fields.Char(related="icms_tax_benefit_code") + nfe40_cBenef = fields.Char( + compute="_compute_nfe40_cBenef", store=True, string="Código de Benefício Fiscal" + ) # TODO em uma importação de XML deve considerar esse campo na busca do # ncm_id @@ -222,6 +224,8 @@ def _export_fields_nfe_40_prod(self, xsd_fields, class_obj, export_dict): nfe40_cEAN = self.product_id.barcode or "SEM GTIN" export_dict["cEAN"] = export_dict["cEANTrib"] = nfe40_cEAN + export_dict["cBenef"] = self.nfe40_cBenef or "" + ########################################################### # NF-e tag: DI # Grupo I01. Produtos e Serviços / Declaração de Importação @@ -400,6 +404,17 @@ def _export_fields_nfe_40_imposto(self, xsd_fields, class_obj, export_dict): string="ICMS SN Crédito", related="icmssn_credit_value" ) + ########################## + # NF-e tag: cBenef + # Compute Method + ########################## + + @api.depends("benefit_code_ids") + def _compute_nfe40_cBenef(self): + for record in self: + first_benefit = record.benefit_code_ids[:1] + record.nfe40_cBenef = first_benefit.benefit_code if first_benefit else "" + ########################## # NF-e tag: ICMS # Compute Methods
+ Add a new Benefit Code +