Skip to content

Fix #11390: Use ISO country codes in FatturaPA export - #11662

Open
Marco Antonio Mauro (marcus905) wants to merge 6 commits into
microsoft:mainfrom
marcus905:fix-11390-fatturapa-iso-country-code
Open

Marco Antonio Mauro (marcus905) wants to merge 6 commits into
microsoft:mainfrom
marcus905:fix-11390-fatturapa-iso-country-code

Conversation

@marcus905

@marcus905 Marco Antonio Mauro (marcus905) commented Sep 21, 2026

Copy link
Copy Markdown

What & why

The Italian FatturaPA exporter currently writes Business Central Country/Region Code values directly into FatturaPA elements such as IdPaese and Nazione.

However, Country/Region Code is the primary key of the Business Central Country/Region record and is not required to be the ISO 3166-1 alpha-2 code.

For example, a tenant can validly configure:

Country/Region Code = USA
ISO Code = US

The current exporter can therefore emit:

<IdPaese>USA</IdPaese>

instead of the FatturaPA-compatible ISO code:

<IdPaese>US</IdPaese>

This change resolves FatturaPA country values through the related Country/Region record and uses its ISO Code instead of assuming that the Business Central primary key is already the required ISO value.

The change:

  • uses Country/Region."ISO Code" when generating FatturaPA country-code elements;
  • applies the same resolution consistently to company, customer, tax representative, and transmission intermediary country values used by the FatturaPA exporter;
  • validates that referenced Country/Region records contain a two-character ISO code before export;
  • reports missing or invalid ISO-code setup through the normal FatturaPA error-message validation flow;
  • preserves the Business Central Country/Region Code primary key and existing address data without requiring tenants to rename their country records.

Linked work

Fixes #11390

How I validated this

  • I read the full diff and it contains only changes I intended.
  • I built the affected app(s) locally with no new analyzer warnings.
  • I ran the change in Business Central and confirmed it behaves as expected.
  • I added or updated tests for the new behavior, or explained below why none are needed.

What I tested and the outcome

Added regression coverage in FatturaPATest.Codeunit.al for the following scenarios:

  • a foreign Country/Region whose Business Central key differs from its ISO code is exported using the two-character ISO Code;
  • the ISO code is used for both IdPaese and Nazione;
  • a Country/Region without a valid two-character ISO code is detected during FatturaPA validation and cannot generate an electronic document.

Existing foreign-customer FatturaPA tests were also updated so their generated Country/Region test data contains a valid ISO code.

The localized Italian Base Application and test applications build successfully.

FatturaPA Test codeunit 144200 was executed locally:

Risk & compatibility

No standard field or table schema is changed.

Country/Region Code remains the Business Central primary key and is not required to be changed to an ISO value. FatturaPA serialization now resolves the corresponding Country/Region."ISO Code" when a two-character country code is required.

Existing tenants that already use ISO alpha-2 values as their Country/Region keys continue to produce the same XML as long as the corresponding ISO Code is configured consistently.

Country/Region records used by FatturaPA must now contain a valid two-character ISO Code. Missing or invalid setup is reported before XML generation instead of allowing an invalid country code to be serialized.

@github-actions github-actions Bot added From Fork Pull request is coming from a fork Team: Finance GitHub request for Finance area needs-approval Workflow runs require maintainer approval to start labels Sep 21, 2026
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 1

Recommendation: Accept with Suggestions

What this PR does

This change resolves FatturaPA country values through the related Country/Region record and writes its two-character ISO Code. It also reports missing or invalid ISO setup before XML generation.

The seven changed XML values address the reported key-versus-ISO mismatch, and the customer regression test exercises the main scenario. One related domestic-country decision still compares record keys, so equivalent records with the same ISO code can still produce foreign-recipient XML behavior.

Problem-solution fit

Fit: Partial

The main serialization defect is fixed consistently across the identified XML values. The remaining key-based domestic-country comparisons and incomplete coverage leave related cases unresolved.

Suggestions

S1 (🟠 Moderate): Use ISO codes for domestic-country decisions
Compare the company and customer ISO codes when deciding whether to emit CodiceFiscale and a domestic CAP. Different Country/Region keys can represent the same ISO country, so the current comparisons can wrongly treat a domestic customer as foreign.

S2 (🟠 Moderate): Update self-billing vendor test setup
Give the mock Fattura vendor country a valid ISO Code and assert that its ISO value is exported. The existing self-billing export tests otherwise fail before reaching their assertions.

S3 (🟠 Moderate): Cover the other changed country sources
The new output test proves only the customer IdPaese and Nazione values. Add mismatched-key checks for company, tax representative, and transmission intermediary because those are separate changed branches.

Risk assessment and necessity

Risk: The production change is narrow and does not change schemas or public APIs. The main regression surface is FatturaPA and self-billing export when Country/Region keys differ from ISO codes or test data has no ISO Code.

Necessity: The change is required because configurable Business Central record keys can produce country values that FatturaPA does not accept. Resolving the ISO Code is the correct approach and avoids requiring tenants to rename existing country records.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=11662 round=1 by=alexei-dobriansky at=2026-09-21T13:37:28.5893004Z lastSha=4cde42fc32c25ffe8b3c836ab69d07c76c033144 reviewKey=2cf433f233465eae35792b4e2f6b664cb15058b655684efff2aee12411452b7b suggestions=S1@9e6c5baa,S2@e05a296d,S3@2c4881c9

@github-actions github-actions Bot removed the needs-approval Workflow runs require maintainer approval to start label Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

From Fork Pull request is coming from a fork Team: Finance GitHub request for Finance area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants