Hankintailmoitukset / hilma-api

11 stars 0 forks source link

BT-501 CompanyId as VAT number fails to validate #210

Closed hasanMercell closed 6 months ago

hasanMercell commented 6 months ago

Describe the bug Under the custom validation rules

  "ublExtensions.ublExtension.extensionContent.eformsExtension.organizations.organization.company.partyLegalEntity.companyID": {
    "xpathAbsolute" : "/*/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/efext:EformsExtension/efac:Organizations/efac:Organization/efac:Company/cac:PartyLegalEntity/cbc:CompanyID",
    "btId": "501",
    "nationalidentifierorvatnumber": true
  },

nationalidentifierorvatnumber is set to true even though vat numbers aren't passing validation.

To Reproduce Validate any XML through the Validates the notice with national validation rules and TED schematron rules API and pass a VAT number under CompanyID such as

  <cac:PartyLegalEntity>
      <cbc:CompanyID schemeID="002">FI07654321</cbc:CompanyID>
  </cac:PartyLegalEntity>

I've tried using FI0765432, FI0765432, FI-FI0765432 and none of them validates.

Expected behavior VAT number should be validated

API response

 "ublExtensions.ublExtension.extensionContent.eformsExtension.organizations.organization.company.partyLegalEntity.companyID": [
            "Company Id is not a valid National Identifier or Private Road Identifier"
        ],

Additional context Under FieldValidator.cs in validation folder I don't see any function that validates VAT number, could it perhaps be missing?

arinurkkala commented 6 months ago

Hi,

The examples you provided are missing 1 digit. Here is the official documentation for it: https://www.ytj.fi/en/index/vatnumber.html

hasanMercell commented 6 months ago

I've tried many different formats also as the example provided in the link

<cac:PartyLegalEntity>
       <cbc:CompanyID schemeID="002">FI12345678</cbc:CompanyID>
</cac:PartyLegalEntity>

but yet I'm still getting the error

"ublExtensions.ublExtension.extensionContent.eformsExtension.organizations.organization.company.partyLegalEntity.companyID": [
            "Company Id is not a valid National Identifier or Private Road Identifier"
],
arinurkkala commented 6 months ago

Length isn't the only thing that is being checked. Use a valid ID. You can use for eg. https://telepartikkeli.azurewebsites.net/tunnusgeneraattori to generate ID's in y-tunnus format. After that you need to add 'FI' to the start and remove the dash.

hasanMercell commented 6 months ago

I have done that, please take a look at the attachments explaining it

Here's the generated Y-tunnus image

And here is the Y-tunnus added with FI and dashes removed

 <cac:PartyLegalEntity>
                  <cbc:CompanyID schemeID="002">FI56822759</cbc:CompanyID>
</cac:PartyLegalEntity>

And this is the result of the API response

"ublExtensions.ublExtension.extensionContent.eformsExtension.organizations.organization.company.partyLegalEntity.companyID": [
            "Company Id is not a valid National Identifier or Private Road Identifier"
],
arinurkkala commented 6 months ago

Ok, now it seems to be an issue in Hilma. Fixing..

arinurkkala commented 6 months ago

Fix is now deployed in DEV environment and coming soon (~20 min) to TEST environment. I have updated the documentation: https://github.com/Hankintailmoitukset/hilma-api/blob/master/validation/ENoticeValidator.cs https://github.com/Hankintailmoitukset/hilma-api/blob/master/validation/FieldValidator.cs

hasanMercell commented 6 months ago

Just did a test and it seems to work now, thanks a lot for the quick fix! @arinurkkala

hasanMercell commented 6 months ago

Any idea when this fix will be deployed to PROD environment?

arinurkkala commented 6 months ago

In about 30 minutes