Skip to content

Commit

Permalink
[16.0][MIG] l10n_es_aeat_partner_check: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoRomera committed Dec 28, 2022
1 parent 0c02bf5 commit e733ddf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion l10n_es_aeat_partner_check/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Acysos S.L., Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-spain",
"category": "Accounting",
"version": "15.0.1.1.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"depends": ["base", "base_vat", "l10n_es_aeat"],
"data": [
Expand Down
24 changes: 11 additions & 13 deletions l10n_es_aeat_partner_check/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,14 @@ def write(self, vals):
partner.aeat_check_partner()
return res

@api.model
def create(self, vals):
partner = super().create(vals)
if "company_id" in vals:
company = self.env["res.company"].browse(vals["company_id"])
elif partner.company_id:
company = partner.company_id
else:
company = self.env.user.company_id
if company.vat_check_aeat:
partner.aeat_check_partner()
return partner
@api.model_create_multi
def create(self, vals_list):
res_list = super().create(vals_list)
for partner in res_list:
company = partner.company_id if partner.company_id else self.env.company
if company.vat_check_aeat:
partner.aeat_check_partner()
return res_list

def aeat_check_re(self):
url = (
Expand All @@ -132,7 +128,9 @@ def aeat_check_re(self):
"l10n.es.aeat.certificate"
].get_certificates()
request = {"nif": vat_number, "apellido": partner.name}
res = requests.post(url, params=request, cert=(public_crt, private_key))
res = requests.post(
url, params=request, cert=(public_crt, private_key), timeout=20
)
vals = {"aeat_last_checked": fields.Datetime.now()}
if b"NIF sometido" in res.content:
vals.update({"aeat_partner_type": "sales_equalization"})
Expand Down
26 changes: 26 additions & 0 deletions l10n_es_aeat_partner_check/tests/test_res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def setUpClass(cls):
}
)

cls.partner_in = cls.env["res.partner"].create(
{
"name": "Block no. 401",
"country_id": cls.env.ref("base.in").id,
"vat": "36BBBFF5679L8ZR",
}
)

@mock.patch(
"%s.send_soap" % soap_model,
return_value=[
Expand Down Expand Up @@ -52,3 +60,21 @@ def test_02_aeat_check_re(self, redirect_mock, *args):
redirect_mock.return_value.content = b"aihjsb NIF sometido asjidnasdhsb"
self.partner.aeat_check_re()
self.assertEqual(self.partner.aeat_partner_type, "sales_equalization")

@mock.patch(
"%s.send_soap" % soap_model,
return_value=[
{
"Nombre": "Block no. 401",
"Nif": "36BBBFF5679L8ZR",
"Resultado": "IDENTIFICADO",
}
],
)
@mock.patch( # we ignore the aeat_check_re in this test to test it individually
"%s.aeat_check_re" % partner_model, return_value=True
)
def test_03_check_partner_no_spanish(self, redirect_mock, *args):
self.assertFalse(self.partner_in.aeat_partner_check_result)
self.partner_in.aeat_check_partner()
self.assertFalse(self.partner_in.aeat_partner_check_result)

0 comments on commit e733ddf

Please sign in to comment.