Skip to content

Commit

Permalink
fix: handle RetryError
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Jul 10, 2023
1 parent 91e7790 commit 6320e31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"fieldname": "status",
"fieldtype": "Select",
"label": "Status",
"options": "Planned\nRunning\nCompleted",
"options": "Planned\nRunning\nCompleted\nUnavailable",
"read_only": 1
},
{
Expand Down Expand Up @@ -168,7 +168,7 @@
}
],
"links": [],
"modified": "2023-07-10 23:59:04.133772",
"modified": "2023-07-11 00:31:49.194157",
"modified_by": "Administrator",
"module": "ERPNext Germany",
"name": "VAT ID Check",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from frappe.model.document import Document
from erpnext_germany.utils.eu_vat import check_vat_approx, parse_vat_id

from tenacity import RetryError


class VATIDCheck(Document):
def before_insert(self):
Expand Down Expand Up @@ -33,16 +35,21 @@ def run_check(doc: VATIDCheck):
requester_country_code, requester_vat_number = parse_vat_id(doc.requester_vat_id)

country_code, vat_number = parse_vat_id(doc.customer_vat_id)
result = check_vat_approx(
country_code=country_code,
vat_number=vat_number,
trader_name=doc.trader_name,
trader_street=doc.trader_street,
trader_postcode=doc.trader_postcode,
trader_city=doc.trader_city,
requester_country_code=requester_country_code,
requester_vat_number=requester_vat_number
)
try:
result = check_vat_approx(
country_code=country_code,
vat_number=vat_number,
trader_name=doc.trader_name,
trader_street=doc.trader_street,
trader_postcode=doc.trader_postcode,
trader_city=doc.trader_city,
requester_country_code=requester_country_code,
requester_vat_number=requester_vat_number
)
except RetryError:
doc.db_set("status", "Service Unavailable", notify=True)
return

doc.db_set(
{
"status": "Completed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ frappe.listview_settings["VAT ID Check"] = {
return [__("Planned"), "blue", "status,=,Planned"];
} else if (doc.status === "Running") {
return [__("Running"), "yellow", "status,=,Running"];
} else if (doc.status === "Service Unavailable") {
return [__("Service Unavailable"), "gray", "status,=,Service Unavailable"];
}
},
};

0 comments on commit 6320e31

Please sign in to comment.