company frontend finished

This commit is contained in:
2026-04-01 09:35:40 +02:00
parent 2f34b9b8be
commit 1d7f31eb96
4 changed files with 69 additions and 29 deletions
+15 -12
View File
@@ -21,7 +21,7 @@ def get_vies_client():
def normalize_vat(country_code: str, vat_number: str):
country_code = (country_code or "").strip().upper()
vat_number = (vat_number or "").strip().replace(" ", "")
vat_number = (vat_number or "").strip().replace(" ", "").replace(".", "").replace("-", "")
if vat_number.upper().startswith(country_code):
vat_number = vat_number[len(country_code):]
@@ -48,9 +48,9 @@ def parse_polish_working_address(address: str):
def parse_vies_address(address: str):
"""
Assumption for VIES address:
- address is comma-separated
- address is comma-separated or line separated
- first part = street
- last part = ZIP + CITY
- last part = ZIP + CITY or middlepart is city
Examples:
"Main Street 12, Some Region, 1000 Brussels"
@@ -59,8 +59,11 @@ def parse_vies_address(address: str):
"""
if not address:
return "", "", ""
parts = [part.strip() for part in address.split(",") if part.strip()]
if "\n" in address:
parts = [part.strip() for part in address.split("\n") if part.strip()]
if not parts:
return "", "", ""
@@ -119,7 +122,7 @@ def check_polish_wl(nip: str):
if not subject:
return {
"source": "polish_wl",
"source": "mf.gov.pl",
"found": False,
"country": "PL",
"vat_number": nip,
@@ -131,11 +134,11 @@ def check_polish_wl(nip: str):
}
name = (subject.get("name") or "").strip()
working_address = (subject.get("workingAddress") or "").strip()
working_address = (subject.get("workingAddress")or subject.get("residenceAddress") or "").strip()
street, zip_code, city = parse_polish_working_address(working_address)
return {
"source": "polish_wl",
"source": "mf.gov.pl",
"found": True,
"country": "PL",
"vat_number": nip,
@@ -149,7 +152,7 @@ def check_polish_wl(nip: str):
@app.get("/")
def index():
return render_template("index.html")
return render_template("company_data.html")
@app.get("/api/company_lookup")
@@ -166,7 +169,7 @@ def company_lookup():
vies_result = check_vies(country, vat_number)
except Exception as exc:
vies_result = {
"source": "vies",
"source": "ec.europa.eu",
"found": False,
"country": country,
"vat_number": vat_number,
@@ -175,7 +178,7 @@ def company_lookup():
"zip": "",
"city": "",
"raw_address": "",
"warning": f"VIES lookup failed: {exc}",
"warning": f"ec.europa.eu lookup failed: {exc}",
}
if vies_result.get("found"):
@@ -190,7 +193,7 @@ def company_lookup():
except Exception as exc:
return jsonify(
{
"source": "polish_wl",
"source": "mf.gov.pl",
"found": False,
"country": country,
"vat_number": vat_number,
@@ -200,7 +203,7 @@ def company_lookup():
"city": "",
"raw_address": "",
"warning": vies_result.get("warning"),
"fallback_error": f"Polish WL lookup failed: {exc}",
"fallback_error": f"mf.gov.pl lookup failed: {exc}",
}
)