Skip to content

Commit

Permalink
[FIX] l10n_br_partner: fix warnings and rename partner's 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 82c5121
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 42 deletions.
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 82c5121

Please sign in to comment.