Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][l10n_br_fiscal] Oca port 14.0 to 16.0 117911 (changes for MDF-e and CT-e) #3582

Draft
wants to merge 15 commits into
base: 16.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions l10n_br_fiscal/constants/fiscal.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,12 @@
MODELO_FISCAL_CFE = "59"
MODELO_FISCAL_CUPOM_FISCAL_ECF = "2D"
MODELO_FISCAL_CTE = "57"
MODELO_FISCAL_MDFE = "58"
MODELO_FISCAL_RL = "04" # Produto Rural
MODELO_FISCAL_01 = "01"
MODELO_FISCAL_04 = "04"


MODELO_FISCAL_EMISSAO_PRODUTO = [
MODELO_FISCAL_NFE,
MODELO_FISCAL_NFCE,
Expand Down
4 changes: 4 additions & 0 deletions l10n_br_fiscal/data/ir_cron.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<field name="numbercall">-1</field>
<field name="model_id" ref="model_l10n_br_fiscal_ncm" />
<field name="code">model._scheduled_update()</field>
<field
name="nextcall"
eval="(DateTime.now()).strftime('%Y-%m-%d 04:00:00')"
/>
</record>

<record
Expand Down
1 change: 1 addition & 0 deletions l10n_br_fiscal/data/l10n_br_fiscal.document.type.csv
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"document_30","30","Bilhete/Recibo do Passageiro","False",,,"icms"
"document_55","55","Nota Fiscal Eletrônica","True","NFe","nf-e","icms"
"document_57","57","Conhecimento de Transporte Eletrônico – CT-e","True","CTe","ct-e","icms"
"document_58","58","Manifesto Eletrônico de Documentos Fiscais","True","MDFe","mdf-e","icms"
"document_59","59","Cupom Fiscal Eletrônico - CF-e","True","CFe","cf-e","icms"
"document_60","60","Cupom Fiscal Eletrônico CF-e-ECF","True",,,"icms"
"document_65","65","Nota Fiscal Eletrônica ao Consumidor Final – NFC-e","True","NFe","nfc-e","icms"
Expand Down
18 changes: 18 additions & 0 deletions l10n_br_fiscal/data/operation_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,24 @@
<field name="state">approved</field>
</record>

<record id="fo_manifesto" model="l10n_br_fiscal.operation">
<field name="code">Manifesto</field>
<field name="name">Manifesto</field>
<field name="fiscal_operation_type">out</field>
<field name="fiscal_type">other</field>
<field name="default_price_unit">sale_price</field>
<field name="state">approved</field>
</record>

<record id="fo_manifesto_manifesto" model="l10n_br_fiscal.operation.line">
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_manifesto" />
<field name="name">Manifesto</field>
<field name="ind_ie_dest">1</field>
<field name="add_to_amount">False</field>
<field name="document_type_id" ref="l10n_br_fiscal.document_58" />
<field name="state">approved</field>
</record>

<!-- l10n_br_fiscal.operation relations -->
<record id="fo_venda" model="l10n_br_fiscal.operation">
<field name="return_fiscal_operation_id" ref="fo_devolucao_venda" />
Expand Down
32 changes: 32 additions & 0 deletions l10n_br_fiscal/demo/company_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@
<field name="active">True</field>
</record>

<record id="empresa_lc_document_57_serie_1" model="l10n_br_fiscal.document.serie">
<field name="code">1</field>
<field name="name">Série 1</field>
<field name="document_type_id" ref="l10n_br_fiscal.document_57" />
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
<field name="active">True</field>
</record>

<record id="empresa_lc_document_58_serie_1" model="l10n_br_fiscal.document.serie">
<field name="code">1</field>
<field name="name">Série 1</field>
<field name="document_type_id" ref="l10n_br_fiscal.document_58" />
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
<field name="active">True</field>
</record>

<record id="empresa_lc_document_65_serie_1" model="l10n_br_fiscal.document.serie">
<field name="code">1</field>
<field name="name">Série 1</field>
Expand Down Expand Up @@ -194,6 +210,22 @@
<field name="active">True</field>
</record>

<record id="empresa_sn_document_57_serie_1" model="l10n_br_fiscal.document.serie">
<field name="code">1</field>
<field name="name">Série 1</field>
<field name="document_type_id" ref="l10n_br_fiscal.document_57" />
<field name="company_id" ref="l10n_br_base.empresa_simples_nacional" />
<field name="active">True</field>
</record>

<record id="empresa_sn_document_58_serie_1" model="l10n_br_fiscal.document.serie">
<field name="code">1</field>
<field name="name">Série 1</field>
<field name="document_type_id" ref="l10n_br_fiscal.document_58" />
<field name="company_id" ref="l10n_br_base.empresa_simples_nacional" />
<field name="active">True</field>
</record>

<record
id="icms_tax_definition_empresa_simples_nacional"
model="l10n_br_fiscal.tax.definition"
Expand Down
30 changes: 23 additions & 7 deletions l10n_br_fiscal/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,29 @@ class Document(models.Model):
default=False,
)

transport_modal = fields.Selection(
selection=[
("01", "Rodoviário"),
("02", "Aéreo"),
("03", "Aquaviário"),
("04", "Ferroviário"),
("05", "Dutoviário"),
("06", "Multimodal"),
],
string="Modal de Transporte",
)

service_provider = fields.Selection(
selection=[
("0", "Remetente"),
("1", "Expedidor"),
("2", "Recebedor"),
("3", "Destinatário"),
("4", "Outros"),
],
string="Tomador do Serviço",
)

@api.constrains("document_key")
def _check_key(self):
for record in self:
Expand Down Expand Up @@ -353,13 +376,6 @@ def _compute_name(self):
def _compute_fiscal_amount(self):
return super()._compute_fiscal_amount()

@api.model_create_multi
def create(self, vals_list):
for values in vals_list:
if not values.get("document_date"):
values["document_date"] = self._date_server_format()
return super().create(vals_list)

def unlink(self):
forbidden_states_unlink = [
SITUACAO_EDOC_AUTORIZADA,
Expand Down
1 change: 1 addition & 0 deletions l10n_br_fiscal/models/document_line_mixin_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def _onchange_fiscal_operation_line_id(self):
nbs=self.nbs_id,
cest=self.cest_id,
city_taxation_code=self.city_taxation_code_id,
service_type=self.service_type_id,
ind_final=self.ind_final,
)

Expand Down
4 changes: 4 additions & 0 deletions l10n_br_fiscal/models/document_mixin_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,7 @@ def _operation_domain(self):
index=True,
unaccent=False,
)

key_random_code = fields.Char(string="Document Key Random Code")
key_check_digit = fields.Char(string="Document Key Check Digit")
total_weight = fields.Float()
11 changes: 11 additions & 0 deletions l10n_br_fiscal/models/document_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ class DocumentRelated(models.Model):

document_date = fields.Date(string="Data")

currency_id = fields.Many2one(
comodel_name="res.currency",
default=lambda self: self.env.company.currency_id,
)
document_total_weight = fields.Float(string="Peso Total")
document_total_amount = fields.Monetary(
string="Valor Total", currency_field="currency_id"
)

@api.constrains("document_key")
def _check_key(self):
for record in self:
Expand Down Expand Up @@ -92,6 +101,8 @@ def _onchange_document_related_id(self):
return False

self.document_type_id = related.document_type_id
self.document_total_amount = related.amount_total
self.document_total_weight = related.total_weight

if related.document_type_id.electronic:
self.document_key = related.document_key
Expand Down
15 changes: 15 additions & 0 deletions l10n_br_fiscal/models/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Operation(models.Model):
string="Operation Line",
readonly=True,
states={"draft": [("readonly", False)]},
copy=True,
)

comment_ids = fields.Many2many(
Expand Down Expand Up @@ -268,3 +269,17 @@ def score(line):
def _onchange_operation_subsequent_ids(self):
for sub_operation in self.operation_subsequent_ids:
sub_operation.fiscal_operation_id = self.id

def copy(self, default=None):
"""
Inherit copy to edit field code. This is needed because the field is
Unique and Required.
"""
self.ensure_one()
if default is None:
default = {}
if self.code:
default["code"] = self.code + _(" (Copy)")

res = super().copy(default)
return res
6 changes: 6 additions & 0 deletions l10n_br_fiscal/models/operation_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class OperationLine(models.Model):
comodel_name="l10n_br_fiscal.tax.definition",
inverse_name="fiscal_operation_line_id",
string="Tax Definition",
copy=True,
)

comment_ids = fields.Many2many(
Expand Down Expand Up @@ -202,6 +203,7 @@ def map_fiscal_taxes(
nbs=None,
cest=None,
city_taxation_code=None,
service_type=None,
ind_final=None,
):
mapping_result = {
Expand All @@ -226,6 +228,7 @@ def map_fiscal_taxes(
nbs=nbs,
cest=cest,
city_taxation_code=city_taxation_code,
service_type=service_type,
):
self._build_mapping_result(mapping_result, tax_definition)

Expand Down Expand Up @@ -270,6 +273,7 @@ def map_fiscal_taxes(
nbs=nbs,
cest=cest,
city_taxation_code=city_taxation_code,
service_type=service_type,
):
self._build_mapping_result(mapping_result, tax_definition)

Expand All @@ -285,6 +289,7 @@ def map_fiscal_taxes(
nbs=nbs,
cest=cest,
city_taxation_code=city_taxation_code,
service_type=service_type,
):
self._build_mapping_result(mapping_result, tax_definition)

Expand All @@ -300,6 +305,7 @@ def map_fiscal_taxes(
nbs=nbs,
cest=cest,
city_taxation_code=city_taxation_code,
service_type=service_type,
):
self._build_mapping_result(mapping_result, tax_definition)

Expand Down
12 changes: 12 additions & 0 deletions l10n_br_fiscal/models/tax_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ def name_get(self):
string="City Taxation Codes",
)

service_type_ids = fields.Many2many(
comodel_name="l10n_br_fiscal.service.type",
relation="tax_definition_service_type_rel",
column1="tax_definition_id",
column2="service_type_id",
string="Fiscal Service Types",
)

ind_final = fields.Selection(
selection=FINAL_CUSTOMER,
string="Final Consumption Operation",
Expand Down Expand Up @@ -423,6 +431,7 @@ def map_tax_definition(
nbs=None,
cest=None,
city_taxation_code=None,
service_type=None,
):
if not ncm:
ncm = product.ncm_id
Expand Down Expand Up @@ -452,6 +461,9 @@ def map_tax_definition(
("city_taxation_code_ids", "=", False),
("city_taxation_code_ids", "=", city_taxation_code.id),
"|",
("service_type_ids", "=", False),
("service_type_ids", "=", service_type.id),
"|",
("product_ids", "=", False),
("product_ids", "=", product.id),
]
Expand Down
1 change: 1 addition & 0 deletions l10n_br_fiscal/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
test_service_type,
test_subsequent_operation,
test_uom_uom,
test_operation,
)
13 changes: 13 additions & 0 deletions l10n_br_fiscal/tests/test_operation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase


class TestOperation(TransactionCase):
def test_copy(self):
"""Test Operation copy()"""
operation_venda = self.env.ref("l10n_br_fiscal.fo_venda")
operation_venda_copy = operation_venda.copy()
self.assertEqual(operation_venda_copy.name, "Venda")
self.assertEqual(operation_venda_copy.code, "Venda (Copy)")
10 changes: 10 additions & 0 deletions l10n_br_fiscal/views/document_related_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
attrs="{'invisible': [('document_type_code', '!=', '04')]}"
/>
</group>
<group
string="Totais"
attrs="{'invisible': [('document_type_code', 'not in', ('55', '57', '58'))]}"
>
<field name="document_total_weight" />
<field
name="document_total_amount"
attrs="{'invisible': [('document_related_id', '!=', False)]}"
/>
</group>
</form>
</field>
</record>
Expand Down
5 changes: 5 additions & 0 deletions l10n_br_fiscal/views/document_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@
<field name="state_fiscal" />
</group>
</group>
<group name="CT-e Info">
<field name="transport_modal" />
<field name="service_provider" />
</group>
<notebook>
<page name="document" string="Document Info">
<group name="Document">
Expand Down Expand Up @@ -402,6 +406,7 @@
<page name="delivery" string="Delivery">
<group>
<field name="force_compute_delivery_costs_by_total" />
<field name="total_weight" />
</group>
</page>
<page name="amounts" string="Amounts">
Expand Down
20 changes: 20 additions & 0 deletions l10n_br_fiscal/views/l10n_br_fiscal_action.xml
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,26 @@
</field>
</record>

<!-- CT-e Document -->
<record id="cte_document_action" model="ir.actions.act_window">
<field name="name">CT-e</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">l10n_br_fiscal.document</field>
<field name="view_mode">tree,form</field>
<field
name="domain"
eval="[('document_type_id', '=', ref('l10n_br_fiscal.document_57'))]"
/>
<field name="view_id" ref="document_tree" />
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Add a new CTe
</p><p>
Here you can create CT-es
</p>
</field>
</record>

<record id="document_all_action" model="ir.actions.act_window">
<field name="name">All Documents</field>
<field name="type">ir.actions.act_window</field>
Expand Down
9 changes: 9 additions & 0 deletions l10n_br_fiscal/views/l10n_br_fiscal_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
sequence="11"
/>

<!-- CTe Fiscal Documents-->
<menuitem
id="document_cte_menu"
action="cte_document_action"
name="CT-e"
parent="document_menu"
sequence="20"
/>

<!-- Sub Menu for All Documents-->
<menuitem
id="document_sub_menu"
Expand Down
Loading
Loading