Skip to content

Commit

Permalink
[FIX] l10n_br_cnpj_search: avoid duplicate CNPJ
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago370 committed Oct 17, 2024
1 parent eee5058 commit f1e386b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 73 deletions.
2 changes: 1 addition & 1 deletion l10n_br_base/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
_(
Expand Down
64 changes: 6 additions & 58 deletions l10n_br_cnpj_search/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -176,7 +124,7 @@ def setUpClass(cls):
},
{
"tipoSocio": "2",
"cpf": "23982012600",
"cpf": "50745238000114",
"nome": "JOANA ALVES MUNDIM PENA",
"qualificacao": "49",
"dataInclusao": "2014-01-01",
Expand All @@ -189,7 +137,7 @@ def setUpClass(cls):
},
{
"tipoSocio": "2",
"cpf": "13946994415",
"cpf": "42887406000340",
"nome": "LUIZA BARBOSA BEZERRA",
"qualificacao": "49",
"dataInclusao": "2014-01-01",
Expand All @@ -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",
Expand All @@ -215,7 +163,7 @@ def setUpClass(cls):
},
{
"tipoSocio": "2",
"cpf": "76822320300",
"cpf": "62157094000245",
"nome": "LUIZA ALDENORA",
"qualificacao": "49",
"dataInclusao": "2014-01-01",
Expand Down
25 changes: 13 additions & 12 deletions l10n_br_cnpj_search/tests/test_serpro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
)
Expand All @@ -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")

Expand Down Expand Up @@ -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(
Expand All @@ -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()

Expand Down
50 changes: 48 additions & 2 deletions l10n_br_crm_cnpj_search/tests/test_receitaws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit f1e386b

Please sign in to comment.