From b0727c6f0993a639c1ce57c34f234ffeb90b6d78 Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Wed, 17 Jul 2024 17:43:26 -0300 Subject: [PATCH] [RFC] l10n_br_cte: ultra mega power refactor :D --- l10n_br_cte/models/comment.py | 10 +- l10n_br_cte/models/document.py | 633 ++++++++++++------------- l10n_br_cte/models/document_line.py | 194 +------- l10n_br_cte/models/document_related.py | 46 +- l10n_br_cte/models/normal_cte_infos.py | 7 +- l10n_br_cte/models/res_partner.py | 1 - l10n_br_cte/views/cte_document.xml | 2 +- 7 files changed, 319 insertions(+), 574 deletions(-) diff --git a/l10n_br_cte/models/comment.py b/l10n_br_cte/models/comment.py index abfe4c67943a..19f48785e8fc 100644 --- a/l10n_br_cte/models/comment.py +++ b/l10n_br_cte/models/comment.py @@ -7,8 +7,9 @@ class CTeComment(spec_models.StackedModel): + _name = "l10n_br_fiscal.comment" - _inherit = ["l10n_br_fiscal.comment", "cte.40.tcte_obscont"] + _inherit = ["l10n_br_fiscal.comment", "cte.40.tcte_obscont", "cte.40.tcte_obsfisco"] _stacked = "cte.40.tcte_obscont" _field_prefix = "cte40_" _schema_name = "cte" @@ -16,6 +17,8 @@ class CTeComment(spec_models.StackedModel): _odoo_module = "l10n_br_cte" _spec_module = "odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00" _spec_tab_name = "CTe" + _stacking_points = {} + _stack_skip = ("cte40_ObsCont_compl_id", "cte40_ObsFisco_compl_id") _binding_module = "nfelib.cte.bindings.v4_0.cte_tipos_basico_v4_00" cte40_xCampo = fields.Char() @@ -31,5 +34,8 @@ def _export_field(self, xsd_field, class_obj, member_spec, export_value=None): self.env.context["params"]["id"] ) vals = {"user": self.env.user, "ctx": self._context, "doc": doc} - return self.compute_message(vals)[:160].strip() + message = self.compute_message(vals).strip() + if self.comment_type == "fiscal": + return message[:60] + return message[:160] return super()._export_field(xsd_field, class_obj, member_spec, export_value) diff --git a/l10n_br_cte/models/document.py b/l10n_br_cte/models/document.py index 20b7bab8e680..6a621de9aab7 100644 --- a/l10n_br_cte/models/document.py +++ b/l10n_br_cte/models/document.py @@ -68,29 +68,66 @@ def filter_processador_edoc_cte(record): class CTe(spec_models.StackedModel): _name = "l10n_br_fiscal.document" - _inherit = ["l10n_br_fiscal.document", "cte.40.tcte_infcte", "cte.40.tcte_fat"] + _inherit = [ + "l10n_br_fiscal.document", + "cte.40.tcte_infcte", + "cte.40.tcte_imp", + "cte.40.tcte_fat", + ] _stacked = "cte.40.tcte_infcte" _field_prefix = "cte40_" _schema_name = "cte" _schema_version = "4.0.0" _odoo_module = "l10n_br_cte" _spec_module = "odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00" + _spec_tab_name = "CTe" _binding_module = "nfelib.cte.bindings.v4_0.cte_tipos_basico_v4_00" + _stack_skip = ( + "cte40_fluxo", + "cte40_semData", + "cte40_noInter", + "cte40_comHora", + "cte40_noPeriodo", + ) _cte_search_keys = ["cte40_Id"] + # all m2o at this level will be stacked even if not required: + _force_stack_paths = ( + "infcte.compl", + "infcte.compl.entrega" "infcte.vprest", + "infcte.imp", + ) + INFCTE_TREE = """ > infCte > - - res.partner + > res.partner + > + > + - + ≡ + ≡ + > res.company - > res.partner + > res.company + > res.partner + > res.partner > + ≡ > - - - - + > + > > - - - - """ + > + ≡ + > + ≡ + ≡ + ≡ + - > + > + > + > """ ########################## # CT-e spec related fields @@ -335,6 +372,57 @@ def _compute_cte40_data(self): doc.cte40_xMunFim = "EXTERIOR" doc.cte40_UFFim = "EX" + ########################## + # CT-e tag: compl + ########################## + + cte40_xObs = fields.Text(compute="_compute_cte40_compl") + cte40_obsCont = fields.One2many( + "l10n_br_fiscal.comment", compute="_compute_cte40_obsCont" + ) + + cte40_obsFisco = fields.One2many( + "l10n_br_fiscal.comment", compute="_compute_cte40_obsCont" + ) + + ########################## + # CT-e tag: compl + # Methods + ########################## + + @api.depends("comment_ids") + def _compute_cte40_obsCont(self): + for doc in self: + doc.cte40_obsCont = doc.comment_ids.filtered( + lambda c: c.comment_type == "commercial" + ) + doc.cte40_obsFisco = doc.comment_ids.filtered( + lambda c: c.comment_type == "fiscal" + ) + + def _compute_cte40_compl(self): + for doc in self: + fiscal_data = ( + doc.fiscal_additional_data if doc.fiscal_additional_data else "" + ) + customer_data = ( + doc.customer_additional_data if doc.customer_additional_data else "" + ) + doc.cte40_xObs = (fiscal_data + " " + customer_data)[:256].strip() + + ########################## + # CT-e tag: entrega + ########################## + + # TODO: pensar em algo genericoom base nisso decidir quais tags + # puxar (comData,semData,noPeriodo...) + cte40_tpPer = fields.Selection( + selection=COMDATA_TPPER, string="Tipo de data/período programado", default="2" + ) + cte40_dProg = fields.Date("Data Programada", default=fields.Date.today) + + cte40_tpHor = fields.Selection(SEMHORA_TPHOR, string="Tipo de hora", default="0") + ########################## # CT-e tag: emit ########################## @@ -446,21 +534,210 @@ def _compute_receb_data(self): doc.cte40_receb = doc.partner_id ########################## - # CT-e tag: imp TODO + # CT-e tag: vPrest + # Methods ########################## - cte40_imp = fields.One2many( - comodel_name="l10n_br_fiscal.document", compute="_compute_cte40_vPrest" + cte40_vTPrest = fields.Monetary( + compute="_compute_cte40_vPrest", + string="Valor da Total Prestação Base de Cálculo", + ) + + cte40_vRec = fields.Monetary( + compute="_compute_cte40_vPrest", + string="Valor Recebido", + ) + + cte40_comp = fields.One2many( + comodel_name="l10n_br_fiscal.document.line", + inverse_name="document_id", + related="fiscal_line_ids", + ) + + def _compute_cte40_vPrest(self): + vTPrest = 0 + vRec = 0 + for doc in self: + for line in self.fiscal_line_ids: + vTPrest += line.amount_total + vRec += line.price_gross + doc.cte40_vTPrest = vTPrest + doc.cte40_vRec = vRec + + ################################################## + # CT-e tag: ICMS + # Grupo N01. Grupo Tributação do ICMS= 00 + # Grupo N02. Grupo Tributação do ICMS= 20 + # Grupo N03. Grupo Tributação do ICMS= 45 (40, 41 e 51) + # Grupo N04. Grupo Tributação do ICMS= 60 + # Grupo N05. Grupo Tributação do ICMS= 90 - ICMS outros + # Grupo N06. Grupo Tributação do ICMS= 90 - ICMS Outra UF + # Grupo N06. Grupo Tributação do ICMS= 01 - ISSN + ################################################# + + cte40_vTotTrib = fields.Monetary(related="amount_estimate_tax") + + # cte40_infAdFisco = fields.Text(related="additional_data") + + ################################################## + # CT-e tag: ICMS + # Methods + ################################################## + + cte40_choice_icms = fields.Selection( + selection=[ + ("cte40_ICMS00", "ICMS00"), + ("cte40_ICMS20", "ICMS20"), + ("cte40_ICMS45", "ICMS45"), + ("cte40_ICMS60", "ICMS60"), + ("cte40_ICMS90", "ICMS90"), + ("cte40_ICMSOutraUF", "ICMSOutraUF"), + ("cte40_ICMSSN", "ICMSSN"), + ], + string="Tipo de ICMS", + compute="_compute_choice_icms", + store=True, ) + cte40_CST = fields.Selection( + selection=[ + ("00", "00 - Tributação normal ICMS"), + ("20", "20 - Tributação com BC reduzida do ICMS"), + ("45", "45 - ICMS Isento, não Tributado ou diferido"), + ("60", "60 - ICMS cobrado por substituição tributária"), + ("90", "90 - ICMS outros"), + ("90", "90 - ICMS Outra UF"), + ("01", "01 - Simples Nacional"), + ], + string="Classificação Tributária do Serviço", + compute="_compute_choice_icms", + store=True, + ) + + # ICMSSN + cte40_indSN = fields.Float(default=1) + + # # ICMSOutraUF + # # TODO + ########################## - # CT-e tag: imp + # CT-e tag: ICMS # Compute Methods ########################## - def _compute_imp(self): - for doc in self: - doc.cte40_ICMS = doc.fiscal_line_ids + @api.depends("fiscal_line_ids") + def _compute_choice_icms(self): + for record in self: + record.cte40_choice_icms = None + record.cte40_CST = None + if not record.fiscal_line_ids: + continue + if record.fiscal_line_ids[0].icms_cst_id.code in ICMS_CST: + if record.fiscal_line_ids[0].icms_cst_id.code in ["40", "41", "50"]: + record.cte40_choice_icms = "cte40_ICMS45" + record.cte40_CST = "45" + elif ( + record.fiscal_line_ids[0].icms_cst_id.code == "90" + and record.partner_id.state_id != record.company_id.state_id + ): + record.cte40_choice_icms = "cte40_ICMSOutraUF" + else: + record.cte40_choice_icms = "{}{}".format( + "cte40_ICMS", record.fiscal_line_ids[0].icms_cst_id.code + ) + record.cte40_CST = record.fiscal_line_ids[0].icms_cst_id.code + elif record.fiscal_line_ids[0].icms_cst_id.code in ICMS_SN_CST: + record.cte40_choice_icms = "cte40_ICMSSN" + record.cte40_CST = "90" + + def _export_fields_icms(self): + # Verifica se fiscal_line_ids está vazio para evitar erros + if not self.fiscal_line_ids: + return {} + + # TODO:aprimorar. talvez criar os campos relacionados com os campos e totais + # do documento fiscal e buscar apenas os percentuais da primeira linha + first_line = self.fiscal_line_ids[0] + + icms = { + "CST": self.cte40_CST, + "vBC": 0.0, + "pRedBC": first_line.icms_reduction, + "pICMS": first_line.icms_percent, + "vICMS": 0.0, + "vICMSSubstituto": 0.0, + "indSN": int(self.cte40_indSN), + "vBCSTRet": 0.0, + "vICMSSTRet": 0.0, + "pICMSSTRet": first_line.icmsst_wh_percent, + } + + for line in self.fiscal_line_ids: + icms["vBC"] += line.icms_base + icms["vICMS"] += line.icms_value + icms["vICMSSubstituto"] += line.icms_substitute + icms["vBCSTRet"] += line.icmsst_wh_base + icms["vICMSSTRet"] += line.icmsst_wh_value + + # Formatar os valores acumulados + icms["vBC"] = str("%.02f" % icms["vBC"]) + icms["vICMS"] = str("%.02f" % icms["vICMS"]) + icms["vICMSSubstituto"] = str("%.02f" % icms["vICMSSubstituto"]) + icms["vBCSTRet"] = str("%.02f" % icms["vBCSTRet"]) + icms["vICMSSTRet"] = str("%.02f" % icms["vICMSSTRet"]) + icms["pRedBC"] = str("%.04f" % icms["pRedBC"]) + icms["pICMS"] = str("%.02f" % icms["pICMS"]) + icms["pICMSSTRet"] = str("%.02f" % icms["pICMSSTRet"]) + + return icms + + def _export_fields_cte_40_timp(self, xsd_fields, class_obj, export_dict): + # TODO Not Implemented + if "cte40_ICMSOutraUF" in xsd_fields: + xsd_fields.remove("cte40_ICMSOutraUF") + + xsd_fields = [self.cte40_choice_icms] + icms_tag = ( + self.cte40_choice_icms.replace("cte40_", "") + .replace("ICMSSN", "Icmssn") + .replace("ICMS", "Icms") + ) + binding_module = sys.modules[self._binding_module] + icms = binding_module.Timp + icms_binding = getattr(icms, icms_tag) + icms_dict = self._export_fields_icms() + sliced_icms_dict = { + key: icms_dict.get(key) + for key in icms_binding.__dataclass_fields__.keys() + if icms_dict.get(key) + } + export_dict[icms_tag.upper()] = icms_binding(**sliced_icms_dict) + + # ########################## + # # CT-e tag: ICMSUFFim + # ########################## + + # cte40_vBCUFFim = fields.Monetary(related="icms_destination_base") + # cte40_pFCPUFFim = fields.Monetary(compute="_compute_cte40_ICMSUFFim", store=True) + # cte40_pICMSUFFim = fields.Monetary(compute="_compute_cte40_ICMSUFFim", store=True) + # # TODO + # # cte40_pICMSInter = fields.Selection( + # # selection=[("0", "Teste")], + # # compute="_compute_cte40_ICMSUFFim") + + # def _compute_cte40_ICMSUFFim(self): + # for record in self: + # # if record.icms_origin_percent: + # # record.cte40_pICMSInter = str("%.02f" % record.icms_origin_percent) + # # else: + # # record.cte40_pICMSInter = False + + # record.cte40_pFCPUFFim = record.icmsfcp_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") ##################################### # CT-e tag: infCTeNorm and infCteComp @@ -484,43 +761,6 @@ def _compute_imp(self): # inverse_name="document_id", # ) - ########################## - # CT-e tag: vPrest - # Methods - ########################## - - cte40_vPrest = fields.Many2one( - comodel_name="l10n_br_fiscal.document", compute="_compute_cte40_vPrest" - ) - - cte40_vTPrest = fields.Monetary( - compute="_compute_cte40_vPrest", - string="Valor da Total Prestação Base de Cálculo", - ) - - cte40_vRec = fields.Monetary( - compute="_compute_cte40_vPrest", - string="Valor Recebido", - ) - - cte40_comp = fields.One2many( - comodel_name="l10n_br_fiscal.document.line", - inverse_name="document_id", - related="fiscal_line_ids", - ) - - def _compute_cte40_vPrest(self): - vTPrest = 0 - vRec = 0 - for doc in self: - doc.cte40_imp = doc - doc.cte40_vPrest = doc - for line in self.fiscal_line_ids: - vTPrest += line.amount_total - vRec += line.price_gross - doc.cte40_vTPrest = vTPrest - doc.cte40_vRec = vRec - ########################## # CT-e tag: infCarga ########################## @@ -693,6 +933,14 @@ def _compute_infresptec(self): ), ) + # TODO: avaliar + # def _compute_dime(self): + # for record in self: + # for package in record.product_id.packaging_ids: + # record.cte40_xDime = ( + # package.width + "X" + package.packaging_length + "X" + package.width + # ) + cte40_CL = fields.Char( string="Classe", help=( @@ -853,13 +1101,6 @@ def _compute_infresptec(self): # Compute Methods ########################## - # TODO: Fix - # - def _compute_cte40_vPrest(self): - # - vPrest = 0 - # - for record in self.fiscal_line_ids: - # - vPrest += record.cte40_vTPrest - # - self.cte40_vPrest = vPrest - def _export_fields_cte_40_tcte_infmodal(self, xsd_fields, class_obj, export_dict): self = self.with_context(module="l10n_br_cte") if self.cte40_modal == "01": @@ -1202,280 +1443,4 @@ def _need_compute_cte_tags(self): else: return False - # Complemento - cte40_compl = fields.Many2one( - comodel_name="l10n_br_fiscal.document", compute="_compute_cte40_compl" - ) - cte40_xObs = fields.Text(compute="_compute_cte40_compl") - cte40_obsCont = fields.One2many( - "l10n_br_fiscal.comment", compute="_compute_cte40_obsCont" - ) - - def _compute_cte40_obsCont(self): - for doc in self: - doc.cte40_obsCont = doc.comment_ids - - def _compute_cte40_compl(self): - for doc in self: - fiscal_data = ( - doc.fiscal_additional_data if doc.fiscal_additional_data else "" - ) - customer_data = ( - doc.customer_additional_data if doc.customer_additional_data else "" - ) - doc.cte40_xObs = (fiscal_data + " " + customer_data)[:256].strip() - doc.cte40_compl = doc.id - - # Entrega - cte40_entrega = fields.Many2one( - comodel_name="l10n_br_fiscal.document", compute="_compute_cte40_entrega" - ) - - cte40_comData = fields.Many2one( - comodel_name="l10n_br_fiscal.document", compute="_compute_cte40_entrega" - ) - cte40_tpPer = fields.Selection( - selection=COMDATA_TPPER, string="Tipo de data/período programado", default="2" - ) - cte40_dProg = fields.Date("Data Programada", default=fields.Date.today) - - cte40_semHora = fields.Many2one( - comodel_name="l10n_br_fiscal.document", compute="_compute_cte40_entrega" - ) - cte40_tpHor = fields.Selection(SEMHORA_TPHOR, string="Tipo de hora", default="0") - - def _compute_cte40_entrega(self): - for doc in self: - doc.cte40_entrega = doc - doc.cte40_comData = doc - doc.cte40_semHora = doc - - ################################################## - # CT-e tag: ICMS - # Grupo N01. Grupo Tributação do ICMS= 00 - # Grupo N02. Grupo Tributação do ICMS= 20 - # Grupo N03. Grupo Tributação do ICMS= 45 (40, 41 e 51) - # Grupo N04. Grupo Tributação do ICMS= 60 - # Grupo N05. Grupo Tributação do ICMS= 90 - ICMS outros - # Grupo N06. Grupo Tributação do ICMS= 90 - ICMS Outra UF - # Grupo N06. Grupo Tributação do ICMS= 01 - ISSN - ################################################# - - cte40_ICMS = fields.Many2one( - comodel_name="l10n_br_fiscal.document", compute="_compute_icms" - ) - cte40_vTotTrib = fields.Monetary(compute="_compute_icms") - - def _compute_icms(self): - for doc in self: - doc.cte40_ICMS = doc - if doc.fiscal_line_ids: - doc.cte40_vTotTrib = doc.fiscal_line_ids[0].estimate_tax - - cte40_choice_icms = fields.Selection( - selection=[ - ("cte40_ICMS00", "ICMS00"), - ("cte40_ICMS20", "ICMS20"), - ("cte40_ICMS45", "ICMS45"), - ("cte40_ICMS60", "ICMS60"), - ("cte40_ICMS90", "ICMS90"), - ("cte40_ICMSOutraUF", "ICMSOutraUF"), - ("cte40_ICMSSN", "ICMSSN"), - ], - string="Tipo de ICMS", - compute="_compute_choice_icms", - store=True, - ) - - cte40_CST = fields.Selection( - selection=[ - ("00", "00 - Tributação normal ICMS"), - ("20", "20 - Tributação com BC reduzida do ICMS"), - ("45", "45 - ICMS Isento, não Tributado ou diferido"), - ("60", "60 - ICMS cobrado por substituição tributária"), - ("90", "90 - ICMS outros"), - ("90", "90 - ICMS Outra UF"), - ("01", "01 - Simples Nacional"), - ], - string="Classificação Tributária do Serviço", - compute="_compute_choice_icms", - store=True, - ) - - # cte40_pICMS = fields.Float(related="icms_percent", string="pICMS") - - # cte40_vICMS = fields.Monetary(related="icms_value") - - # # ICMS20 - ICMS90 - # cte40_pRedBC = fields.Float( - # related="icms_reduction", - # ) - - # cte40_vBC = fields.Monetary(related="icms_base") - - # # ICMS60 - # cte40_vBCSTRet = fields.Monetary(related="icmsst_wh_base") - - # cte40_vICMSSTRet = fields.Monetary(related="icmsst_wh_value") - - # TODO cte40_pICMSTRet = fields.Monetary(related="") - - # ICMSSN - cte40_indSN = fields.Float(default=1) - - # # ICMS NF - # cte40_vBCST = fields.Monetary(related="icmsst_base") - - # # ICMSOutraUF - # # TODO - - ########################## - # CT-e tag: ICMS - # Compute Methods - ########################## - - @api.depends("fiscal_line_ids") - def _compute_choice_icms(self): - for record in self: - record.cte40_choice_icms = None - record.cte40_CST = None - if not record.fiscal_line_ids: - continue - if record.fiscal_line_ids[0].icms_cst_id.code in ICMS_CST: - if record.fiscal_line_ids[0].icms_cst_id.code in ["40", "41", "50"]: - record.cte40_choice_icms = "cte40_ICMS45" - record.cte40_CST = "45" - elif ( - record.fiscal_line_ids[0].icms_cst_id.code == "90" - and record.partner_id.state_id != record.company_id.state_id - ): - record.cte40_choice_icms = "cte40_ICMSOutraUF" - else: - record.cte40_choice_icms = "{}{}".format( - "cte40_ICMS", record.fiscal_line_ids[0].icms_cst_id.code - ) - record.cte40_CST = record.fiscal_line_ids[0].icms_cst_id.code - elif record.fiscal_line_ids[0].icms_cst_id.code in ICMS_SN_CST: - record.cte40_choice_icms = "cte40_ICMSSN" - record.cte40_CST = "90" - - # def _export_fields_icms(self): - # icms = { - # "CST": self.cte40_CST, - # "vBC": str("%.02f" % self.fiscal_line_ids[0].icms_base), - # "pRedBC": str("%.04f" % self.fiscal_line_ids[0].icms_reduction), - # "pICMS": str("%.02f" % self.fiscal_line_ids[0].icms_percent), - # "vICMS": str("%.02f" % self.fiscal_line_ids[0].icms_value), - # "vICMSSubstituto": str("%.02f" % self.fiscal_line_ids[0].icms_substitute), - # "indSN": int(self.cte40_indSN), - # "vBCSTRet": str("%.02f" % self.fiscal_line_ids[0].icmsst_wh_base), - # "vICMSSTRet": str("%.02f" % self.fiscal_line_ids[0].icmsst_wh_value), - # "pICMSSTRet": str("%.02f" % self.fiscal_line_ids[0].icmsst_wh_percent), - # } - # return icms - - def _export_fields_icms(self): - # Verifica se fiscal_line_ids está vazio para evitar erros - if not self.fiscal_line_ids: - return {} - - first_line = self.fiscal_line_ids[0] - - icms = { - "CST": self.cte40_CST, - "vBC": 0.0, - "pRedBC": first_line.icms_reduction, - "pICMS": first_line.icms_percent, - "vICMS": 0.0, - "vICMSSubstituto": 0.0, - "indSN": int(self.cte40_indSN), - "vBCSTRet": 0.0, - "vICMSSTRet": 0.0, - "pICMSSTRet": first_line.icmsst_wh_percent, - } - - for line in self.fiscal_line_ids: - icms["vBC"] += line.icms_base - icms["vICMS"] += line.icms_value - icms["vICMSSubstituto"] += line.icms_substitute - icms["vBCSTRet"] += line.icmsst_wh_base - icms["vICMSSTRet"] += line.icmsst_wh_value - - # Formatar os valores acumulados - icms["vBC"] = str("%.02f" % icms["vBC"]) - icms["vICMS"] = str("%.02f" % icms["vICMS"]) - icms["vICMSSubstituto"] = str("%.02f" % icms["vICMSSubstituto"]) - icms["vBCSTRet"] = str("%.02f" % icms["vBCSTRet"]) - icms["vICMSSTRet"] = str("%.02f" % icms["vICMSSTRet"]) - icms["pRedBC"] = str("%.04f" % icms["pRedBC"]) - icms["pICMS"] = str("%.02f" % icms["pICMS"]) - icms["pICMSSTRet"] = str("%.02f" % icms["pICMSSTRet"]) - - return icms - - def _export_fields_cte_40_timp(self, xsd_fields, class_obj, export_dict): - # TODO Not Implemented - if "cte40_ICMSOutraUF" in xsd_fields: - xsd_fields.remove("cte40_ICMSOutraUF") - - xsd_fields = [self.cte40_choice_icms] - icms_tag = ( - self.cte40_choice_icms.replace("cte40_", "") - .replace("ICMSSN", "Icmssn") - .replace("ICMS", "Icms") - ) - binding_module = sys.modules[self._binding_module] - icms = binding_module.Timp - icms_binding = getattr(icms, icms_tag) - icms_dict = self._export_fields_icms() - sliced_icms_dict = { - key: icms_dict.get(key) - for key in icms_binding.__dataclass_fields__.keys() - if icms_dict.get(key) - } - export_dict[icms_tag.upper()] = icms_binding(**sliced_icms_dict) - - # ########################## - # # CT-e tag: ICMSUFFim - # ########################## - - # cte40_vBCUFFim = fields.Monetary(related="icms_destination_base") - # cte40_pFCPUFFim = fields.Monetary(compute="_compute_cte40_ICMSUFFim", store=True) - # cte40_pICMSUFFim = fields.Monetary(compute="_compute_cte40_ICMSUFFim", store=True) - # # TODO - # # cte40_pICMSInter = fields.Selection( - # # selection=[("0", "Teste")], - # # compute="_compute_cte40_ICMSUFFim") - - # def _compute_cte40_ICMSUFFim(self): - # for record in self: - # # if record.icms_origin_percent: - # # record.cte40_pICMSInter = str("%.02f" % record.icms_origin_percent) - # # else: - # # record.cte40_pICMSInter = False - - # record.cte40_pFCPUFFim = record.icmsfcp_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") - - ########################## - # CT-e tag: natCarga - ########################## - - # cte40_xDime = fields.Char(compute="_compute_dime", store=True) - - # def _compute_dime(self): - # for record in self: - # for package in record.product_id.packaging_ids: - # record.cte40_xDime = ( - # package.width + "X" + package.packaging_length + "X" + package.width - # ) - - ########################## - # CT-e tag: infAdFisco - ########################## - # cte40_infAdFisco = fields.Text(related="additional_data") diff --git a/l10n_br_cte/models/document_line.py b/l10n_br_cte/models/document_line.py index 294f184f6bfe..df7ef721f09b 100644 --- a/l10n_br_cte/models/document_line.py +++ b/l10n_br_cte/models/document_line.py @@ -8,8 +8,8 @@ class CTeLine(spec_models.StackedModel): _name = "l10n_br_fiscal.document.line" - _inherit = ["l10n_br_fiscal.document.line", "cte.40.tcte_imp"] - _stacked = "cte.40.tcte_imp" + _inherit = ["l10n_br_fiscal.document.line", "cte.40.tcte_vprest_comp"] + _stacked = "cte.40.tcte_vprest_comp" _field_prefix = "cte40_" _schema_name = "cte" _schema_version = "4.0.0" @@ -17,7 +17,7 @@ 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" _stacking_points = {} - _force_stack_paths = "tcte_imp.timp" + _stack_skip = ("cte40_Comp_vPrest_id",) _binding_module = "nfelib.cte.bindings.v4_0.cte_tipos_basico_v4_00" ########################## @@ -27,191 +27,3 @@ class CTeLine(spec_models.StackedModel): cte40_xNome = fields.Text(related="name") cte40_vComp = fields.Monetary(related="amount_total") - - # ################################################## - # # CT-e tag: ICMS - # # Grupo N01. Grupo Tributação do ICMS= 00 - # # Grupo N02. Grupo Tributação do ICMS= 20 - # # Grupo N03. Grupo Tributação do ICMS= 45 (40, 41 e 51) - # # Grupo N04. Grupo Tributação do ICMS= 60 - # # Grupo N05. Grupo Tributação do ICMS= 90 - ICMS outros - # # Grupo N06. Grupo Tributação do ICMS= 90 - ICMS Outra UF - # # Grupo N06. Grupo Tributação do ICMS= 01 - ISSN - # ################################################# - - # cte40_ICMS = fields.Many2one( - # comodel_name="l10n_br_fiscal.document.line", compute="_compute_icms", store=True - # ) - - # def _compute_icms(self): - # for doc in self: - # doc.cte40_ICMS = doc - - # cte40_choice_icms = fields.Selection( - # selection=[ - # ("cte40_ICMS00", "ICMS00"), - # ("cte40_ICMS20", "ICMS20"), - # ("cte40_ICMS45", "ICMS45"), - # ("cte40_ICMS60", "ICMS60"), - # ("cte40_ICMS90", "ICMS90"), - # ("cte40_ICMSOutraUF", "ICMSOutraUF"), - # ("cte40_ICMSSN", "ICMSSN"), - # ], - # string="Tipo de ICMS", - # compute="_compute_choice_icms", - # store=True, - # ) - - # cte40_CST = fields.Selection( - # selection=[ - # ("00", "00 - Tributação normal ICMS"), - # ("20", "20 - Tributação com BC reduzida do ICMS"), - # ("45", "45 - ICMS Isento, não Tributado ou diferido"), - # ("60", "60 - ICMS cobrado por substituição tributária"), - # ("90", "90 - ICMS outros"), - # ("90", "90 - ICMS Outra UF"), - # ("01", "01 - Simples Nacional"), - # ], - # string="Classificação Tributária do Serviço", - # compute="_compute_choice_icms", - # store=True, - # ) - - # cte40_vTotTrib = fields.Monetary(related="estimate_tax") - - # cte40_pICMS = fields.Float(related="icms_percent", string="pICMS") - - # cte40_vICMS = fields.Monetary(related="icms_value") - - # # ICMS20 - ICMS90 - # cte40_pRedBC = fields.Float( - # related="icms_reduction", - # ) - - # cte40_vBC = fields.Monetary(related="icms_base") - - # # ICMS60 - # cte40_vBCSTRet = fields.Monetary(related="icmsst_wh_base") - - # cte40_vICMSSTRet = fields.Monetary(related="icmsst_wh_value") - - # # TODO cte40_pICMSTRet = fields.Monetary(related="") - - # # ICMSSN - # cte40_indSN = fields.Float(default=1) - - # # ICMS NF - # cte40_vBCST = fields.Monetary(related="icmsst_base") - - # # ICMSOutraUF - # # TODO - - # ########################## - # # CT-e tag: ICMS - # # Compute Methods - # ########################## - - # @api.depends("icms_cst_id") - # def _compute_choice_icms(self): - # for record in self: - # record.cte40_choice_icms = None - # record.cte40_CST = None - # if record.icms_cst_id.code in ICMS_CST: - # if record.icms_cst_id.code in ["40", "41", "50"]: - # record.cte40_choice_icms = "cte40_ICMS45" - # record.cte40_CST = "45" - # elif ( - # record.icms_cst_id.code == "90" - # and self.partner_id.state_id != self.company_id.state_id - # ): - # record.cte40_choice_icms = "cte40_ICMSOutraUF" - # else: - # record.cte40_choice_icms = "{}{}".format( - # "cte40_ICMS", record.icms_cst_id.code - # ) - # record.cte40_CST = record.icms_cst_id.code - # elif record.icms_cst_id.code in ICMS_SN_CST: - # record.cte40_choice_icms = "cte40_ICMSSN" - # record.cte40_CST = "90" - - # def _export_fields_icms(self): - # icms = { - # "CST": self.cte40_CST, - # "vBC": str("%.02f" % self.icms_base), - # "pRedBC": str("%.04f" % self.icms_reduction), - # "pICMS": str("%.02f" % self.icms_percent), - # "vICMS": str("%.02f" % self.icms_value), - # "vICMSSubstituto": str("%.02f" % self.icms_substitute), - # "indSN": int(self.cte40_indSN), - # "vBCSTRet": str("%.02f" % self.icmsst_wh_base), - # "vICMSSTRet": str("%.02f" % self.icmsst_wh_value), - # "pICMSSTRet": str("%.02f" % self.icmsst_wh_percent), - # } - # return icms - - # def _export_fields_cte_40_timp(self, xsd_fields, class_obj, export_dict): - # # TODO Not Implemented - # if "cte40_ICMSOutraUF" in xsd_fields: - # xsd_fields.remove("cte40_ICMSOutraUF") - - # xsd_fields = [self.cte40_choice_icms] - # icms_tag = ( - # self.cte40_choice_icms.replace("cte40_", "") - # .replace("ICMSSN", "Icmssn") - # .replace("ICMS", "Icms") - # ) - # binding_module = sys.modules[self._binding_module] - # icms = binding_module.Timp - # icms_binding = getattr(icms, icms_tag) - # icms_dict = self._export_fields_icms() - # sliced_icms_dict = { - # key: icms_dict.get(key) - # for key in icms_binding.__dataclass_fields__.keys() - # if icms_dict.get(key) - # } - # export_dict[icms_tag.upper()] = icms_binding(**sliced_icms_dict) - - # ########################## - # # CT-e tag: ICMSUFFim - # ########################## - - # cte40_vBCUFFim = fields.Monetary(related="icms_destination_base") - # cte40_pFCPUFFim = fields.Monetary(compute="_compute_cte40_ICMSUFFim", store=True) - # cte40_pICMSUFFim = fields.Monetary(compute="_compute_cte40_ICMSUFFim", store=True) - # # TODO - # # cte40_pICMSInter = fields.Selection( - # # selection=[("0", "Teste")], - # # compute="_compute_cte40_ICMSUFFim") - - # def _compute_cte40_ICMSUFFim(self): - # for record in self: - # # if record.icms_origin_percent: - # # record.cte40_pICMSInter = str("%.02f" % record.icms_origin_percent) - # # else: - # # record.cte40_pICMSInter = False - - # record.cte40_pFCPUFFim = record.icmsfcp_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") - - # ########################## - # # CT-e tag: natCarga - # ########################## - - # cte40_xDime = fields.Char(compute="_compute_dime", store=True) - - # def _compute_dime(self): - # for record in self: - # for package in record.product_id.packaging_ids: - # record.cte40_xDime = ( - # package.width + "X" + package.packaging_length + "X" + package.width - # ) - - # ########################## - # # CT-e tag: infAdFisco - # ########################## - - # cte40_infAdFisco = fields.Text(related="additional_data") diff --git a/l10n_br_cte/models/document_related.py b/l10n_br_cte/models/document_related.py index 02dec91e54c9..9c84c820905e 100644 --- a/l10n_br_cte/models/document_related.py +++ b/l10n_br_cte/models/document_related.py @@ -11,13 +11,9 @@ class CTeRelated(spec_models.StackedModel): _name = "l10n_br_fiscal.document.related" _inherit = [ "l10n_br_fiscal.document.related", - "cte.40.tcte_infctenorm", - # "cte.40.tcte_infnfe", - # "cte.40.tcte_infnf", - # "cte.40.tcte_infq", + "cte.40.tcte_infdoc", ] - _stacked = "cte.40.tcte_infctenorm" - # _stacked = "cte.40.tcte_infnfe" + _stacked = "cte.40.tcte_infdoc" _field_prefix = "cte40_" _schema_name = "cte" _schema_version = "4.0.0" @@ -26,39 +22,6 @@ class CTeRelated(spec_models.StackedModel): _spec_tab_name = "CTe" _binding_module = "nfelib.cte.bindings.v4_0.cte_tipos_basico_v4_00" - # infQ TODO computes/relateds - - cte40_tpMed = fields.Char() - - cte40_qCarga = fields.Float() - - cte40_cUnid = fields.Selection( - selection=[ - ("00", "M3"), - ("01", "KG"), - ("02", "TON"), - ("03", "UNIDADE"), - ("04", "LITROS"), - ("05", "MMBTU"), - ], - ) - - # infCarga - cte40_prodPred = fields.Char(string="prodPred") - - cte40_vCarga = fields.Monetary( - currency_field="currency_id", compute="_compute_vCarga", store=True - ) - - currency_id = fields.Many2one( - comodel_name="res.currency", related="company_id.currency_id", readonly=True - ) - - company_id = fields.Many2one( - comodel_name="res.company", - default=lambda self: self.env.company, - ) - # InfNFe cte40_chave = fields.Char( compute="_compute_cte_data", @@ -122,11 +85,6 @@ def _compute_chCTe(self): string="CHOICE", ) - def _compute_vCarga(self): - 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""" diff --git a/l10n_br_cte/models/normal_cte_infos.py b/l10n_br_cte/models/normal_cte_infos.py index 0a0e0ef85bd0..71165a69ad6b 100644 --- a/l10n_br_cte/models/normal_cte_infos.py +++ b/l10n_br_cte/models/normal_cte_infos.py @@ -56,7 +56,12 @@ class CTeNormalInfos(spec_models.StackedModel): cte40_infNFe = fields.One2many( comodel_name="l10n_br_fiscal.document.related", - related="document_id.document_related_ids", + related="document_id.cte40_infNFe", + ) + + cte40_infOutros = fields.One2many( + comodel_name="l10n_br_fiscal.document.related", + related="document_id.cte40_infOutros", ) cte40_versaoModal = fields.Char(related="document_id.cte40_versaoModal") diff --git a/l10n_br_cte/models/res_partner.py b/l10n_br_cte/models/res_partner.py index 01a76c418ac5..a4546c11aad9 100644 --- a/l10n_br_cte/models/res_partner.py +++ b/l10n_br_cte/models/res_partner.py @@ -89,7 +89,6 @@ class ResPartner(spec_models.SpecModel): compute="_compute_cep", inverse="_inverse_cte40_CEP", compute_sudo=True, - store=True, ) cte40_cPais = fields.Char( related="country_id.bc_code", diff --git a/l10n_br_cte/views/cte_document.xml b/l10n_br_cte/views/cte_document.xml index f311b0b44f17..d509c4bd2c57 100644 --- a/l10n_br_cte/views/cte_document.xml +++ b/l10n_br_cte/views/cte_document.xml @@ -103,7 +103,7 @@ - +