microsoft / microsoft/BCApps

[Bug]: Italian FatturaPA export ignores the document Company Bank Account Code when generating the IBAN

Open
#10,839 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

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
  1. In an Italian Business Central company, configure FatturaPA so that an electronic sales invoice can be generated.

  2. Configure Company Information with an IBAN, for example:

    IBAN-A

  3. Create a company Bank Account, for example:

    BANK-B

    with a different IBAN:

    IBAN-B

  4. Create a Sales Invoice or Sales Order for a customer configured for FatturaPA.

  5. Set the document's Company Bank Account Code to BANK-B.

  6. Post the document.

  7. Verify that the resulting Posted Sales Invoice has:

    Company Bank Account Code = BANK-B

  8. Generate/export the FatturaPA XML using the standard Italian localization.

  9. 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:

  1. determines the source table from TempFatturaHeader.GetTableID();
  2. retrieves the corresponding posted document using TempFatturaHeader."Document No.";
  3. reads its "Company Bank Account Code";
  4. retrieves the corresponding Bank Account;
  5. uses Bank Account.IBAN for DettaglioPagamento/IBAN;
  6. falls back to Company Information.IBAN when 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.