From 8e6fcab96d1c1b1f8857d7a81c191c6e14f42efd Mon Sep 17 00:00:00 2001 From: ODBreno Date: Wed, 19 Jul 2023 10:13:21 -0300 Subject: [PATCH] [IMP] Model Fields Created --- l10n_br_cte/models/__init__.py | 1 + l10n_br_cte/models/document.py | 215 +++++++++++------- l10n_br_cte/models/document_line.py | 53 +++-- l10n_br_cte/models/document_related.py | 96 +++++--- l10n_br_cte/models/res_company.py | 37 ++- l10n_br_cte/models/res_partner.py | 45 ++-- .../models/v4_0/cte_tipos_basico_v4_00.py | 12 +- 7 files changed, 314 insertions(+), 145 deletions(-) diff --git a/l10n_br_cte/models/__init__.py b/l10n_br_cte/models/__init__.py index 7a93b6edbe54..612c3174db49 100644 --- a/l10n_br_cte/models/__init__.py +++ b/l10n_br_cte/models/__init__.py @@ -3,3 +3,4 @@ from . import res_partner from . import document_related from . import document_line +from . import res_config_settings diff --git a/l10n_br_cte/models/document.py b/l10n_br_cte/models/document.py index 93fdf85f6c4d..145f74b51239 100644 --- a/l10n_br_cte/models/document.py +++ b/l10n_br_cte/models/document.py @@ -88,34 +88,43 @@ def _inverse_cte40_Id(self): ########################## cte40_cUF = fields.Char( - related="company_id.partner_id.state_id.ibge_code", string="cte40_cUF" + related="company_id.partner_id.state_id.ibge_code", + string="cte40_cUF", + store=True, ) - cte40_cCT = fields.Char() # TODO + cte40_cCT = fields.Char(related="document_key", store=True) - cte40_CFOP = fields.Char(compute="_compute_cte40_CFOP") + cfop_id = fields.Many2one( + comodel_name="l10n_br_fiscal.cfop", + string="CFOP", + ) + + cte40_CFOP = fields.Char(related="cfop_id.code", store=True) - cte40_natOp = fields.Char(related="operation_name") + cte40_natOp = fields.Char(related="operation_name", store=True) - cte40_mod = fields.Char(related="document_type_id.code", string="cte40_mod") + cte40_mod = fields.Char( + related="document_type_id.code", string="cte40_mod", store=True + ) - cte40_serie = fields.Char(related="document_serie") + cte40_serie = fields.Char(related="document_serie", store=True) - cte40_nCT = fields.Char(related="document_number") + cte40_nCT = fields.Char(related="document_number", store=True) - cte40_dhEmi = fields.Datetime(related="document_date") + cte40_dhEmi = fields.Datetime(related="document_date", store=True) - cte40_tpImp = fields.Selection(related="tpImp") + cte40_tpImp = fields.Selection(related="tpImp", store=True) - cte40_tpEmis = fields.Selection(related="cte_transmission") + cte40_tpEmis = fields.Selection(related="cte_transmission", store=True) - cte40_cDV = fields.Char() # TODO + cte40_cDV = fields.Char(compute="_compute_cDV", store=True) - cte40_tpAmb = fields.Selection(related="cte_environment") + cte40_tpAmb = fields.Selection(related="cte_environment", store=True) - cte40_tpCTe = fields.Selection(related="tpCTe") + cte40_tpCTe = fields.Selection(related="tpCTe", store=True) - cte40_procEmi = fields.Selection(default="0") + cte40_procEmi = fields.Selection(default="0", store=True) cte40_verProc = fields.Char( copy=False, @@ -124,56 +133,53 @@ def _inverse_cte40_Id(self): .get_param("l10n_br_cte.version.name", default="Odoo Brasil OCA v14"), ) - cte40_cMunEnv = fields.Char( - related="company_id.partner_id.city_id.ibge_code" - ) # TODO compute pro exterior + cte40_cMunEnv = fields.Char(compute="_compute_cte40_data", store=True) - cte40_xMunEnv = fields.Char( - related="company_id.partner_id.city_id.name" - ) # TODO compute pro exterior + cte40_xMunEnv = fields.Char(compute="_compute_cte40_data", store=True) cte40_UFEnv = fields.Char( - related="company_id.partner_id.state_id.code", - string="cte40_UFEnv", + compute="_compute_cte40_data", string="cte40_UFEnv", store=True ) - cte40_tpServ = fields.Selection(related="tpServ") + cte40_tpServ = fields.Selection(related="tpServ", store=True) - cte40_indIEToma = fields.Char() # TODO IE tomador + cte40_indIEToma = fields.Char(compute="_compute_toma", store=True) - cte40_cMunIni = fields.Char( - related="company_id.partner_id.city_id.ibge_code" - ) # TODO compute pro exterior + cte40_cMunIni = fields.Char(compute="_compute_cte40_data", store=True) - cte40_xMunIni = fields.Char( - related="company_id.partner_id.city_id.name" - ) # TODO compute pro exterior + cte40_xMunIni = fields.Char(compute="_compute_cte40_data", store=True) - cte40_UFIni = fields.Char( - related="company_id.partner_id.state_id.ibge_code", string="cte40_cUF" - ) + cte40_UFIni = fields.Char(compute="_compute_cte40_data", store=True) - cte40_cMunFim = fields.Char(related="partner_id.city_id.ibge_code") + cte40_cMunFim = fields.Char( + compute="_compute_cte40_data", + related="partner_id.city_id.ibge_code", + store=True, + ) - cte40_xMunFim = fields.Char(related="partner_id.city_id.name") + cte40_xMunFim = fields.Char( + compute="_compute_cte40_data", related="partner_id.city_id.name", store=True + ) - cte40_UFFim = fields.Char(related="partner_id.state_id.code", string="cte40_cUF") + cte40_UFFim = fields.Char( + compute="_compute_cte40_data", string="cte40_cUF", store=True + ) - cte40_retira = fields.Selection(related="retira") + cte40_retira = fields.Selection(related="retira", store=True) cte40_toma4 = fields.Many2one( comodel_name="res.partner", compute="_compute_toma", readonly=True, string="Tomador de Serviço", - ) # TODO + ) cte40_toma3 = fields.Many2one( comodel_name="res.partner", compute="_compute_toma", readonly=True, string="Tomador de Serviço", - ) # TODO + ) ########################## # CT-e tag: ide @@ -182,25 +188,51 @@ def _inverse_cte40_Id(self): def _compute_toma(self): for doc in self: - if self.service_provider in ["0", "1"]: + if doc.service_provider in ["0", "1"]: doc.cte40_toma3 = doc.company_id + doc.cte40_indIEToma = doc.cte40_toma3.inscr_est doc.cte40_toma4 = None - elif self.service_provider in ["2", "3"]: + elif doc.service_provider in ["2", "3"]: doc.cte40_toma3 = doc.partner_id + doc.cte40_indIEToma = doc.cte40_toma3.inscr_est doc.cte40_toma4 = None else: doc.cte40_toma3 = None doc.cte40_toma4 = doc.partner_id + doc.cte40_indIEToma = doc.cte40_toma4.inscr_est + + def _compute_cDV(self): + for rec in self: + if rec.document_key: + rec.cte40_cDV = rec.document_key[:-1] @api.depends("partner_id", "company_id") - def _compute_cte40_exterior(self): + def _compute_cte40_data(self): for doc in self: - if doc.company_id.partner_id.state_id == doc.partner_id.state_id: - doc.cte40_idDest = "1" - elif doc.company_id.partner_id.country_id == doc.partner_id.country_id: - doc.cte40_idDest = "2" + if doc.company_id.partner_id.country_id == doc.partner_id.country_id: + doc.cte40_xMunIni = doc.company_id.partner_id.city_id.name + doc.cte40_cMunIni = doc.company_id.partner_id.city_id.ibge_code + doc.cte40_xMunEnv = doc.company_id.partner_id.city_id.name + doc.cte40_cMunEnv = doc.company_id.partner_id.city_id.ibge_code + doc.cte40_UFEnv = doc.company_id.partner_id.state_id.code + doc.cte40_UFIni = doc.company_id.partner_id.state_id.ibge_code + doc.cte40_cMunFim = doc.partner_id.city_id.ibge_code + doc.cte40_xMunFim = doc.partner_id.city_id.name + doc.cte40_UFFim = doc.partner_id.state_id.code else: - doc.cte40_idDest = "3" + doc.cte40_UFIni = "EX" + doc.cte40_UFEnv = "EX" + doc.cte40_xMunIni = "EXTERIOR" + doc.cte40_cMunIni = "9999999" + doc.cte40_xMunEnv = ( + doc.company_id.partner_id.country_id.name + + "/" + + doc.company_id.partner_id.city_id.name + ) + doc.cte40_cMunEnv = "9999999" + doc.cte40_cMunFim = "9999999" + doc.cte40_xMunFim = "EXTERIOR" + doc.cte40_UFFim = "EX" ########################## # CT-e tag: emit @@ -211,11 +243,13 @@ def _compute_cte40_exterior(self): compute="_compute_emit_data", readonly=True, string="Emit", + store=True, ) cte40_CRT = fields.Selection( related="company_tax_framework", string="Código de Regime Tributário (CTe)", + store=True, ) ########################## @@ -236,6 +270,7 @@ def _compute_emit_data(self): compute="_compute_rem_data", readonly=True, string="Rem", + store=True, ) ########################## @@ -256,6 +291,7 @@ def _compute_rem_data(self): compute="_compute_exped_data", readonly=True, string="Exped", + store=True, ) ########################## @@ -276,6 +312,7 @@ def _compute_exped_data(self): compute="_compute_receb_data", readonly=True, string="Receb", + store=True, ) ########################## @@ -296,6 +333,7 @@ def _compute_receb_data(self): compute="_compute_dest_data", readonly=True, string="Dest", + store=True, ) ########################## @@ -305,42 +343,63 @@ def _compute_receb_data(self): def _compute_dest_data(self): for doc in self: # TODO if out - doc.cte40_dest = doc.company_id + doc.cte40_dest = doc.partner_id ########################## - # CT-e tag: vPrest + # CT-e tag: imp ########################## - cte40_vTPrest = fields.Float( - string="vTPrest", + cte40_imp = fields.One2many( + comodel_name="l10n_br_fiscal.document.line", related="fiscal_line_ids" ) - cte40_vRec = fields.Float( - string="vRec", - ) - - ########################## - # CT-e tag: imp - ########################## + ##################################### + # CT-e tag: infCTeNorm and infCteComp + ##################################### - # cte40_imp = fields.One2many(related="l10n_br_fiscal.document.line") + cte40_choice244 = fields.Selection( + selection=[ + ("cte40_infCTeComp", "infCTeComp"), + ("cte40_infCTeNorm", "infCTeNorm"), + ], + default="cte40_infCTeNorm", + ) - ########################## - # CT-e tag: infCTeNorm - ########################## + cte40_infCarga = fields.One2many( + comodel_name="l10n_br_fiscal.document.related", + string="Informações de quantidades da Carga do CTe", + inverse_name="document_id", + store=True, + ) - # cte40_infCteNorm = fields.One2many(related="l10n_br_fiscal.document.related") + cte40_infCTeNorm = fields.One2many( + comodel_name="l10n_br_fiscal.document.related", + inverse_name="document_id", + compute="_compute_cte_doc", + store=True, + ) - # cte40_infQ = fields.One2many( - # comodel_name="l10n_br_fiscal.document.related", - # string="Informações de quantidades da Carga do CTe" - # ) TODO + cte40_infCTeComp = fields.One2many( + comodel_name="l10n_br_fiscal.document.related", + inverse_name="document_id", + compute="_compute_cte_doc", + store=True, + ) - ########################## - # CT-e tag: infCteComp - ########################## + ##################################### + # CT-e tag: infCTeNorm and infCteComp + # Compute Methods + ##################################### - cte40_chCTe = fields.Char(string="chCte") + @api.depends("document_type_id") + def _compute_cte_doc(self): + """Set schema data which are not just related fields""" + for rec in self: + if rec.document_type_id: + if rec.cte40_choice244 == "cte40_infNorm": + rec.cte40_infCTeNorm = rec + elif rec.cte40_choice244 == "cte40_infComp": + rec.cte40_infCTeComp = rec ########################## # CT-e tag: autXML @@ -363,10 +422,10 @@ def _default_cte40_autxml(self): # CT-e tag: autXML ########################## - cte40_autXML = fields.One2many(default=_default_cte40_autxml) + cte40_autXML = fields.One2many(default=_default_cte40_autxml, store=True) # View - retira = fields.Selection(selection=[("0", "Sim"), ("1", "Não")]) # TODO constantes + retira = fields.Selection(selection=[("0", "Sim"), ("1", "Não")], default="1") tpServ = fields.Selection( selection=[ @@ -374,6 +433,7 @@ def _default_cte40_autxml(self): ("7", "Transporte de Valores"), ("8", "Excesso de Bagagem"), ], + default="6", ) tpCTe = fields.Selection( @@ -382,12 +442,14 @@ def _default_cte40_autxml(self): ("1", "CTe Complementar"), ("3", "CTe Substituição"), ], + default="0", ) cte_environment = fields.Selection( selection=[("1", "Produção"), ("2", "Homologação")], string="CTe Environment", copy=False, + default="2", ) cte_transmission = fields.Selection( @@ -395,9 +457,10 @@ def _default_cte40_autxml(self): ("1", "Normal"), ("3", "Regime Especial NFF"), ("4", "EPEC pela SVC"), - ] + ], + default="1", ) tpImp = fields.Selection( - selection=[("1", "Retrato"), ("2", "Paisagem")] - ) # TODO constantes + selection=[("1", "Retrato"), ("2", "Paisagem")], default="1" + ) diff --git a/l10n_br_cte/models/document_line.py b/l10n_br_cte/models/document_line.py index 6173f0042e9b..01325e4c9549 100644 --- a/l10n_br_cte/models/document_line.py +++ b/l10n_br_cte/models/document_line.py @@ -3,7 +3,7 @@ from odoo import api, fields -from odoo.addons.l10n_br_fiscal.constants.icms import ICMS_CST +from odoo.addons.l10n_br_fiscal.constants.icms import ICMS_CST, ICMS_SN_CST from odoo.addons.spec_driven_model.models import spec_models @@ -18,6 +18,17 @@ class CTeLine(spec_models.StackedModel): _spec_module = "odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00" _spec_tab_name = "CTe" + ########################## + # CT-e tag: vPrest + ########################## + + cte40_vTPrest = fields.Monetary(string="vTPrest", related="amount_total") + + cte40_vRec = fields.Monetary( + related="price_gross", + string="vRec", + ) + ################################################## # CT-e tag: ICMS # Grupo N01. Grupo Tributação do ICMS= 00 @@ -44,27 +55,30 @@ class CTeLine(spec_models.StackedModel): store=True, ) - cte40_vTotTrib = fields.Monetary(related="estimate_tax") + cte40_vTotTrib = fields.Monetary( + related="estimate_tax", + store=True, + ) - cte40_pICMS = fields.Float(related="icms_percent", string="pICMS") + cte40_pICMS = fields.Float(related="icms_percent", string="pICMS", store=True) - cte40_vICMS = fields.Monetary(related="amount_icms_value") + cte40_vICMS = fields.Monetary(related="icms_value", store=True) # ICMS20 - ICMS90 - cte40_pRedBC = fields.Float(related="icms_reduction") + cte40_pRedBC = fields.Float(related="icms_reduction", store=True) - cte40_vBC = fields.Monetary(related="icms_base") + cte40_vBC = fields.Monetary(related="icms_base", store=True) # ICMS60 - cte40_vBCSTRet = fields.Monetary(related="icmsst_wh_base") + cte40_vBCSTRet = fields.Monetary(related="icmsst_wh_base", store=True) - cte40_vICMSSTRet = fields.Monetary(related="icmsst_wh_value") + cte40_vICMSSTRet = fields.Monetary(related="icmsst_wh_value", store=True) # ICMSSN - cte40_indSN = fields.Selection(related="indSN") + cte40_indSN = fields.Selection(related="indSN", store=True) # ICMS NF - cte40_vBCST = fields.Monetary(related="icmsst_base") + cte40_vBCST = fields.Monetary(related="icmsst_base", store=True) # ICMSOutraUF # TODO @@ -88,22 +102,25 @@ def _compute_choice11(self): icms_choice = "cte40_ICMSOutraUF" else: icms_choice = "{}{}".format("cte40_ICMS", record.icms_cst_id.code) + elif record.icms_cst_id.code in ICMS_SN_CST: + icms_choice = "cte40_ICMSSN" record.cte40_choice11 = icms_choice indSN = fields.Selection( selection=[ ("0", "Não é simples nacional"), ("1", "É simples nacional"), - ] + ], + default="0", ) ########################## # CT-e tag: ICMSUFFim ########################## - cte40_vBCUFFim = fields.Monetary(related="icms_destination_base") - cte40_pFCPUFFim = fields.Monetary(compute="_compute_cte40_ICMSUFFim") - cte40_pICMSUFFim = fields.Monetary(compute="_compute_cte40_ICMSUFFim") + cte40_vBCUFFim = fields.Monetary(related="icms_destination_base", store=True) + cte40_pFCPUFFim = fields.Monetary(compute="_compute_cte40_ICMSUFFim", store=True) + cte40_pICMSUFFim = fields.Monetary(compute="_compute_cte40_ICMSUFFim", store=True) # cte40_pICMSInter = fields.Selection( # selection=[("0", "Teste")], # compute="_compute_cte40_ICMSUFFim") @@ -116,8 +133,8 @@ def _compute_cte40_ICMSUFFim(self): # record.cte40_pICMSInter = False record.cte40_pFCPUFFim = record.icmsfcp_percent - record.cte40_pICMSUFfim = record.icms_destination_percent + record.cte40_pICMSUFFim = record.icms_destination_percent - cte40_vFCPUFfim = fields.Monetary(related="icmsfcp_value") - cte40_vICMSUFfim = fields.Monetary(related="icms_destination_value") - cte40_vICMSUFIni = fields.Monetary(related="icms_origin_value") + cte40_vFCPUFfim = fields.Monetary(related="icmsfcp_value", store=True) + cte40_vICMSUFFim = fields.Monetary(related="icms_destination_value", store=True) + cte40_vICMSUFIni = fields.Monetary(related="icms_origin_value", store=True) diff --git a/l10n_br_cte/models/document_related.py b/l10n_br_cte/models/document_related.py index 509503619888..9d6c77c08a5a 100644 --- a/l10n_br_cte/models/document_related.py +++ b/l10n_br_cte/models/document_related.py @@ -1,7 +1,7 @@ # Copyright 2023 KMEE INFORMATICA LTDA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import fields +from odoo import api, fields from odoo.addons.spec_driven_model.models import spec_models @@ -42,44 +42,88 @@ class CTeRelated(spec_models.StackedModel): ] ) - # infCarga One2many pro document line ? + # infCarga cte40_prodPred = fields.Char(string="prodPred") - cte40_vCarga = fields.Monetary(related="price_gross") # TODO compute - - cte40_infDoc = fields.Selection(related="infDoc") - - # infNF - infNFE - cte40_mod = fields.Char(related="document_type_id.code", string="cte40_mod") - - cte40_serie = fields.Char(related="document_serie") - - cte40_nDoc = fields.Char(related="document_number") + cte40_vCarga = fields.Monetary( + currency_field="currency_id", compute="_compute_vCarga", store=True + ) - cte40_dEmi = fields.Datetime(related="document_date") + currency_id = fields.Many2one( + comodel_name="res.currency", related="company_id.currency_id", readonly=True + ) - cte40_vBC = fields.Monetary(related="icms_base") + company_id = fields.Many2one( + comodel_name="res.company", + default=lambda self: self.env.company, + ) - cte40_vICMS = fields.Monetary(related="amount_icms_value") + # InfNFe + cte40_chave = fields.Char( + compute="_compute_cte_data", + inverse="_inverse_cte40_chave", + ) - cte40_vBCST = fields.Monetary(related="amount_icmsst_base") + cte40_tpDoc = fields.Char( + compute="_compute_cte_data", + inverse="_inverse_cte40_tpDoc", + ) - cte40_vST = fields.Monetary(related="amount_icmsst_value") + cte40_infDoc = fields.Selection(related="cte40_choice254") - cte40_vProd = fields.Monetary(related="amount_total") + # infCteNorm + cte40_chCTe = fields.Char(compute="_compute_chCte", string="chCte") - cte40_vNF = fields.Monetary(related="amount_financial_total") + ########################## + # CT-e tag: infCTeComp + # Compute Methods + ########################## - cte40_nCFOP = fields.Char(related="cfop_id.code") + def _compute_chCTe(self): + records = "" + for rec in self: + if rec.cte40_Id: + records += rec.document_key + self.cte40_chCTe = records - infDoc = fields.Selection( + cte40_choice254 = fields.Selection( selection=[ - ("cte40_infNF", "NF"), - ("cte40_infNFe", "NFe"), + ("cte40_infNF", "infNF"), + ("cte40_infNFe", "infNFe"), ("cte40_infOutros", "Outros"), - ] + ], + compute="_compute_cte_data", + inverse="_inverse_cte40_choice254", ) def _compute_vCarga(self): - # TODO - pass + for rec in self: + if rec.document_related_id: + rec.cte40_vCarga += rec.document_related_id.amount_price_gross + + @api.depends("document_type_id") + def _compute_cte_data(self): + """Set schema data which are not just related fields""" + for rec in self: + if rec.document_type_id: + if rec.document_type_id.code in ("55",): + rec.cte40_choice254 = "cte40_infNFe" + rec.cte40_chave = rec.document_key + elif rec.document_type_id.code in ("00", "10", "59", "65", "99"): + rec.cte40_choice254 = "cte40_infOutros" + rec.cte40_tpDoc = rec.document_type_id.code + + def _inverse_cte40_chave(self): + for rec in self: + if rec.cte40_chave: + rec.document_key = rec.cte40_chave + + def _inverse_cte40_tpDoc(self): + for rec in self: + if rec.cte40_tpDoc: + rec.document_type_id = rec.cte40_tpDoc + + def _inverse_cte40_choice254(self): + for rec in self: + if rec.cte40_choice254 == "cte40_infNFe": + rec.document_type_id = self.env.ref("l10n_br_fiscal.document_55") diff --git a/l10n_br_cte/models/res_company.py b/l10n_br_cte/models/res_company.py index ad6a441e44d1..1a71f3098d2d 100644 --- a/l10n_br_cte/models/res_company.py +++ b/l10n_br_cte/models/res_company.py @@ -16,16 +16,35 @@ class ResCompany(spec_models.SpecModel): # CT-e spec fields ########################## - cte40_CNPJ = fields.Char(related="partner_id.cte40_CNPJ") - cte40_CPF = fields.Char(related="partner_id.cte40_CPF") - cte40_IE = fields.Char(related="partner_id.cte40_IE") - cte40_xNome = fields.Char(related="partner_id.legal_name") - cte40_xFant = fields.Char(related="partner_id.name") - cte40_CRT = fields.Selection(related="tax_framework") + cte40_CNPJ = fields.Char( + related="partner_id.cte40_CNPJ", + store=True, + ) + cte40_CPF = fields.Char( + related="partner_id.cte40_CPF", + store=True, + ) + cte40_IE = fields.Char( + related="partner_id.cte40_IE", + store=True, + ) + cte40_xNome = fields.Char( + related="partner_id.legal_name", + store=True, + ) + cte40_xFant = fields.Char( + related="partner_id.name", + store=True, + ) + cte40_CRT = fields.Selection( + related="tax_framework", + store=True, + ) cte40_enderEmit = fields.Many2one( comodel_name="res.partner", related="partner_id", + store=True, ) ########################## @@ -34,18 +53,21 @@ class ResCompany(spec_models.SpecModel): rntrc_code = fields.Char( string="RNTRC", + store=True, help="Registro Nacional de Transportadores Rodoviários de Carga", ) cte_default_serie_id = fields.Many2one( comodel_name="l10n_br_fiscal.document.serie", string="CT-e Default Serie", + store=True, ) cte_dacte_layout = fields.Selection( selection=[("1", "Paisagem"), ("2", "Retrato")], string="CT-e DACTE Layout", default="1", + store=True, ) cte_transmission = fields.Selection( @@ -59,6 +81,7 @@ class ResCompany(spec_models.SpecModel): ], string="CT-e Transmission Type", default="1", + store=True, ) cte_type = fields.Selection( @@ -69,12 +92,14 @@ class ResCompany(spec_models.SpecModel): ], string="CT-e Type", default="0", + store=True, ) cte_environment = fields.Selection( selection=[("1", "Produção"), ("2", "Homologação")], string="CT-e Environment", default="2", + store=True, ) cte_version = fields.Selection( diff --git a/l10n_br_cte/models/res_partner.py b/l10n_br_cte/models/res_partner.py index 4a1b4ad262e2..8b59e0d471a3 100644 --- a/l10n_br_cte/models/res_partner.py +++ b/l10n_br_cte/models/res_partner.py @@ -10,7 +10,8 @@ _logger = logging.getLogger(__name__) try: - from erpbrasil.base.misc import punctuation_rm + from erpbrasil.base.fiscal import cnpj_cpf + from erpbrasil.base.misc import format_zipcode, punctuation_rm except ImportError: _logger.error("Biblioteca erpbrasil.base não instalada") @@ -31,7 +32,6 @@ class ResPartner(spec_models.SpecModel): cte40_CNPJ = fields.Char( compute="_compute_cte_data", - # inverse="_inverse_cte40_CNPJ", store=True, ) @@ -42,20 +42,29 @@ class ResPartner(spec_models.SpecModel): ) # enderToma/enderEmit/enderReme/enderEmit - cte40_xLgr = fields.Char(related="street_name", readonly=True) - cte40_nro = fields.Char(related="street_number", readonly=True) - cte40_xCpl = fields.Char(related="street2", readonly=True) - cte40_xBairro = fields.Char(related="district", readonly=True) - cte40_cMun = fields.Char(related="city_id.ibge_code", readonly=True) - cte40_xMun = fields.Char(related="city_id.name", readonly=True) - cte40_UF = fields.Char(related="state_id.code") + cte40_xLgr = fields.Char(related="street_name", readonly=True, store=True) + cte40_nro = fields.Char(related="street_number", readonly=True, store=True) + cte40_xCpl = fields.Char(related="street2", readonly=True, store=True) + cte40_xBairro = fields.Char(related="district", readonly=True, store=True) + cte40_cMun = fields.Char(related="city_id.ibge_code", readonly=True, store=True) + cte40_xMun = fields.Char(related="city_id.name", readonly=True, store=True) + cte40_UF = fields.Char(related="state_id.code", store=True) cte40_CEP = fields.Char( - compute="_compute_nfe_data", inverse="_inverse_nfe40_CEP", compute_sudo=True + compute="_compute_cep", + inverse="_inverse_cte40_CEP", + compute_sudo=True, + store=True, + ) + cte40_cPais = fields.Char( + related="country_id.bc_code", + store=True, + ) + cte40_xPais = fields.Char( + related="country_id.name", + store=True, ) - cte40_cPais = fields.Char(related="country_id.bc_code") - cte40_xPais = fields.Char(related="country_id.name") - nfe40_xNome = fields.Char(related="legal_name") + cte40_xNome = fields.Char(related="legal_name", store=True) @api.depends("company_type", "inscr_est", "cnpj_cpf", "country_id") def _compute_cte_data(self): @@ -97,3 +106,13 @@ def _inverse_cte40_CPF(self): rec.cte40_choice8 = "cte40_CNPJ" rec.cte40_choice19 = "cte40_CNPJ" rec.cnpj_cpf = cnpj_cpf.formata(str(rec.cte40_CPF)) + + def _inverse_cte40_CEP(self): + for rec in self: + if rec.cte40_CEP: + country_code = rec.country_id.code if rec.country_id else "BR" + rec.zip = format_zipcode(rec.cte40_CEP, country_code) + + def _compute_cep(self): + for rec in self: + rec.cte40_CEP = punctuation_rm(rec.zip) diff --git a/l10n_br_cte_spec/models/v4_0/cte_tipos_basico_v4_00.py b/l10n_br_cte_spec/models/v4_0/cte_tipos_basico_v4_00.py index a5c6b7c832a3..89273bf8a61a 100644 --- a/l10n_br_cte_spec/models/v4_0/cte_tipos_basico_v4_00.py +++ b/l10n_br_cte_spec/models/v4_0/cte_tipos_basico_v4_00.py @@ -563,12 +563,12 @@ class Tendernac(models.AbstractModel): ) -class Timp(models.AbstractModel): - "Tipo Dados do Imposto CT-e" - _description = textwrap.dedent(" %s" % (__doc__,)) - _name = "cte.40.timp" - _inherit = "spec.mixin.cte" - _binding_type = "Timp" +# class Timp(models.AbstractModel): +# "Tipo Dados do Imposto CT-e" +# _description = textwrap.dedent(" %s" % (__doc__,)) +# _name = "cte.40.timp" +# _inherit = "spec.mixin.cte" +# _binding_type = "Timp" # class TimpOs(models.AbstractModel):