Skip to content

Commit

Permalink
Merge pull request #167 from VoicuStefan2001/15.0-upd-l10n_ro_partner…
Browse files Browse the repository at this point in the history
…_by_vat_button

[15.0][UPD] l10n ro partner by vat button
  • Loading branch information
dhongu authored Mar 25, 2024
2 parents 4758577 + 8a20fdc commit 040aaac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
19 changes: 18 additions & 1 deletion l10n_ro_partner_create_by_vat_button/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

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__)

Expand Down Expand Up @@ -52,6 +55,20 @@ 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ 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", [])
Expand All @@ -19,5 +23,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

0 comments on commit 040aaac

Please sign in to comment.