microsoft / microsoft/BCApps

[Bug]: Italian FatturaPA export can generate invalid RegimeFiscale values from unvalidated Company Type

Open
#11,371 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 generates the RegimeFiscale element by prefixing the value of Company Information."Company Type" with RF.

The current implementation is effectively:

TempXMLBuffer.AddNonEmptyLastElement(
    'RegimeFiscale',
    'RF' + CompanyInformation."Company Type");

However, RegimeFiscale is not a free-form value. The FatturaPA specification defines a fixed set of allowed RFxx codes.

Company Type is currently exposed as a generic field and is not validated against the allowed FatturaPA fiscal-regime values. As a result, Business Central can successfully generate a FatturaPA XML document containing an invalid RegimeFiscale.

For example, setting:

Company Type = 99

results in:

<RegimeFiscale>RF99</RegimeFiscale>

even though RF99 is not a valid FatturaPA fiscal-regime code.

There is also a usability/data-model issue: the caption Company Type does not make it clear that the field represents the company's FatturaPA RegimeFiscale.

The exact implementation could use a lookup table, enum, or another validation mechanism, but the stored/exported value should be constrained to valid FatturaPA fiscal-regime codes.

Expected behavior

Business Central should prevent the FatturaPA exporter from generating a RegimeFiscale value that is not allowed by the FatturaPA specification.

The company setup should expose the fiscal regime using a FatturaPA-specific concept rather than an unrestricted/generically named Company Type value.

For example, the user should be able to select only supported fiscal regimes, and the exporter should generate the corresponding valid RFxx value.

Whether this is implemented using a table, enum, validation logic, or another approach is an implementation detail.

At minimum, generation of a FatturaPA document containing an invalid RegimeFiscale should not be possible.

Steps to reproduce
  1. Open Company Information in an Italian Business Central company.

  2. Set Company Type to a value that does not correspond to a valid FatturaPA fiscal regime, for example:

    99
    
  3. Create and post a sales invoice for a customer configured for FatturaPA.

  4. Generate/export the electronic invoice.

  5. Inspect the generated XML.

The XML contains:

<RegimeFiscale>RF99</RegimeFiscale>

The export succeeds even though RF99 is not an allowed FatturaPA RegimeFiscale value.

Additional context

The issue is in the Italian FatturaPA export implementation, currently in:

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

The relevant logic in PopulateCompanyInformation directly concatenates RF with Company Information."Company Type".

Other parts of the FatturaPA exporter already contain schema-aware handling, such as explicitly limiting several XML values to the maximum lengths allowed by the FatturaPA schema. RegimeFiscale should similarly be generated from a validated set of allowed values.

In addition to the validation problem, renaming or recaptioning the current Company Type field to make its FatturaPA purpose explicit would improve usability, although the primary issue is that invalid XML values can currently be generated.

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, especially PopulateCompanyInformation, and trace how Company Information."Company Type" reaches RegimeFiscale. Check the FatturaPA specification for the allowed fiscal-regime codes and reproduce the RF99 case. Done means company setup and export cannot produce a RegimeFiscale value outside that allowed set.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.