Skip to content

Fix #10839: Use document bank account IBAN in FatturaPA - #12216

Open
Marco Antonio Mauro (marcus905) wants to merge 8 commits into
microsoft:mainfrom
marcus905:fix-10839-fatturapa-document-bank-account
Open

Marco Antonio Mauro (marcus905) wants to merge 8 commits into
microsoft:mainfrom
marcus905:fix-10839-fatturapa-document-bank-account

Conversation

@marcus905

@marcus905 Marco Antonio Mauro (marcus905) commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What & why

The Italian FatturaPA exporter currently always writes Company Information.IBAN to DatiPagamento/DettaglioPagamento/IBAN, even when the posted document contains a different Company Bank Account Code.

This change carries the document-specific company bank account into the temporary Fattura Header while the source document is collected, and uses that bank account's IBAN when generating the payment XML.

The existing localization layering is preserved:

  • Sales Invoice / Sales Credit Memo bank account information is collected in Fattura Doc. Helper.
  • Service Invoice / Service Credit Memo bank account information is collected in Serv. Fattura Subscribers.
  • Export FatturaPA Document consumes the normalized value from the temporary Fattura Header and does not depend directly on Service document tables.

When no document-specific company bank account can be resolved, the exporter continues to use Company Information.IBAN, preserving the existing fallback behavior.

Linked work

Fixes #10839
Fixes AB#657000

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

Built the localized IT Base Application and Tests-Local and ran codeunit 144200 "FatturaPA Test".

Added regression coverage for:

  • Sales Invoice using the selected Company Bank Account IBAN.
  • Sales Credit Memo using the selected Company Bank Account IBAN.
  • Service Invoice using the selected Company Bank Account IBAN.
  • Service Credit Memo using the selected Company Bank Account IBAN.
  • Sales Invoice without a Company Bank Account Code retaining the Company Information.IBAN fallback.

The four positive scenarios set the Company Bank Account Code on the source document before posting, so the tests cover both normal posting propagation and FatturaPA export.

Result:

  • 50 tests executed
  • 42 passed
  • 8 failed

All five tests added for this fix pass.

The remaining 8 failures are unrelated existing test-environment failures in the PostAndSend...WithMissingFields / SendPosted...WithMissingFields tests. They all fail in Library - Error Message.LoadErrorMessages with:

The field with ID = 2074815070 is not found on the page.

The standard FatturaPA Sales/Service Invoice and Credit Memo exports, batch exports, and XSD validation tests pass.

Risk & compatibility

The behavior change is limited to the IBAN emitted in FatturaPA payment data.

Documents with a Company Bank Account Code now export the IBAN from that Bank Account. Documents without a document-specific bank account retain the existing Company Information.IBAN behavior.

The existing OnBeforePopulatePaymentData extensibility point remains unchanged.

No changes are made to posting behavior, payment calculations, FatturaPA routing, or document validation.

@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 and removed needs-approval Workflow runs require maintainer approval to start labels Oct 1, 2026
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 1

Recommendation: Accept

What this PR does

This change carries the selected company bank account from posted sales and service documents into the temporary Fattura header, then exports that account's IBAN. The existing company-information fallback remains when the account cannot be found. The implementation covers invoices and credit memos consistently, preserves the existing event boundary, and the focused tests exercise all four document types plus the fallback.

Problem-solution fit

Fit: Strong

The change directly corrects the reported payment instruction and covers every supported document type described by the scenario. Its scope is limited to collecting and exporting the selected bank account.

Suggestions

None.

Risk assessment and necessity

Risk: Payment export is financially sensitive because an incorrect IBAN can direct a customer to the wrong account. The change is narrow, does not alter posting calculations or public event signatures, and follows the established sales and service bank-account propagation and fallback patterns.

Necessity: The change is required to honor the bank account selected on the posted document. Without it, generated invoices can contain incorrect payment instructions.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=12216 round=1 by=alexei-dobriansky at=2026-10-02T07:49:18.380Z lastSha=6e8cd23eb286e1d27907d7cee59c139070df5ba3 reviewKey=86e8c961200d5e2c944e1c66cb831055aeef2c7bc64632ab4eded9e261e6c5e8 suggestions=

@github-actions github-actions Bot added needs-approval Workflow runs require maintainer approval to start and removed needs-approval Workflow runs require maintainer approval to start labels Oct 2, 2026
@github-actions github-actions Bot added needs-approval Workflow runs require maintainer approval to start and removed needs-approval Workflow runs require maintainer approval to start labels Oct 4, 2026
var
BankAccount: Record "Bank Account";
begin
if BankAccount.Get(TempFatturaHeader."Company Bank Account Code") then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟡\ Medium\ Severity\ —\ Performance}$

GetPaymentIBAN calls BankAccount.Get before guarding the optional Company Bank Account Code, so documents without a selected bank account perform an unnecessary database lookup before falling back to Company Information. Check that the code is non-empty before calling Get.

Suggested fix (apply manually — could not be anchored as a one-click suggestion):

if TempFatturaHeader."Company Bank Account Code" <> '' then
            if BankAccount.Get(TempFatturaHeader."Company Bank Account Code") then
                exit(BankAccount.IBAN);

Knowledge:

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.51.6

Avoid a Bank Account.Get on a blank document Company Bank Account Code,
retaining the existing Company Information.IBAN fallback.

Add an independent Service Invoice regression for the blank-code fallback,
complementing the existing Sales Invoice and four document-bank tests.
@marcus905

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in 856f69e.

GetPaymentIBAN now checks that Company Bank Account Code is nonblank before calling BankAccount.Get, avoiding an unnecessary lookup for documents without a selected bank account.

I also added ExportServiceInvoiceWithoutDocumentBankAccountUsesCompanyIBAN, complementing the existing sales-invoice fallback test.

Validation: Codeunit 144200 executed 51 tests, with 43 passed, including all six IBAN-specific scenarios. The 8 remaining failures are unchanged test-environment issues (Error Messages TestPage failures).

No further changes to payment calculation, bank-account selection or the XML serializer were required.

@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 2

Recommendation: Accept

What this PR does

The change carries the selected bank account from posted sales and service invoices and credit memos into the Fattura header, then exports that account's IBAN. The new commit skips the Bank Account lookup when the code is blank and adds a service-invoice fallback test. A nonblank code still uses the selected account when found; a blank or missing account falls back to Company Information.IBAN. The existing payment-data event can still handle the operation before any lookup.

Problem-solution fit

Fit: Strong

The implementation directly fixes payment instructions that ignored the document's selected bank account, consistently covering all four supported sales and service document types. The new guard preserves the requested blank-code fallback, and the added service test verifies the exact exported IBAN after normal posting.

Status of previous suggestions

No previous suggestions.

New observations (commits since round 1)

None. No new issue was found in the PR-owned changes since the previous round.

Risk assessment and necessity

Risk: An incorrect IBAN can send customers to the wrong account, so payment export is financially sensitive. The round-2 production change only guards an optional lookup; it does not change account selection for nonblank codes, payment amounts, posting, public signatures, or XML structure. The added test uses the existing setup restoration, normal service posting, a blank-code assertion on the posted invoice, and an exact XML value assertion.

Necessity: The fix is needed to honor the bank account selected on the document. Without it, payment XML can direct customers to another company account, requiring a payment-data event replacement as a workaround. The round-2 guard avoids an unnecessary lookup, and the service regression protects the existing fallback without expanding production scope.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=12216 round=2 by=alexei-dobriansky at=2026-11-02T10:42:33.8121309Z lastSha=856f69eeba0e7e5c7669f650365407fc044c8ebf reviewKey=3d41bcc573bcbc77660475aa94f0c1dee811f52b6e5e7340e98ba8486fb8e37c suggestions= parentRound=1

This branch was previously deployed

1 inactive (outdated) deployment
triage — 6e8cd23e Deployed Oct 29, 2026 by AndersLarsenMicrosoft via Classify team ownership #9494
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ADO: Sync Creates an Azure DevOps work item if needed and indicates that one is linked From Fork Pull request is coming from a fork needs-approval Workflow runs require maintainer approval to start Team: Finance GitHub request for Finance area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants