Skip to content

fix(bg/vat): accept 9-digit numbers whatever their first digit - #172

Open
kallehauge wants to merge 3 commits into
koblas:mainfrom
kallehauge:fix/bg-vat-first-digit
Open

kallehauge wants to merge 3 commits into
koblas:mainfrom
kallehauge:fix/bg-vat-first-digit

Conversation

@kallehauge

Copy link
Copy Markdown

Problem

bg/vat rejects registered Bulgarian VAT numbers whose first digit is not 0, 1, 2, 3 or 9. Vivacom Bulgaria, one of the country's largest telecom operators, is an example:

stdnum.BG.vat.validate('BG831642181');
// { isValid: false, error: InvalidFormat }

BG831642181 is a valid, registered VAT number. Its check digit is correct; validation stops at the first-digit rule before the check digit is computed.

The numbers in this PR were checked in the EU VIES service before it was opened.

The official format has no first-digit rule

  • Bulgarian VAT Act (ЗДДС), art. 94(2): the VAT number of a registered company is BG followed by its unified identification code (ЕИК).
  • Ordinance No. 1 of 14 February 2007 on the Commercial Register (official PDF, Registry Agency), art. 114(3): the ЕИК "is 9 digits, is assigned at first registration and stays unchanged until deletion". It sets no rule for the first digit.

python-stdnum agrees: its validate() checks the length, that the number is all digits, and the check digit, and no version of stdnum/bg/vat.py since 2012 has had a first-digit rule. python-stdnum 2.2 accepts 831642181. The first-digit rule has been in bg/vat.ts since the module was added, with no source given.

Fix

This PR removes the rule. The check digit still applies to every number.

Input Before After
BG831642181 InvalidFormat valid
BG831642182 (wrong check digit) InvalidFormat InvalidChecksum
BG175074752 valid valid

Tested

  • src/bg/vat.spec.ts: 2 new cases; they fail before the change and pass after it.
  • Full suite: TZ=UTC npx jest --runInBand passes, 200 suites / 1637 tests.
  • npm run lint passes.

validate() refused any number not starting with 0, 1, 2, 3 or 9 with
InvalidFormat, before the check digit was looked at. python-stdnum's
bg/vat has never had that rule, and registered numbers fall outside it:
BG831137001 is valid in the EU VIES service and was rejected.
BG831642181 belongs to Vivacom Bulgaria, one of the country's largest
telecom operators, and is valid in the EU VIES service. It starts with
8, so it shows the same rejection with a well-known company.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant