Skip to content

Commit

Permalink
[WIP] cBenef
Browse files Browse the repository at this point in the history
  • Loading branch information
corredato committed Dec 19, 2024
1 parent 229efde commit f0dd3cc
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 2 deletions.
1 change: 1 addition & 0 deletions l10n_br_fiscal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"views/invalidate_number_view.xml",
"views/city_taxation_code.xml",
"views/operation_dashboard_view.xml",
"views/benefit_code_view.xml",
# Actions
"views/l10n_br_fiscal_action.xml",
# Menus
Expand Down
10 changes: 10 additions & 0 deletions l10n_br_fiscal/data/l10n_br_fiscal_comment_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,14 @@
<field name="comment_type">fiscal</field>
<field name="object">l10n_br_fiscal.document.mixin</field>
</record>

<record
id="fiscal_comment_codigo_do_beneficio_fiscal"
model="l10n_br_fiscal.comment"
>
<field name="name">Código de benefício fiscal</field>
<field name="comment"> cBenef: ${benefit_code}</field>
<field name="comment_type">fiscal</field>
<field name="object">l10n_br_fiscal.document.line.mixin</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions l10n_br_fiscal/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@
from . import document_email
from . import city_taxation_code
from . import document_supplement
from . import benefit
20 changes: 20 additions & 0 deletions l10n_br_fiscal/models/benefit.py
Original file line number Diff line number Diff line change
@@ -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 ""
6 changes: 6 additions & 0 deletions l10n_br_fiscal/models/document_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
15 changes: 14 additions & 1 deletion l10n_br_fiscal/models/document_line_mixin_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions l10n_br_fiscal/models/tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 !")
]
Expand Down
3 changes: 3 additions & 0 deletions l10n_br_fiscal/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions l10n_br_fiscal/views/benefit_code_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version='1.0' encoding='utf-8' ?>
<odoo>
<record id="benefit_code_tree" model="ir.ui.view">
<field name="name">l10n_br_fiscal.benefit.code.tree</field>
<field name="model">l10n_br_fiscal.benefit</field>
<field name="arch" type="xml">
<tree>
<field name="code" />
<field name="name" />
</tree>
</field>
</record>

<record id="benefit_code_form" model="ir.ui.view">
<field name="name">l10n_br_fiscal.benefit.code.form</field>
<field name="model">l10n_br_fiscal.benefit</field>
<field name="arch" type="xml">
<form string="Benefit Code">
<sheet>
<group>
<field name="code" />
<field name="name" />
</group>
</sheet>
</form>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions l10n_br_fiscal/views/document_fiscal_line_mixin_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
force_save="1"
attrs="{'readonly': ['|', ('icms_tax_id', '!=', False), ('icmssn_tax_id', '!=', False)]}"
/>
<field name="benefit_code_ids" widget="many2many_tags" />
<field name="icms_tax_benefit_id" force_save="1" />
</group>
<group>
Expand Down
13 changes: 13 additions & 0 deletions l10n_br_fiscal/views/l10n_br_fiscal_action.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@
</field>
</record>

<record id="benefit_code_action" model="ir.actions.act_window">
<field name="name">Benefit Code</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">l10n_br_fiscal.benefit</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="benefit_code_tree" />
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Add a new Benefit Code
</p>
</field>
</record>

<!-- Tax ICMS Regulation -->
<record id="tax_icms_regulation_action" model="ir.actions.act_window">
<field name="name">ICMS Regulation</field>
Expand Down
17 changes: 17 additions & 0 deletions l10n_br_fiscal/views/l10n_br_fiscal_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,23 @@
sequence="20"
/>

<menuitem
id="benefit_code_config_menu"
name="Benefit Code"
groups="l10n_br_fiscal.group_manager"
parent="configuration_menu"
sequence="35"
/>

<!-- Benefit Code -->
<menuitem
id="benefit_code_menu"
action="benefit_code_action"
groups="l10n_br_fiscal.group_manager"
parent="benefit_code_config_menu"
sequence="25"
/>

<!-- Simplified Tax -->
<menuitem
id="simplified_tax_menu"
Expand Down
1 change: 1 addition & 0 deletions l10n_br_fiscal/views/tax_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
attrs="{'invisible': [('tax_domain', 'not in', ['icms', 'icmssn', 'ipi', 'pis', 'cofins'])]}"
options="{'no_create': True, 'no_create_edit': True}"
/>
<field name="benefit_code_ids" widget="many2many_tags" />
</group>
</sheet>
</form>
Expand Down
17 changes: 16 additions & 1 deletion l10n_br_nfe/models/document_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f0dd3cc

Please sign in to comment.