From e733ddf609550dcbb3d951466e4bddc911511f4e Mon Sep 17 00:00:00 2001 From: FernandoRomera Date: Wed, 28 Dec 2022 14:31:11 +0100 Subject: [PATCH] [16.0][MIG] l10n_es_aeat_partner_check: Migration to 16.0 --- l10n_es_aeat_partner_check/__manifest__.py | 2 +- .../models/res_partner.py | 24 ++++++++--------- .../tests/test_res_partner.py | 26 +++++++++++++++++++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/l10n_es_aeat_partner_check/__manifest__.py b/l10n_es_aeat_partner_check/__manifest__.py index 55f7d70843c..fef0fb1b850 100644 --- a/l10n_es_aeat_partner_check/__manifest__.py +++ b/l10n_es_aeat_partner_check/__manifest__.py @@ -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": [ diff --git a/l10n_es_aeat_partner_check/models/res_partner.py b/l10n_es_aeat_partner_check/models/res_partner.py index b266337fd35..9775fffdf02 100644 --- a/l10n_es_aeat_partner_check/models/res_partner.py +++ b/l10n_es_aeat_partner_check/models/res_partner.py @@ -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 = ( @@ -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"}) diff --git a/l10n_es_aeat_partner_check/tests/test_res_partner.py b/l10n_es_aeat_partner_check/tests/test_res_partner.py index 07d4d0e0986..0d829597374 100644 --- a/l10n_es_aeat_partner_check/tests/test_res_partner.py +++ b/l10n_es_aeat_partner_check/tests/test_res_partner.py @@ -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=[ @@ -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)