跳到正文
DEV Community· Michal Novotný·· 4 天前AI 評分46

捷克發票帳戶核查需要區分三種結果

A Czech invoice check needs three answers

AI 導讀

捷克發票帳戶核查應明確區分 MATCH、NO_MATCH 和 UNKNOWN;查詢逾時或資料不足時,不應以空清單表示不匹配。流程分別查詢 ARES 和增值税登記冊,並保留公司名稱,讓帳戶可轉交人工審核。n8n 測試中,為清晰發票分支的 webhook 共用最終節點回傳結果,修正了 HTTP 500 問題。

正文

A supplier account either matches a published account, differs from every published account, or cannot be checked with the data available. A surprisingly easy way to lose the third outcome is to return an empty list when a registry request times out. Every downstream payment check then treats the outage as a mismatch.

Start with the supplier identifier

An ISDOC electronic invoice carries the supplier identifier and the payment details on the document. To look up a Czech supplier's registered name, you can call ARES directly. Keep the IČO as a string so the leading zeros survive. This example uses the public identifier of the Moravian Library in Brno.

import json
from urllib.request import urlopen

ico = "00094943"
url = f"https://ares.gov.cz/ekonomicke-subjekty-v-be/rest/ekonomicke-subjekty/{ico}"
with urlopen(url, timeout=10) as response:
    company = json.load(response)
print(company["ico"], company["obchodniJmeno"])

For published bank accounts and VAT reliability, the workflow queries the Czech Financial Administration's VAT register. The company name from ARES remains useful even when the VAT register is unavailable. Keeping the two results separate lets the caller display the name and send the account for manual review.

Make uncertainty an explicit input

The comparison below assumes both sides have already been normalized. A Czech domestic account string includes a bank code, an optional prefix and an account number. For a Czech IBAN and a domestic account to compare equal, those components must be represented consistently.

def compare_account(invoice_account, published_accounts):
    if published_accounts is None:
        return "UNKNOWN"
    if invoice_account in published_accounts:
        return "MATCH"
    return "NO_MATCH"

assert compare_account("account-A", ["account-A"]) == "MATCH"
assert compare_account("account-A", []) == "NO_MATCH"
assert compare_account("account-A", None) == "UNKNOWN"

Only pass an empty list after a successful, complete lookup. Pass None if the upstream response omits the field you need. In a production workflow, keep the source, lookup time and status alongside the result. Even a successful match only establishes that the account appeared in the source at lookup time.

Test the webhook response as well as the business rule

In a running n8n instance, we tried a CZK 100 invoice, a EUR 50 invoice using the Czech National Bank rate for 16 November 2026, and an unavailable VAT register. The CZK amount stayed at 100. The foreign invoice converted to CZK 1,221.50. For the outage test we replaced the upstream response with a controlled fixture. The workflow returned VAT_STATUS_UNKNOWN and UNKNOWN_ADIS.

The clear invoice initially triggered an unexpected HTTP 500. A terminal IF node returned no item on the clear branch, leaving the webhook with nothing to send. Returning one result from a shared final node fixed the response. The caller can now route all three outcomes explicitly.

I maintain EuroKYB. The standalone Python examples above run without a EuroKYB account. The project also exposes these lookups through an open-source MCP bridge. This article was prepared with AI assistance and draws on the live workflow tests described above.

來源:DEV Community · dev.to