microsoft / microsoft/BCApps

[Bug]: Italian FatturaPA exporter uses Business Central Country/Region Code instead of ISO alpha-2 country code

Open
#11,390 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Approved Team: Finance
Dominant language
AL
Stars
683
Forks
459
Avg merge
3d 26m
Merged PRs (30d)
633

Description

Describe the issue

In the Italian localization, the FatturaPA exporter writes Country/Region Code directly into XML fields such as IdPaese and Nazione.

For example, the exporter effectively does:

TempXMLBuffer.AddNonEmptyElement(
    'IdPaese',
    Customer."Country/Region Code");

TempXMLBuffer.AddNonEmptyLastElement(
    'Nazione',
    Customer."Country/Region Code");

However, the FatturaPA specification requires these values to use a two-character country code.

In Business Central, Country/Region Code is the primary key of the Country/Region record and is not inherently guaranteed to contain the ISO 3166-1 alpha-2 value. A tenant can legitimately configure a record such as:

Code = USA
ISO Code = US

The FatturaPA exporter currently uses USA directly rather than resolving the Country/Region record and using the corresponding ISO alpha-2 code.

This can therefore produce XML such as:

<IdPaese>USA</IdPaese>

or:

<Nazione>USA</Nazione>

even though the FatturaPA format expects the two-character country code, in this example US.

Expected behavior

When generating FatturaPA XML, Business Central should use the ISO 3166-1 alpha-2 country code associated with the relevant Country/Region record rather than assuming that the Business Central Country/Region Code primary key is itself the ISO code.

For example, given:

Country/Region Code = USA
ISO Code = US

the generated XML should contain:

<IdPaese>US</IdPaese>

and:

<Nazione>US</Nazione>

The same logic should be applied consistently wherever the FatturaPA XML requires a country code.

If a Country/Region record does not contain a valid ISO alpha-2 code, the FatturaPA validation should prevent generation of an invalid electronic invoice.

Steps to reproduce
  1. Open Countries/Regions in an Italian Business Central company.

  2. Create or use a foreign Country/Region with a Business Central key that is not the ISO alpha-2 code, for example:

    Code = USA
    ISO Code = US
    
  3. Assign that Country/Region Code to a customer.

  4. Create and post a sales invoice for that customer.

  5. Generate/export the FatturaPA electronic invoice.

  6. Inspect the generated XML.

Business Central uses the Country/Region record key directly, for example:

<IdPaese>USA</IdPaese>

and/or:

<Nazione>USA</Nazione>

instead of the ISO alpha-2 value:

US
Additional context

The issue is in the Italian FatturaPA exporter, primarily in:

src/Layers/IT/BaseApp/Local/EServices/EDocument/ExportFatturaPADocument.Codeunit.al

Several serialization paths currently use Company Information."Country/Region Code", Customer."Country/Region Code" or similar fields directly for FatturaPA IdPaese and Nazione.

The standard Country/Region table already contains a separate ISO country-code concept, so the exporter should resolve and use that value rather than relying on the primary key format.

This issue also affects foreign-recipient handling, where correct country identification is important for the FatturaPA-specific routing and fiscal-identification rules.

I will provide a fix for a bug
  • I will provide a fix for a bug

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Layers/IT/BaseApp/Local/EServices/EDocument/ExportFatturaPADocument.Codeunit.al and inspect the serialization paths that write IdPaese and Nazione from Country/Region Code fields. Check how the Country/Region record exposes its ISO country-code value, then review the foreign-recipient paths and existing FatturaPA validation. Done means all relevant country-code fields use the ISO alpha-2 value and invalid or missing values prevent generation.

Written by the indexing model from the issue text.

Assessment

Domain
backend, localization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.