[Bug]: Italian FatturaPA export ignores the document Company Bank Account Code when generating the IBAN
Nobody has claimed this yet.
- Dominant language
- AL
- Stars
- 683
- Forks
- 459
- Avg merge
- 3d 26m
- Merged PRs (30d)
- 633
Description
Describe the issue
The Italian FatturaPA export always uses the IBAN from Company Information when generating DatiPagamento/DettaglioPagamento/IBAN.
This ignores the Company Bank Account Code stored on the source document.
As a result, when a sales or service document is posted using a company bank account other than the one represented by Company Information.IBAN, the generated FatturaPA XML contains payment instructions for the wrong bank account.
The issue is in codeunit 12179 "Export FatturaPA Document", in PopulatePaymentData().
The current implementation ultimately writes:
TempXMLBuffer.AddNonEmptyLastElement('IBAN', CompanyInformation.IBAN);
regardless of the source document's Company Bank Account Code.
This is particularly problematic because the selected company bank account is part of the document and is carried to the posted document, but the FatturaPA exporter does not use it.
Expected behavior
When a source document has a Company Bank Account Code, the FatturaPA exporter should use the IBAN of that Bank Account when generating:
<DatiPagamento>
<DettaglioPagamento>
...
<IBAN>...</IBAN>
</DettaglioPagamento>
</DatiPagamento>
For example, if:
Company Information.IBAN= IBAN-A- Bank Account
BANK-B.IBAN = IBAN-B - the posted invoice has
Company Bank Account Code = BANK-B
then the generated FatturaPA should contain:
<IBAN>IBAN-B</IBAN>
and not IBAN-A.
If no Company Bank Account Code is present on the document, retaining Company Information.IBAN as the fallback would preserve the current standard behavior.
The same principle should apply to the document types supported by the FatturaPA exporter, including Sales Invoices / Credit Memos and Service Invoices / Credit Memos.
Steps to reproduce
-
In an Italian Business Central company, configure FatturaPA so that an electronic sales invoice can be generated.
-
Configure Company Information with an IBAN, for example:
IBAN-A -
Create a company Bank Account, for example:
BANK-Bwith a different IBAN:
IBAN-B -
Create a Sales Invoice or Sales Order for a customer configured for FatturaPA.
-
Set the document's Company Bank Account Code to
BANK-B. -
Post the document.
-
Verify that the resulting Posted Sales Invoice has:
Company Bank Account Code = BANK-B -
Generate/export the FatturaPA XML using the standard Italian localization.
-
Inspect:
FatturaElettronicaBody
/DatiPagamento
/DettaglioPagamento
/IBAN
Actual result
The XML contains:
<IBAN>IBAN-A</IBAN>
because PopulatePaymentData() unconditionally uses CompanyInformation.IBAN.
Expected result
The XML should contain:
<IBAN>IBAN-B</IBAN>
because BANK-B is the company bank account selected on the document.
Additional context
The source document can already be determined from the temporary Fattura Header.
A working extension-side workaround currently uses the existing OnBeforePopulatePaymentData event and:
- determines the source table from
TempFatturaHeader.GetTableID(); - retrieves the corresponding posted document using
TempFatturaHeader."Document No."; - reads its
"Company Bank Account Code"; - retrieves the corresponding
Bank Account; - uses
Bank Account.IBANforDettaglioPagamento/IBAN; - falls back to
Company Information.IBANwhen no document-specific bank account is available.
This workaround currently covers:
- Sales Invoice Header
- Sales Cr.Memo Header
- Service Invoice Header
- Service Cr.Memo Header
Since the standard exporter already owns the document context and payment XML generation, resolving the document-specific company bank account inside the standard implementation would avoid requiring extensions to replace all of PopulatePaymentData() merely to correct the IBAN.
I can provide a PR with the fix and tests.
I will provide a fix for a bug
- I will provide a fix for a bug
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with codeunit 12179 "Export FatturaPA Document", especially PopulatePaymentData(), and trace the temporary Fattura Header to the posted document and its Company Bank Account Code. Verify generated FatturaPA XML for sales and service invoices and credit memos: use the selected bank account's IBAN when present, and Company Information.IBAN as the fallback.
Written by the indexing model from the issue text.
Assessment
- Domain
- localization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100