Skip to content

Commit

Permalink
[FIX] l10n_br_cte: test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Nov 13, 2024
1 parent 3a3b21d commit 880864e
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 48 deletions.
10 changes: 6 additions & 4 deletions l10n_br_cte/constants/cte.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@

CTE_EMISSION_PROCESS_DEFAULT = "0"

CTE_TYPE = [
("0", "CT-e Normal"),
("1", "CT-e de Complemento de Valores"),
("3", "CT-e de Substituição"),
]

# CTE_TYPE
# 0 - CT-e Normal;
# 1 - CT-e de Complemento de Valores;
# 3 - CT-e de Substituição
CTE_TYPE_DEFAULT = "0"
2 changes: 1 addition & 1 deletion l10n_br_cte/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from . import document
from . import res_company
from . import res_partner
from . import document
from . import document_related
from . import document_line
from . import res_config_settings
Expand Down
60 changes: 44 additions & 16 deletions l10n_br_cte/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# TODO: precisa tratar
# from erpbrasil.edoc.cte import TransmissaoCTE
from erpbrasil.base.fiscal.edoc import ChaveEdoc
from lxml import etree
from nfelib.cte.bindings.v4_0.cte_v4_00 import Cte
from nfelib.cte.bindings.v4_0.proc_cte_v4_00 import CteProc
Expand All @@ -22,7 +23,7 @@
from xsdata.formats.dataclass.parsers import XmlParser

from odoo import _, api, fields
from odoo.exceptions import UserError
from odoo.exceptions import UserError, ValidationError

from odoo.addons.l10n_br_cte_spec.models.v4_0.cte_modal_ferroviario_v4_00 import (
FERROV_TPTRAF,
Expand Down Expand Up @@ -57,6 +58,9 @@
from odoo.addons.l10n_br_fiscal.constants.icms import ICMS_CST, ICMS_SN_CST
from odoo.addons.spec_driven_model.models import spec_models

from ..constants.cte import (
CTE_TRANSMISSIONS,
)
from ..constants.modal import (
CTE_MODAL_DEFAULT,
CTE_MODAL_VERSION_DEFAULT,
Expand Down Expand Up @@ -86,27 +90,23 @@ class CTe(spec_models.StackedModel):
_inherit = [
"l10n_br_fiscal.document",
"cte.40.tcte_infcte",
"cte.40.tcte_imp",
"cte.40.tcte_fat",
]
_cte40_odoo_module = (
"odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00"
)
_cte40_stacking_mixin = "cte.40.tcte_infcte"
_cte40_stacking_skip_paths = (
"cte40_fluxo",
"cte40_semData",
"cte40_noInter",
"cte40_comHora",
"cte40_noPeriodo",
"cte40_NFref_ide_id",
"cte40_comHora",
"cte40_noInter",
# "cte40_NFref_ide_id",
)

# all m2o at this level will be stacked even if not required:
_cte40_stacking_force_paths = (
"infcte.compl",
"infcte.compl.entrega" "infcte.vprest",
"infcte.imp",
"infcte.compl.entrega",
)
_cte_search_keys = ["cte40_Id"]

Expand Down Expand Up @@ -223,7 +223,8 @@ def _inverse_cte40_Id(self):

cte40_dhEmi = fields.Datetime(related="document_date")

cte40_cDV = fields.Char(compute="_compute_cte40_cDV", store=True)
# cte40_cDV = fields.Char(compute="_compute_cte40_cDV", store=True)
# cte40_cDV = fields.Char(related="key_check_digit")

cte40_procEmi = fields.Selection(default="0")

Expand Down Expand Up @@ -306,6 +307,13 @@ def _inverse_cte40_Id(self):
default="1",
)

cte_transmission = fields.Selection(
selection=CTE_TRANSMISSIONS,
string="CTE Transmission",
copy=False,
default=lambda self: self.env.company.cte_transmission,
)

cte40_tpImp = fields.Selection(
selection=[("1", "Retrato"), ("2", "Paisagem")], default="1"
)
Expand Down Expand Up @@ -358,11 +366,11 @@ def _compute_cte40_CFOP(self):
if rec.fiscal_line_ids:
rec.cte40_CFOP = rec.fiscal_line_ids[0].cfop_id.code

@api.depends("document_key")
def _compute_cte40_cDV(self):
for rec in self.filtered(filter_processador_edoc_cte):
if rec.document_key:
rec.cte40_cDV = rec.document_key[-1]
# @api.depends("document_key")
# def _compute_cte40_cDV(self):
# for rec in self.filtered(filter_processador_edoc_cte):
# if rec.document_key:
# rec.cte40_cDV = rec.document_key[-1]

def _compute_cte40_cct(self):
for rec in self.filtered(filter_processador_edoc_cte):
Expand Down Expand Up @@ -1704,7 +1712,7 @@ def get_cte_qrcode(self):
# return

processador = self._edoc_processor()
# if self.nfe_transmission == "1":
# if self.cte_transmission == "1":
# return processador.monta_qrcode(self.document_key)
return processador.monta_qrcode(self.document_key)

Expand Down Expand Up @@ -1822,3 +1830,23 @@ def import_binding_cte(self, binding, edoc_type="out"):
document.issuer = "partner"

return document

def _document_number(self):
# TODO: Criar campos no fiscal para codigo aleatorio e digito verificador,
# pois outros modelos também precisam dessescampos: CT-e, MDF-e etc
result = super()._document_number()
for record in self.filtered(filter_processador_edoc_cte):
if record.document_key:
try:
chave = ChaveEdoc(record.document_key)
record.cte40_cCT = chave.codigo_aleatorio
record.cte40_cDV = chave.digito_verificador
except Exception as e:
raise ValidationError(
_(
"%(name)s:\n %(error)s",
name=record.document_type_id.name,
error=e,
)
) from e
return result
47 changes: 24 additions & 23 deletions l10n_br_cte/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@

from odoo.addons.spec_driven_model.models import spec_models

from ..constants.cte import (
CTE_ENVIRONMENT_DEFAULT,
CTE_ENVIRONMENTS,
CTE_TRANSMISSION_DEFAULT,
CTE_TRANSMISSIONS,
CTE_TYPE,
CTE_TYPE_DEFAULT,
CTE_VERSION_DEFAULT,
CTE_VERSIONS,
)


class ResCompany(spec_models.SpecModel):
_name = "res.company"
Expand All @@ -27,38 +38,28 @@ class ResCompany(spec_models.SpecModel):
)

cte_transmission = fields.Selection(
selection=[
("1", "Normal"),
("2", "Regime Especial NFF"),
("4", "EPEC pela SVC"),
("5", "Contingência FSDA"),
("7", "Contingência SVC-RS"),
("8", "Contingência SVC-SP"),
],
string="CT-e Transmission Type",
default="1",
selection=CTE_TRANSMISSIONS,
string="CTe Transmission",
copy=False,
default=CTE_TRANSMISSION_DEFAULT,
)

cte_type = fields.Selection(
selection=[
("0", "CT-e Normal"),
("1", "CT-e de Complemento de Valores"),
("3", "CT-e de Substituição"),
],
string="CT-e Type",
default="0",
selection=CTE_TYPE,
string="CTe Type",
default=CTE_TYPE_DEFAULT,
)

cte_environment = fields.Selection(
selection=[("1", "Produção"), ("2", "Homologação")],
string="CT-e Environment",
default="2",
selection=CTE_ENVIRONMENTS,
string="CTe Environment",
default=CTE_ENVIRONMENT_DEFAULT,
)

cte_version = fields.Selection(
selection=[("3.00", "3.00"), ("4.00", "4.00")],
string="CT-e Version",
default="4.00",
selection=CTE_VERSIONS,
string="CTe Version",
default=CTE_VERSION_DEFAULT,
)

# processador_edoc = fields.Selection(
Expand Down
6 changes: 6 additions & 0 deletions l10n_br_cte/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ class ResConfigSettings(models.TransientModel):
related="company_id.cte_authorize_accountant_download_xml",
readonly=False,
)

cte_transmission = fields.Selection(
string="NFe Transmission",
related="company_id.cte_transmission",
readonly=False,
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@
<indIEToma>1</indIEToma>
<toma3 />
<toma4>
<enderToma />
<enderToma>
<xLgr>Rua Samuel Morse</xLgr>
<nro>135</nro>
<xCpl>20º andar - Conjunto 151</xCpl>
<xBairro>Brooklin</xBairro>
<cMun>3550308</cMun>
<xMun>São Paulo</xMun>
<CEP>04576060</CEP>
<UF>SP</UF>
<cPais>1058</cPais>
<xPais>Brasil</xPais>
</enderToma>
</toma4>
</ide>
<compl>
Expand All @@ -41,7 +52,20 @@
</ObsFisco>
</compl>
<emit>
<enderEmit />
<CNPJ>59594315000157</CNPJ>
<IE>755338250133</IE>
<xNome>TESTE - Simples Nacional</xNome>
<xFant>TESTE - Simples Nacional</xFant>
<enderEmit>
<xLgr>Rua Paulo Dias</xLgr>
<nro>586</nro>
<xBairro>Vila Santa Luzia</xBairro>
<cMun>3501152</cMun>
<xMun>Alumínio</xMun>
<CEP>18125000</CEP>
<UF>SP</UF>
<fone>2130109965</fone>
</enderEmit>
<CRT>1</CRT>
</emit>
<rem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@
<indIEToma>1</indIEToma>
<toma3 />
<toma4>
<enderToma />
<enderToma>
<xLgr>Rua Samuel Morse</xLgr>
<nro>135</nro>
<xCpl>20º andar - Conjunto 151</xCpl>
<xBairro>Brooklin</xBairro>
<cMun>3550308</cMun>
<xMun>São Paulo</xMun>
<CEP>04576060</CEP>
<UF>SP</UF>
<cPais>1058</cPais>
<xPais>Brasil</xPais>
</enderToma>
</toma4>
</ide>
<compl>
Expand All @@ -41,7 +52,20 @@
</ObsFisco>
</compl>
<emit>
<enderEmit />
<CNPJ>81583054000129</CNPJ>
<IE>078016350838</IE>
<xNome>Empresa Lucro Presumido Ltda</xNome>
<xFant>Empresa Lucro Presumido</xFant>
<enderEmit>
<xLgr>Avenida Paulista</xLgr>
<nro>1</nro>
<xBairro>Bela Vista</xBairro>
<cMun>3550308</cMun>
<xMun>São Paulo</xMun>
<CEP>01311000</CEP>
<UF>SP</UF>
<fone>551199999999</fone>
</enderEmit>
<CRT>3</CRT>
</emit>
<rem>
Expand Down

0 comments on commit 880864e

Please sign in to comment.