diff --git a/l10n_br_crm/__manifest__.py b/l10n_br_crm/__manifest__.py index 29d69bfaa816..295f896e3398 100644 --- a/l10n_br_crm/__manifest__.py +++ b/l10n_br_crm/__manifest__.py @@ -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, diff --git a/l10n_br_crm/models/crm_lead.py b/l10n_br_crm/models/crm_lead.py index 29720cf7f30d..02f8c6a2458c 100644 --- a/l10n_br_crm/models/crm_lead.py +++ b/l10n_br_crm/models/crm_lead.py @@ -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() @@ -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.", @@ -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): @@ -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): @@ -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) @@ -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, @@ -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, } diff --git a/l10n_br_crm/tests/test_crm_lead.py b/l10n_br_crm/tests/test_crm_lead.py index 1606d35523b3..2424e15af972 100644 --- a/l10n_br_crm/tests/test_crm_lead.py +++ b/l10n_br_crm/tests/test_crm_lead.py @@ -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", @@ -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", @@ -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", @@ -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( diff --git a/l10n_br_crm/tests/test_crm_onchange.py b/l10n_br_crm/tests/test_crm_onchange.py index df40560c5638..7e4f77b0dc77 100644 --- a/l10n_br_crm/tests/test_crm_onchange.py +++ b/l10n_br_crm/tests/test_crm_onchange.py @@ -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": "testcontact@email.com", "phone": "999999999", } @@ -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() diff --git a/l10n_br_crm/views/crm_lead_view.xml b/l10n_br_crm/views/crm_lead_view.xml index b119bc2dc5ae..84cb01fce311 100644 --- a/l10n_br_crm/views/crm_lead_view.xml +++ b/l10n_br_crm/views/crm_lead_view.xml @@ -17,7 +17,7 @@ - + - +