microsoft / microsoft/BCApps

[Bug]: FatturaPA filename does not fall back to VAT Registration No. when Fiscal Code is empty

Open Beginner friendly
#10,964 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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 transport filename generated by codeunit "Fattura Doc. Helper" is inconsistent with the transmitter identifier written to the generated FatturaPA XML when the company's Fiscal Code is empty.

Fattura Doc. Helper.GetFileName() currently builds the filename as:

CompanyInformation."Country/Region Code" +
CompanyInformation."Fiscal Code" + '_' +
ZeroNo + BaseString

The method itself documents the expected structure as:

country code + transmitter's unique identity code + unique progressive number of the file

However, when generating DatiTrasmissione/IdTrasmittente/IdCodice, "Export FatturaPA Document" already uses the following logic:

if CompanyInformation."Fiscal Code" = '' then
    TempXMLBuffer.AddNonEmptyLastElement(
        'IdCodice', CompanyInformation."VAT Registration No.")
else
    TempXMLBuffer.AddNonEmptyLastElement(
        'IdCodice', CompanyInformation."Fiscal Code");

Therefore, when Fiscal Code is empty and VAT Registration No. is populated, Business Central can generate an XML containing a valid transmitter identifier while producing a transport filename without that identifier.

For example, with:

Country/Region Code: IT
Fiscal Code:
VAT Registration No.: 01234567890
Progressive No.: 123

the XML contains:

<IdTrasmittente>
    <IdPaese>IT</IdPaese>
    <IdCodice>01234567890</IdCodice>
</IdTrasmittente>

while the generated filename is effectively:

IT_0000000123.xml

instead of:

IT01234567890_0000000123.xml

The same issue affects the corresponding ZIP filename because the FatturaPA export code uses FatturaDocHelper.GetFileName() as its base name for both XML and ZIP output.

This also means that populating Company Information."Fiscal Code" solely as a workaround for filename generation is undesirable: the XML generator intentionally supports using the VAT Registration No. as IdTrasmittente/IdCodice when Fiscal Code is not set.

Expected behavior

The transmitter identifier used in the FatturaPA transport filename should follow the same selection logic as DatiTrasmissione/IdTrasmittente/IdCodice:

  1. use Company Information."Fiscal Code" when it is populated;
  2. otherwise use Company Information."VAT Registration No.".

In other words, the identifier represented in the transport filename and the identifier represented by IdTrasmittente/IdCodice should remain consistent.

A possible implementation would be to centralize this selection in a helper procedure and use it both for XML generation and filename generation, avoiding duplicated logic.

Conceptually:

local procedure GetTransmitterId(): Text
begin
    if CompanyInformation."Fiscal Code" <> '' then
        exit(CompanyInformation."Fiscal Code");

    exit(CompanyInformation."VAT Registration No.");
end;

and then use the resulting identifier from GetFileName() as well as when populating IdTrasmittente/IdCodice.

Steps to reproduce
  1. Use the Italian localization.

  2. Open Company Information.

  3. Set:

    • Country/Region Code = IT
    • VAT Registration No. to a valid Italian VAT registration number
    • leave Fiscal Code empty.
  4. Configure FatturaPA and its progressive number series normally.

  5. Generate/export a FatturaPA document.

  6. Inspect DatiTrasmissione/IdTrasmittente in the generated XML.

  7. Compare IdCodice with the generated XML/ZIP filename.

Actual result

IdTrasmittente/IdCodice falls back to VAT Registration No., while the filename is generated using the empty Fiscal Code, resulting in a name such as:

IT_0000000123.xml
Expected result

The same transmitter identifier should be used in both places, resulting in:

IT01234567890_0000000123.xml

and, where applicable:

IT01234567890_0000000123.zip
Additional context

The inconsistency is currently visible directly in the BaseApp implementation:

  • Fattura Doc. Helper.GetFileName() always uses CompanyInformation."Fiscal Code" for the transmitter part of the filename.
  • Export FatturaPA Document already falls back from Fiscal Code to VAT Registration No. when generating IdTrasmittente/IdCodice.

This appears to be a small localization bug rather than a request for configurable file naming: FatturaPA transport filenames have protocol significance and should continue to be generated by the localization. The proposed change only aligns the filename transmitter identifier with the transmitter identifier that Business Central already writes to the XML.

I am willing to provide a fix once the issue is approved for contribution.

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 by reading Fattura Doc. Helper.GetFileName() and the IdTrasmittente/IdCodice logic in Export FatturaPA Document. Trace how the transmitter identifier reaches XML, XML filenames, and ZIP filenames. Done means Fiscal Code is preferred, VAT Registration No. is used when it is empty, and all output names match the XML identifier.

Written by the indexing model from the issue text.

Assessment

Domain
backend, localization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.