Skip to content

Commit

Permalink
fix: skip invalid VAT IDs in cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Aug 31, 2023
1 parent 9e8fa10 commit 4b306a5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions erpnext_germany/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from erpnext import get_default_company
import frappe
from erpnext import get_default_company
from erpnext_germany.utils.eu_vat import parse_vat_id


def all():
Expand All @@ -8,8 +9,9 @@ def all():

def get_customers(batch_size=4):
"""Return a list of n customers who didn't have their VAT ID checked in the last 3 months."""
from pypika import functions as fn, Interval
from frappe.query_builder import DocType
from pypika import Interval
from pypika import functions as fn

customers = DocType("Customer")
vat_id_checks = DocType("VAT ID Check")
Expand Down Expand Up @@ -52,6 +54,11 @@ def check_some_customers():
requester_vat_id = frappe.get_cached_value("Company", company, "tax_id")

for customer, customer_name, primary_address, vat_id in get_customers():
try:
parse_vat_id(vat_id)
except ValueError:
continue

doc = frappe.new_doc("VAT ID Check")
doc.customer = customer
doc.trader_name = customer_name
Expand Down

0 comments on commit 4b306a5

Please sign in to comment.