From f1e386bd2f4f9468b94d9f7951ad37bb24d76455 Mon Sep 17 00:00:00 2001 From: Tiago Amaral Date: Mon, 14 Oct 2024 13:47:03 -0300 Subject: [PATCH] [FIX] l10n_br_cnpj_search: avoid duplicate CNPJ --- l10n_br_base/models/res_partner.py | 2 +- l10n_br_cnpj_search/tests/common.py | 64 ++----------------- l10n_br_cnpj_search/tests/test_serpro.py | 25 ++++---- .../tests/test_receitaws.py | 50 ++++++++++++++- 4 files changed, 68 insertions(+), 73 deletions(-) diff --git a/l10n_br_base/models/res_partner.py b/l10n_br_base/models/res_partner.py index a1c82783f951..5a045cf4a1cf 100644 --- a/l10n_br_base/models/res_partner.py +++ b/l10n_br_base/models/res_partner.py @@ -94,7 +94,7 @@ def _check_cnpj_inscr_est(self): for partner in record.env["res.partner"].search(domain): if ( partner.inscr_est == record.inscr_est - and not record.inscr_est + and record.inscr_est ): raise ValidationError( _( diff --git a/l10n_br_cnpj_search/tests/common.py b/l10n_br_cnpj_search/tests/common.py index ce531fba22a9..3e33454c93c0 100644 --- a/l10n_br_cnpj_search/tests/common.py +++ b/l10n_br_cnpj_search/tests/common.py @@ -67,7 +67,7 @@ def setUpClass(cls): "socios": [ { "tipoSocio": "2", - "cpf": "07119488449", + "cpf": "38729752000160", "nome": "LUIZA ARAUJO DE OLIVEIRA", "qualificacao": "49", "dataInclusao": "2014-01-01", @@ -78,58 +78,6 @@ def setUpClass(cls): "qualificacao": "00", }, }, - { - "tipoSocio": "2", - "cpf": "23982012600", - "nome": "JOANA ALVES MUNDIM PENA", - "qualificacao": "49", - "dataInclusao": "2014-01-01", - "pais": {"codigo": "105", "descricao": "BRASIL"}, - "representanteLegal": { - "cpf": "00000000000", - "nome": "", - "qualificacao": "00", - }, - }, - { - "tipoSocio": "2", - "cpf": "13946994415", - "nome": "LUIZA BARBOSA BEZERRA", - "qualificacao": "49", - "dataInclusao": "2014-01-01", - "pais": {"codigo": "105", "descricao": "BRASIL"}, - "representanteLegal": { - "cpf": "00000000000", - "nome": "", - "qualificacao": "00", - }, - }, - { - "tipoSocio": "2", - "cpf": "00031298702", - "nome": "MARCELO ANTONIO BARROS DE CICCO", - "qualificacao": "49", - "dataInclusao": "2014-01-01", - "pais": {"codigo": "105", "descricao": "BRASIL"}, - "representanteLegal": { - "cpf": "00000000000", - "nome": "", - "qualificacao": "00", - }, - }, - { - "tipoSocio": "2", - "cpf": "76822320300", - "nome": "LUIZA ALDENORA", - "qualificacao": "49", - "dataInclusao": "2014-01-01", - "pais": {"codigo": "105", "descricao": "BRASIL"}, - "representanteLegal": { - "cpf": "00000000000", - "nome": "", - "qualificacao": "00", - }, - }, ], "endereco": { "tipoLogradouro": "SETOR", @@ -163,7 +111,7 @@ def setUpClass(cls): "socios": [ { "tipoSocio": "2", - "cpf": "07119488449", + "cpf": "42806249000562", "nome": "LUIZA ARAUJO DE OLIVEIRA", "qualificacao": "49", "dataInclusao": "2014-01-01", @@ -176,7 +124,7 @@ def setUpClass(cls): }, { "tipoSocio": "2", - "cpf": "23982012600", + "cpf": "50745238000114", "nome": "JOANA ALVES MUNDIM PENA", "qualificacao": "49", "dataInclusao": "2014-01-01", @@ -189,7 +137,7 @@ def setUpClass(cls): }, { "tipoSocio": "2", - "cpf": "13946994415", + "cpf": "42887406000340", "nome": "LUIZA BARBOSA BEZERRA", "qualificacao": "49", "dataInclusao": "2014-01-01", @@ -202,7 +150,7 @@ def setUpClass(cls): }, { "tipoSocio": "2", - "cpf": "00031298702", + "cpf": "39367267000157", "nome": "MARCELO ANTONIO BARROS DE CICCO", "qualificacao": "49", "dataInclusao": "2014-01-01", @@ -215,7 +163,7 @@ def setUpClass(cls): }, { "tipoSocio": "2", - "cpf": "76822320300", + "cpf": "62157094000245", "nome": "LUIZA ALDENORA", "qualificacao": "49", "dataInclusao": "2014-01-01", diff --git a/l10n_br_cnpj_search/tests/test_serpro.py b/l10n_br_cnpj_search/tests/test_serpro.py index 853d4f8fef2c..74caf64866af 100644 --- a/l10n_br_cnpj_search/tests/test_serpro.py +++ b/l10n_br_cnpj_search/tests/test_serpro.py @@ -62,6 +62,8 @@ def test_serpro_basica(self): def test_serpro_not_found(self): # In the Trial version there are only a few registered CNPJ records + self.model.search([("cnpj_cpf", "=", "44.356.113/0001-08")]).unlink() + self.set_param("serpro_schema", "basica") invalid = self.model.create( {"name": "invalid", "cnpj_cpf": "44.356.113/0001-08"} ) @@ -77,7 +79,6 @@ def assert_socios(self, partner, expected_cnpjs): [("id", "in", partner.child_ids.ids)], fields=["name", "cnpj_cpf", "company_type"], ) - for s in socios: s.pop("id") @@ -112,13 +113,21 @@ def assert_socios(self, partner, expected_cnpjs): self.assertEqual(socios, expected_socios) def test_serpro_empresa(self): + self.env["ir.config_parameter"].sudo().set_param( + "l10n_br_base.allow_cnpj_multi_ie", "True" + ) + expected_cnpjs = { + "Joana": "50745238000114", + "Aldenora": "62157094000245", + "Araujo": "42806249000562", + "Barbosa": "42887406000340", + "Marcelo": "39367267000157", + } with mock.patch( "odoo.addons.l10n_br_cnpj_search.models.cnpj_webservice.CNPJWebservice.validate", return_value=self.mocked_response_serpro_2, ): - self.model.search([("cnpj_cpf", "=", "34.238.864/0002-49")]).write( - {"active": False} - ) + self.model.search([("cnpj_cpf", "=", "34.238.864/0002-49")]).unlink() self.set_param("serpro_schema", "empresa") dummy_empresa = self.model.create( @@ -135,14 +144,6 @@ def test_serpro_empresa(self): ) wizard.action_update_partner() - expected_cnpjs = { - "Joana": "23982012600", - "Aldenora": "76822320300", - "Araujo": "07119488449", - "Barbosa": "13946994415", - "Marcelo": "00031298702", - } - self.assert_socios(dummy_empresa, expected_cnpjs) dummy_empresa.unlink() diff --git a/l10n_br_crm_cnpj_search/tests/test_receitaws.py b/l10n_br_crm_cnpj_search/tests/test_receitaws.py index 52147489d62e..ad43dd6b1b00 100644 --- a/l10n_br_crm_cnpj_search/tests/test_receitaws.py +++ b/l10n_br_crm_cnpj_search/tests/test_receitaws.py @@ -5,5 +5,51 @@ class TestCRMReceitaws(TransactionCase): - def test_crm_receita_ws_success(self): - pass + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.crm_lead_model = cls.env["crm.lead"] + cls.res_partner_model = cls.env["res.partner"] + cls.crm_lead_1 = cls.crm_lead_model.create({"name": "Jamanta"}) + + def test_convert_to_oportunity(self): + # self.crm_lead_1._onchange_cnpj_cpf() + self.crm_lead_1.write({"cnpj_cpf": "31.954.065/0001-08"}) + action_wizard = self.crm_lead_1.action_open_cnpj_search_wizard() + wizard_context = action_wizard.get("context") + wizard = ( + self.env["partner.search.wizard"].with_context(**wizard_context).create({}) + ) + wizard.action_update_partner() + self.assertEqual( + self.crm_lead_1.legal_name, + "Atacadao Jamanta Ltda", + ) + self.assertEqual(self.crm_lead_1.name, "Atacadao Jamanta") + self.assertEqual(self.crm_lead_1.street, "Rodovia Br 393") + self.assertEqual(self.crm_lead_1.street2, "Km 72") + self.assertEqual(self.crm_lead_1.street_number, "774") + self.assertEqual(self.crm_lead_1.zip, "25.887-000") + self.assertEqual(self.crm_lead_1.district, "Jamapara") + self.assertEqual(self.crm_lead_1.phone, "(32) 8412-7486") + self.assertEqual(self.crm_lead_1.mobile, False) + self.assertEqual(self.crm_lead_1.state_id.code, "RJ") + self.assertEqual(self.crm_lead_1.equity_capital, 95400.0) + self.assertEqual(self.crm_lead_1.cnae_main_id.code, "4635-4/02") + + cnaes = [ + "4635-4/99", + "4646-0/01", + "4691-5/00", + "4723-7/00", + "4729-6/99", + "4772-5/00", + "4930-2/02", + ] + cnaes = sorted(cnaes) + cnae_secondary_codes = [ + cnae.code for cnae in self.crm_lead_1.cnae_secondary_ids + ] + cnae_secondary_codes = sorted(cnae_secondary_codes) + for i in range(0, len(cnae_secondary_codes)): + self.assertEqual(cnaes[i], cnae_secondary_codes[i])