-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8af3a6b
commit f2077d0
Showing
10 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import frappe | ||
|
||
|
||
@frappe.whitelist() | ||
def validate_vat_id(vat_id: str) -> bool: | ||
"""Use the EU VAT checker to validate a VAT ID.""" | ||
from .utils.eu_vat import is_valid_eu_vat_id | ||
|
||
result = frappe.cache().hget("eu_vat_validation", vat_id, shared=True) | ||
if result is not None: | ||
return result | ||
|
||
try: | ||
result = is_valid_eu_vat_id(vat_id) | ||
frappe.cache().hset("eu_vat_validation", vat_id, result, shared=True) | ||
except Exception: | ||
frappe.response["status_code"] = 501 | ||
result = None | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
frappe.ui.form.on("Customer", { | ||
setup: function (frm) { | ||
erpnext_germany.utils.setup_vat_id_validation_button(frm); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
frappe.ui.form.on("Supplier", { | ||
setup: function (frm) { | ||
erpnext_germany.utils.setup_vat_id_validation_button(frm); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
frappe.provide("erpnext_germany.utils"); | ||
|
||
erpnext_germany.utils.setup_vat_id_validation_button = function (frm) { | ||
const $wrapper = $(frm.fields_dict.tax_id.input_area); | ||
const $link_button = $( | ||
`<span class="link-btn" | ||
style="top: 2px; right: 2px;" | ||
> | ||
<a | ||
class="btn btn-xs btn-default" | ||
title="${__("Validate EU VAT ID")}" | ||
style="padding: 3px;" | ||
> | ||
${frappe.utils.icon("search", "sm")} | ||
</a> | ||
</span>` | ||
); | ||
|
||
$($wrapper).append($link_button); | ||
$link_button.toggle(true); | ||
$link_button.on("click", "a", () => { | ||
const vat_id = frm.doc.tax_id; | ||
erpnext_germany.utils.check_vat_id(vat_id) | ||
.then((is_valid) => { | ||
if (is_valid === true) { | ||
frappe.show_alert({ | ||
message: __("Tax ID is a valid EU VAT ID"), | ||
indicator: "green", | ||
}); | ||
} else if (is_valid === false) { | ||
frappe.show_alert({ | ||
message: __("Tax ID is not a valid EU VAT ID"), | ||
indicator: "red", | ||
}); | ||
} else { | ||
frappe.show_alert({ | ||
message: __("Tax ID could not be validated"), | ||
indicator: "grey", | ||
}); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
erpnext_germany.utils.check_vat_id = function (vat_id) { | ||
return frappe.xcall( | ||
"erpnext_germany.api.validate_vat_id", | ||
{ vat_id: vat_id }, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
Register Type,Registerart | ||
Register Number,Registernummer | ||
Register Court,Registergericht | ||
Validate EU VAT ID,Ust-IdNr. validieren | ||
Tax ID is a valid EU VAT ID,Steuernummer ist gültige Ust-IdNr. | ||
Tax ID is not a valid EU VAT ID,Steuernummer ist keine gültige Ust-IdNr. | ||
Tax ID could not be validated,Steuernummer konnte nicht validiert werden. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import zeep | ||
|
||
|
||
def is_valid_eu_vat_id(vat_id) -> bool: | ||
"""Use the EU VAT checker to validate a VAT ID.""" | ||
country_code = vat_id[:2].upper() | ||
vat_number = vat_id[2:].replace(" ", "") | ||
|
||
client = zeep.Client("https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl") | ||
result = client.service.checkVat(vatNumber=vat_number, countryCode=country_code) | ||
|
||
return result.valid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from unittest import TestCase | ||
from .eu_vat import is_valid_vat_id | ||
|
||
|
||
class TestUtils(TestCase): | ||
def test_validate_vat_id(self): | ||
valid_ids = [ | ||
"DE329035522", # ALYF | ||
"DE210157578", # SAP | ||
] | ||
invalid_ids = [ | ||
"ABC123", | ||
"Test Test", | ||
"DE1234567890", | ||
] | ||
|
||
for vat_id in valid_ids: | ||
self.assertTrue(is_valid_vat_id(vat_id)) | ||
|
||
for vat_id in invalid_ids: | ||
self.assertFalse(is_valid_vat_id(vat_id)) |