From e18463a337cd80660fc8f1b09cfe98444af310a6 Mon Sep 17 00:00:00 2001 From: VoicuStefan2001 Date: Mon, 25 Mar 2024 08:55:50 +0200 Subject: [PATCH 1/2] [15.0][UPD]l10n_ro_partner_create_by_vat_button: Vies option --- .../models/res_partner.py | 20 +++++++++++++++++-- .../wizard/get_partner_data.py | 6 ++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/l10n_ro_partner_create_by_vat_button/models/res_partner.py b/l10n_ro_partner_create_by_vat_button/models/res_partner.py index 7ccf16d1..894cfebb 100644 --- a/l10n_ro_partner_create_by_vat_button/models/res_partner.py +++ b/l10n_ro_partner_create_by_vat_button/models/res_partner.py @@ -4,8 +4,9 @@ import logging - -from odoo import api, models +from zeep import Client +from odoo import _, api, models +from odoo.exceptions import UserError _logger = logging.getLogger(__name__) @@ -52,6 +53,21 @@ def button_get_partner_data(self): return True # self.onchange_vat_subjected() # fortare compltare ro + def get_partner_name_from_vies(self): + + # Create a client for the VIES SOAP service + client = Client('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl') + + # Make a request to the VIES service to check the VAT number + response = client.service.checkVat(countryCode=self.name[:2], vatNumber=self.name[2:]) + if response.valid: + self.vat = self.name + self.country_id = self.env["res.country"].search([("code", "ilike", self.name[:2].lower())])[0].id + self.name = response.name + self.street = response.address + else: + raise UserError(_("Invalid VAT")) + @api.onchange("vat", "country_id") def ro_vat_change(self): skip_ro_vat_change = self.env.context.get("skip_ro_vat_change", True) diff --git a/l10n_ro_partner_create_by_vat_button/wizard/get_partner_data.py b/l10n_ro_partner_create_by_vat_button/wizard/get_partner_data.py index b7f15804..3f60c64a 100644 --- a/l10n_ro_partner_create_by_vat_button/wizard/get_partner_data.py +++ b/l10n_ro_partner_create_by_vat_button/wizard/get_partner_data.py @@ -6,7 +6,8 @@ class GetPartnerData(models.TransientModel): _name = "get.partner.data" _description = "Get partner data from" - service = fields.Selection([("anaf", "ANAF"), ("openapi", "OpenAPI")], default="anaf", string="Service") + service = fields.Selection([("anaf", "ANAF"), ("openapi", "OpenAPI"), ("vies", "VIES for non-Romanian partners")], + default="anaf", string="Service") def do_get_data(self): active_ids = self.env.context.get("active_ids", []) @@ -19,5 +20,6 @@ def do_get_data(self): if not openapi_key: raise UserError(_("API Key is missing - please contact support service!")) partner.button_get_partner_data_openapi() - + if self.service == "vies": + partner.get_partner_name_from_vies() return From 8a20fdcaaf35f2c36ff084c179a2a01702b22f2b Mon Sep 17 00:00:00 2001 From: VoicuStefan2001 Date: Mon, 25 Mar 2024 09:00:34 +0200 Subject: [PATCH 2/2] pre-commit --- l10n_ro_partner_create_by_vat_button/models/res_partner.py | 5 +++-- .../wizard/get_partner_data.py | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/l10n_ro_partner_create_by_vat_button/models/res_partner.py b/l10n_ro_partner_create_by_vat_button/models/res_partner.py index 894cfebb..fde398fa 100644 --- a/l10n_ro_partner_create_by_vat_button/models/res_partner.py +++ b/l10n_ro_partner_create_by_vat_button/models/res_partner.py @@ -4,7 +4,9 @@ import logging + from zeep import Client + from odoo import _, api, models from odoo.exceptions import UserError @@ -54,9 +56,8 @@ def button_get_partner_data(self): # self.onchange_vat_subjected() # fortare compltare ro def get_partner_name_from_vies(self): - # Create a client for the VIES SOAP service - client = Client('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl') + client = Client("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl") # Make a request to the VIES service to check the VAT number response = client.service.checkVat(countryCode=self.name[:2], vatNumber=self.name[2:]) diff --git a/l10n_ro_partner_create_by_vat_button/wizard/get_partner_data.py b/l10n_ro_partner_create_by_vat_button/wizard/get_partner_data.py index 3f60c64a..7eba5b72 100644 --- a/l10n_ro_partner_create_by_vat_button/wizard/get_partner_data.py +++ b/l10n_ro_partner_create_by_vat_button/wizard/get_partner_data.py @@ -6,8 +6,11 @@ class GetPartnerData(models.TransientModel): _name = "get.partner.data" _description = "Get partner data from" - service = fields.Selection([("anaf", "ANAF"), ("openapi", "OpenAPI"), ("vies", "VIES for non-Romanian partners")], - default="anaf", string="Service") + service = fields.Selection( + [("anaf", "ANAF"), ("openapi", "OpenAPI"), ("vies", "VIES for non-Romanian partners")], + default="anaf", + string="Service", + ) def do_get_data(self): active_ids = self.env.context.get("active_ids", [])