Skip to content

Commit

Permalink
[REF] l10n_br_crm: CNPJ->vat
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Sep 30, 2024
1 parent 78b6401 commit 5def05c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion l10n_br_crm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "Akretion, Odoo Community Association (OCA)",
"maintainers": ["renatonlima", "rvalyi", "mbcosta"],
"website": "https://github.com/OCA/l10n-brazil",
"version": "16.0.1.1.1",
"version": "16.0.2.0.0",
"depends": ["l10n_br_base", "crm"],
"data": ["views/crm_lead_view.xml", "views/crm_quick_create_opportunity_form.xml"],
"installable": True,
Expand Down
34 changes: 16 additions & 18 deletions l10n_br_crm/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class Lead(models.Model):
_name = "crm.lead"
_inherit = [_name, "l10n_br_base.party.mixin"]

cnpj = fields.Char(string="CNPJ")
vat = fields.Char(
string="Tax ID",
index=True,
help="The Tax Identification Number. Values here will be validated based on the country format. You can use '/' to indicate that the partner is not subject to tax.",
)

street_name = fields.Char()

Expand All @@ -25,8 +29,6 @@ class Lead(models.Model):
string="Name and Surname", help="Name used in fiscal documents"
)

cpf = fields.Char(string="CPF")

show_l10n_br = fields.Boolean(
compute="_compute_show_l10n_br",
help="Indicates if Brazilian localization fields should be displayed.",
Expand Down Expand Up @@ -69,15 +71,15 @@ def _onchange_contact_name(self):
if not self.name_surname:
self.name_surname = self.contact_name

@api.constrains("cnpj")
@api.constrains("vat")
def _check_cnpj(self):
for record in self:
check_cnpj_cpf(record.env, record.cnpj, record.country_id)
check_cnpj_cpf(record.env, record.vat, record.country_id)

@api.constrains("cpf")
@api.constrains("l10n_br_cpf_code")
def _check_cpf(self):
for record in self:
check_cnpj_cpf(record.env, record.cpf, record.country_id)
check_cnpj_cpf(record.env, record.l10n_br_cpf_code, record.country_id)

@api.constrains("inscr_est")
def _check_ie(self):
Expand All @@ -89,13 +91,9 @@ def _check_ie(self):
for record in self:
check_ie(record.env, record.inscr_est, record.state_id, record.country_id)

@api.onchange("cnpj", "country_id")
def _onchange_cnpj(self):
self.cnpj = cnpj_cpf.formata(self.cnpj)

@api.onchange("cpf", "country_id")
@api.onchange("l10n_br_cpf_code", "country_id")
def _onchange_mask_cpf(self):
self.cpf = cnpj_cpf.formata(self.cpf)
self.l10n_br_cpf_code = cnpj_cpf.formata(self.l10n_br_cpf_code)

@api.onchange("city_id")
def _onchange_city_id(self):
Expand Down Expand Up @@ -130,19 +128,19 @@ def _onchange_partner_id(self):
result["country_id"] = self.partner_id.country_id.id
if self.partner_id.is_company:
result["legal_name"] = self.partner_id.legal_name
result["cnpj"] = self.partner_id.cnpj_cpf
result["vat"] = self.partner_id.vat
result["inscr_est"] = self.partner_id.inscr_est
result["inscr_mun"] = self.partner_id.inscr_mun
result["suframa"] = self.partner_id.suframa
else:
result["partner_name"] = self.partner_id.parent_id.name or False
result["legal_name"] = self.partner_id.parent_id.legal_name or False
result["cnpj"] = self.partner_id.parent_id.cnpj_cpf or False
result["vat"] = self.partner_id.parent_id.vat or False
result["inscr_est"] = self.partner_id.parent_id.inscr_est or False
result["inscr_mun"] = self.partner_id.parent_id.inscr_mun or False
result["suframa"] = self.partner_id.parent_id.suframa or False
result["website"] = self.partner_id.parent_id.website or False
result["cpf"] = self.partner_id.cnpj_cpf
result["l10n_br_cpf_code"] = self.partner_id.l10n_br_cpf_code
result["rg"] = self.partner_id.rg
result["name_surname"] = self.partner_id.legal_name
self.update(result)
Expand All @@ -168,7 +166,7 @@ def _prepare_customer_values(self, name, is_company, parent_id=False):
if is_company:
values.update(
{
"cnpj_cpf": self.cnpj,
"vat": self.vat,
"inscr_est": self.inscr_est,
"inscr_mun": self.inscr_mun,
"suframa": self.suframa,
Expand All @@ -177,7 +175,7 @@ def _prepare_customer_values(self, name, is_company, parent_id=False):
else:
values.update(
{
"cnpj_cpf": self.cpf,
"l10n_br_cpf_code": self.l10n_br_cpf_code,
"inscr_est": self.rg,
"rg": self.rg,
}
Expand Down
10 changes: 5 additions & 5 deletions l10n_br_crm/tests/test_crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUp(self):
{
"name": "Test Company Lead",
"legal_name": "Teste Empresa",
"cnpj": "56.647.352/0001-98",
"vat": "56.647.352/0001-98",
"stage_id": self.env.ref("crm.stage_lead1").id,
"partner_name": "Test Partner",
"inscr_est": "079.798.013.363",
Expand All @@ -28,7 +28,7 @@ def setUp(self):
self.crm_lead_contact = self.env["crm.lead"].create(
{
"name": "Test Contact",
"cpf": "70531160505",
"l10n_br_cpf_code": "70531160505",
"rg": "99.888.777-1",
"stage_id": self.env.ref("crm.stage_lead1").id,
"contact_name": "Test Contact",
Expand All @@ -40,7 +40,7 @@ def setUp(self):
{
"name": "Test Company Lead IE",
"legal_name": "Teste Empresa 1",
"cnpj": "57.240.310/0001-09",
"vat": "57.240.310/0001-09",
"stage_id": self.env.ref("crm.stage_lead1").id,
"partner_name": "Test Partner 1",
"inscr_est": "041.092.540.590",
Expand Down Expand Up @@ -218,10 +218,10 @@ def test_change_lead_partner(self):
)

self.assertEqual(
self.crm_lead_company_1.cnpj,
self.crm_lead_company_1.vat,
"22.898.817/0001-61",
"In the change of the partner \
the field cpf was not automatically filled.",
the field CNPJ was not automatically filled.",
)

self.assertEqual(
Expand Down
6 changes: 3 additions & 3 deletions l10n_br_crm/tests/test_crm_onchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def setUp(self):
"legal_name": "Test Company LTDA",
"contact_name": "Test Name Contact",
"name_surname": "Test NameSurname Contact",
"cnpj": "56.647.352/0001-98",
"vat": "56.647.352/0001-98",
"city_id": self.env.ref("l10n_br_base.city_3205002").id,
"country_id": self.env.ref("base.br").id,
"zip": "29161-695",
"cpf": "70531160505",
"l10n_br_cpf_code": "70531160505",
"email_from": "[email protected]",
"phone": "999999999",
}
Expand All @@ -30,7 +30,7 @@ def test_onchange(self):
"""
Call all the onchange methods in l10n_br_crm
"""
self.crm_lead_01._onchange_cnpj()
self.crm_lead_01._onchange_vat()
self.crm_lead_01._onchange_mask_cpf()
self.crm_lead_01._onchange_city_id()
self.crm_lead_01._onchange_zip()
Expand Down
8 changes: 4 additions & 4 deletions l10n_br_crm/views/crm_lead_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<xpath expr="//group[@name='lead_info']/div" position="after">
<field name="name_surname" />
<field
name="cpf"
name="l10n_br_cpf_code"
attrs="{'invisible': [('show_l10n_br', '=', False)]}"
/>
<field
Expand All @@ -35,7 +35,7 @@
attrs="{'invisible': [('show_l10n_br', '=', False)]}"
/>
<field
name="cnpj"
name="vat"
attrs="{'invisible': [('show_l10n_br', '=', False)]}"
/>
<field
Expand Down Expand Up @@ -67,7 +67,7 @@
attrs="{'invisible': [('show_l10n_br', '=', False)]}"
/>
<field
name="cnpj"
name="vat"
attrs="{'invisible': [('show_l10n_br', '=', False)]}"
/>
<field
Expand All @@ -94,7 +94,7 @@
>
<field name="name_surname" />
<field
name="cpf"
name="l10n_br_cpf_code"
attrs="{'invisible': [('show_l10n_br', '=', False)]}"
/>
<field
Expand Down
4 changes: 2 additions & 2 deletions l10n_br_crm/views/crm_quick_create_opportunity_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<field name="arch" type="xml">
<xpath expr="//group" position="inside">
<field name="legal_name" invisible="1" />
<field name="cnpj" invisible="1" />
<field name="vat" invisible="1" />
<field name="inscr_est" invisible="1" />
<field name="inscr_mun" invisible="1" />
<field name="suframa" invisible="1" />
<field name="name_surname" invisible="1" />
<field name="cpf" invisible="1" />
<field name="l10n_br_cpf_code" invisible="1" />
<field name="rg" invisible="1" />
</xpath>
</field>
Expand Down

0 comments on commit 5def05c

Please sign in to comment.