Skip to content

Commit

Permalink
[FIX] l10n_br_mdfe: fix warnings and rename choice fields
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Oct 21, 2024
1 parent 04a6d59 commit f2346a1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 59 deletions.
24 changes: 13 additions & 11 deletions l10n_br_mdfe/models/modal_rodoviario.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MDFeModalRodoviarioCIOT(spec_models.SpecModel):

mdfe30_CPF = fields.Char(string="CPF do responsável")

mdfe30_choice1 = fields.Selection(
mdfe30_choice_responsible = fields.Selection(
selection=[("mdfe30_CNPJ", "CNPJ"), ("mdfe30_CPF", "CPF")],
string="CNPJ/CPF do responsável",
compute="_compute_ciot_choice",
Expand All @@ -96,7 +96,9 @@ class MDFeModalRodoviarioCIOT(spec_models.SpecModel):
@api.depends("is_company")
def _compute_ciot_choice(self):
for record in self:
record.mdfe30_choice1 = "mdfe30_CNPJ" if record.is_company else "mdfe30_CPF"
record.mdfe30_choice_responsible = (
"mdfe30_CNPJ" if record.is_company else "mdfe30_CPF"
)


class MDFeModalRodoviarioValePedagioDispositivo(spec_models.SpecModel):
Expand Down Expand Up @@ -136,7 +138,7 @@ class MDFeModalRodoviarioPagamento(spec_models.StackedModel):

mdfe30_xNome = fields.Char(related="partner_id.mdfe30_xNome")

mdfe30_choice1 = fields.Selection(
mdfe30_choice_tresponsible = fields.Selection(
selection=[
("mdfe30_CNPJ", "CNPJ"),
("mdfe30_CPF", "CPF"),
Expand Down Expand Up @@ -167,7 +169,7 @@ class MDFeModalRodoviarioPagamento(spec_models.StackedModel):
default="bank",
)

mdfe30_choice1 = fields.Selection(
mdfe30_choice_tpayment = fields.Selection(
selection=[
("mdfe30_codBanco", "Banco"),
("mdfe30_codAgencia", "Agencia"),
Expand All @@ -182,25 +184,25 @@ class MDFeModalRodoviarioPagamento(spec_models.StackedModel):
def _compute_payment_type(self):
for record in self:
if record.payment_type == "bank":
record.mdfe30_choice1 = "mdfe30_codBanco"
record.mdfe30_choice_tpayment = "mdfe30_codBanco"
elif record.payment_type == "pix":
record.mdfe30_choice1 = "mdfe30_PIX"
record.mdfe30_choice_tpayment = "mdfe30_PIX"
else:
record.mdfe30_choice1 = False
record.mdfe30_choice_tpayment = False

@api.depends("partner_id")
def _compute_mdfe_data(self):
for rec in self:
cnpj_cpf = punctuation_rm(rec.partner_id.cnpj_cpf)
if cnpj_cpf:
if rec.partner_id.country_id.code != "BR":
rec.mdfe30_choice1 = "mdfe40_idEstrangeiro"
rec.mdfe30_choice_tresponsible = "mdfe40_idEstrangeiro"
elif rec.partner_id.is_company:
rec.mdfe30_choice1 = "mdfe30_CNPJ"
rec.mdfe30_choice_tresponsible = "mdfe30_CNPJ"
else:
rec.mdfe30_choice1 = "mdfe30_CPF"
rec.mdfe30_choice_tresponsible = "mdfe30_CPF"
else:
rec.mdfe30_choice1 = False
rec.mdfe30_choice_tresponsible = False


class MDFeModalRodoviarioPagamentoFrete(spec_models.SpecModel):
Expand Down
6 changes: 3 additions & 3 deletions l10n_br_mdfe/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MDFeProductLotacaoLocal(spec_models.SpecModel):
default="CEP",
)

mdfe30_choice12 = fields.Selection(
mdfe30_choice_tlocal = fields.Selection(
selection=[("mdfe30_CEP", "CEP"), ("mdfe30_latitude", "Latitude/Longitude")],
string="Tipo de Local",
compute="_compute_choice",
Expand All @@ -63,6 +63,6 @@ class MDFeProductLotacaoLocal(spec_models.SpecModel):
def _compute_choice(self):
for record in self:
if record.local_type == "CEP":
record.mdfe30_choice12 = "mdfe30_CEP"
record.mdfe30_choice_tlocal = "mdfe30_CEP"
else:
record.mdfe30_choice12 = "mdfe30_latitude"
record.mdfe30_choice_tlocal = "mdfe30_latitude"
6 changes: 3 additions & 3 deletions l10n_br_mdfe/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ResCompany(spec_models.SpecModel):

mdfe30_fone = fields.Char(related="partner_id.mdfe30_fone")

mdfe30_choice6 = fields.Selection(
mdfe30_choice_emit = fields.Selection(
[("mdfe30_CNPJ", "CNPJ"), ("mdfe30_CPF", "CPF")],
string="MDFe emit CNPJ/CPF",
compute="_compute_mdfe_data",
Expand All @@ -85,9 +85,9 @@ class ResCompany(spec_models.SpecModel):
def _compute_mdfe_data(self):
for rec in self:
if rec.partner_id.is_company:
rec.mdfe30_choice6 = "mdfe30_CNPJ"
rec.mdfe30_choice_emit = "mdfe30_CNPJ"
else:
rec.mdfe30_choice6 = "mdfe30_CPF"
rec.mdfe30_choice_emit = "mdfe30_CPF"

def _build_attr(self, node, fields, vals, path, attr):
if attr[0] == "enderEmit" and self.env.context.get("edoc_type") == "in":
Expand Down
94 changes: 53 additions & 41 deletions l10n_br_mdfe/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,24 @@ def _prepare_import_dict(
return values

mdfe30_CNPJ = fields.Char(
compute="_compute_mdfe_data", inverse="_inverse_mdfe30_CNPJ", store=True
compute="_compute_mdfe_data",
inverse="_inverse_mdfe30_CNPJ",
store=True,
compute_sudo=True,
)

mdfe30_idEstrangeiro = fields.Char(
compute="_compute_mdfe_data",
inverse="_inverse_mdfe30_idEstrangeiro",
store=True,
compute_sudo=True,
)

mdfe30_CPF = fields.Char(
compute="_compute_mdfe_data", inverse="_inverse_mdfe30_CPF", store=True
compute="_compute_mdfe_data",
inverse="_inverse_mdfe30_CPF",
store=True,
compute_sudo=True,
)

mdfe30_xLgr = fields.Char(
Expand Down Expand Up @@ -105,14 +112,17 @@ def _prepare_import_dict(
compute_sudo=True,
)

mdfe30_choice6 = fields.Selection(
mdfe30_choice_emit = fields.Selection(
selection=[("mdfe30_CNPJ", "CNPJ"), ("mdfe30_CPF", "CPF")],
string="CNPJ/CPF do Emitente - MDFe",
compute="_compute_mdfe_data",
)

mdfe30_CEP = fields.Char(
compute="_compute_mdfe_data", inverse="_inverse_mdfe30_CEP", string="CEP - MDFe"
compute="_compute_mdfe_data",
inverse="_inverse_mdfe30_CEP",
string="CEP - MDFe",
compute_sudo=True,
)

mdfe30_cPais = fields.Char(
Expand All @@ -133,6 +143,7 @@ def _prepare_import_dict(
compute="_compute_mdfe_data",
inverse="_inverse_mdfe30_fone",
string="Telefone MDFe",
compute_sudo=True,
)

mdfe30_xNome = fields.Char(related="legal_name", string="Nome - MDFe")
Expand All @@ -142,6 +153,7 @@ def _prepare_import_dict(
mdfe30_IE = fields.Char(
compute="_compute_mdfe_data",
inverse="_inverse_mdfe30_IE",
compute_sudo=True,
)

mdfe30_email = fields.Char(related="email")
Expand All @@ -154,19 +166,19 @@ def _prepare_import_dict(

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

mdfe30_choice8 = fields.Selection(
mdfe30_choice_autxml = fields.Selection(
selection=[("mdfe30_CNPJ", "CNPJ"), ("mdfe30_CPF", "CPF")],
string="CNPJ/CPF do Parceiro Autorizado - MDFe",
compute="_compute_mdfe_data",
)

mdfe30_choice9 = fields.Selection(
mdfe30_choice_trailer_owner = fields.Selection(
selection=[("mdfe30_CNPJ", "CNPJ"), ("mdfe30_CPF", "CPF")],
string="CNPJ/CPF do Proprietário do Reboque",
compute="_compute_mdfe_data",
)

mdfe30_choice10 = fields.Selection(
mdfe30_choice_tcontractor = fields.Selection(
selection=[
("mdfe30_CNPJ", "CNPJ"),
("mdfe30_CPF", "CPF"),
Expand All @@ -176,13 +188,13 @@ def _prepare_import_dict(
compute="_compute_mdfe_data",
)

mdfe30_choice11 = fields.Selection(
mdfe30_choice_contractor = fields.Selection(
selection=[("mdfe30_CNPJ", "CNPJ"), ("mdfe30_CPF", "CPF")],
string="CNPJ/CPF do Contratante",
compute="_compute_mdfe_data",
)

mdfe30_choice12 = fields.Selection(
mdfe30_choice_insurer = fields.Selection(
selection=[("mdfe30_CNPJ", "CNPJ"), ("mdfe30_CPF", "CPF")],
string="CNPJ/CPF do Responsável pelo Seguro da Carga",
compute="_compute_mdfe_data",
Expand All @@ -195,33 +207,33 @@ def _compute_mdfe_data(self):
cnpj_cpf = punctuation_rm(rec.cnpj_cpf)
if cnpj_cpf:
if rec.country_id.code != "BR":
rec.mdfe30_choice10 = "mdfe30_idEstrangeiro"
rec.mdfe30_choice_tcontractor = "mdfe30_idEstrangeiro"
rec.mdfe30_idEstrangeiro = rec.vat
elif rec.is_company:
rec.mdfe30_choice6 = "mdfe30_CNPJ"
rec.mdfe30_choice8 = "mdfe30_CNPJ"
rec.mdfe30_choice9 = "mdfe30_CNPJ"
rec.mdfe30_choice10 = "mdfe30_CNPJ"
rec.mdfe30_choice11 = "mdfe30_CNPJ"
rec.mdfe30_choice12 = "mdfe30_CNPJ"
rec.mdfe30_choice_emit = "mdfe30_CNPJ"
rec.mdfe30_choice_autxml = "mdfe30_CNPJ"
rec.mdfe30_choice_trailer_owner = "mdfe30_CNPJ"
rec.mdfe30_choice_tcontractor = "mdfe30_CNPJ"
rec.mdfe30_choice_contractor = "mdfe30_CNPJ"
rec.mdfe30_choice_insurer = "mdfe30_CNPJ"
rec.mdfe30_CNPJ = cnpj_cpf
rec.mdfe30_CPF = None
else:
rec.mdfe30_choice6 = "mdfe30_CPF"
rec.mdfe30_choice8 = "mdfe30_CPF"
rec.mdfe30_choice9 = "mdfe30_CPF"
rec.mdfe30_choice10 = "mdfe30_CPF"
rec.mdfe30_choice11 = "mdfe30_CPF"
rec.mdfe30_choice12 = "mdfe30_CPF"
rec.mdfe30_choice_emit = "mdfe30_CPF"
rec.mdfe30_choice_autxml = "mdfe30_CPF"
rec.mdfe30_choice_trailer_owner = "mdfe30_CPF"
rec.mdfe30_choice_tcontractor = "mdfe30_CPF"
rec.mdfe30_choice_contractor = "mdfe30_CPF"
rec.mdfe30_choice_insurer = "mdfe30_CPF"
rec.mdfe30_CPF = cnpj_cpf
rec.mdfe30_CNPJ = None
else:
rec.mdfe30_choice6 = False
rec.mdfe30_choice8 = False
rec.mdfe30_choice9 = False
rec.mdfe30_choice10 = False
rec.mdfe30_choice11 = False
rec.mdfe30_choice12 = False
rec.mdfe30_choice_emit = False
rec.mdfe30_choice_autxml = False
rec.mdfe30_choice_trailer_owner = False
rec.mdfe30_choice_tcontractor = False
rec.mdfe30_choice_contractor = False
rec.mdfe30_choice_insurer = False
rec.mdfe30_CNPJ = ""
rec.mdfe30_CPF = ""

Expand All @@ -237,30 +249,30 @@ def _inverse_mdfe30_CNPJ(self):
for rec in self:
if rec.mdfe30_CNPJ:
rec.is_company = True
rec.mdfe30_choice6 = "mdfe30_CPF"
rec.mdfe30_choice8 = "mdfe30_CPF"
rec.mdfe30_choice9 = "mdfe30_CPF"
rec.mdfe30_choice10 = "mdfe30_CPF"
rec.mdfe30_choice11 = "mdfe30_CPF"
rec.mdfe30_choice12 = "mdfe30_CPF"
rec.mdfe30_choice_emit = "mdfe30_CPF"
rec.mdfe30_choice_autxml = "mdfe30_CPF"
rec.mdfe30_choice_trailer_owner = "mdfe30_CPF"
rec.mdfe30_choice_tcontractor = "mdfe30_CPF"
rec.mdfe30_choice_contractor = "mdfe30_CPF"
rec.mdfe30_choice_insurer = "mdfe30_CPF"
rec.cnpj_cpf = cnpj_cpf.formata(str(rec.mdfe30_CNPJ))

def _inverse_mdfe30_CPF(self):
for rec in self:
if rec.mdfe30_CPF:
rec.is_company = False
rec.mdfe30_choice6 = "mdfe30_CNPJ"
rec.mdfe30_choice8 = "mdfe30_CNPJ"
rec.mdfe30_choice9 = "mdfe30_CNPJ"
rec.mdfe30_choice10 = "mdfe30_CNPJ"
rec.mdfe30_choice11 = "mdfe30_CNPJ"
rec.mdfe30_choice12 = "mdfe30_CNPJ"
rec.mdfe30_choice_emit = "mdfe30_CNPJ"
rec.mdfe30_choice_autxml = "mdfe30_CNPJ"
rec.mdfe30_choice_trailer_owner = "mdfe30_CNPJ"
rec.mdfe30_choice_tcontractor = "mdfe30_CNPJ"
rec.mdfe30_choice_contractor = "mdfe30_CNPJ"
rec.mdfe30_choice_insurer = "mdfe30_CNPJ"
rec.cnpj_cpf = cnpj_cpf.formata(str(rec.mdfe30_CPF))

def _inverse_mdfe30_idEstrangeiro(self):
for rec in self:
if rec.mdfe30_idEstrangeiro:
rec.mdfe30_choice10 = "mdfe30_CPF"
rec.mdfe30_choice_tcontractor = "mdfe30_CPF"
rec.vat = rec.mdfe30_idEstrangeiro

def _inverse_mdfe30_IE(self):
Expand Down
4 changes: 3 additions & 1 deletion l10n_br_mdfe/tests/test_mdfe_res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def setUp(self):
def test_compute_fields(self):
self.partner_id.country_id = self.env.ref("base.us")

self.assertEqual(self.partner_id.mdfe30_choice10, "mdfe30_idEstrangeiro")
self.assertEqual(
self.partner_id.mdfe30_choice_tcontractor, "mdfe30_idEstrangeiro"
)
self.assertEqual(self.partner_id.mdfe30_idEstrangeiro, self.partner_id.cnpj_cpf)

def test_inverse_fields(self):
Expand Down

0 comments on commit f2346a1

Please sign in to comment.