Repository navigation
Add SaaS-safe unposted FatturaPA XML preview API (#12334) - #13014
Marco Antonio Mauro (marcus905) wants to merge 7 commits into
Conversation
Reuse standard FatturaPA line and VAT rules, capture posting-preview accounting entries, and expose side-effect-free preparation and XML serialization. Cover invoice, credit memo and sales order preview, including accounting parity, setup-safe document type resolution, and transmission number isolation. Preserve upstream XSD test-path correction in the existing test helper.
Good Sense Reviewer - Round 1Recommendation: Request ChangesWhat this PR doesThis change adds a SaaS-callable path that prepares temporary FatturaPA buffers from unposted sales documents and reuses the standard XML serializer. Posting preview supplies the accounting entries, and the new tests cover the main invoice, credit memo, sales order, VAT, and numbering scenarios. However, the manual buffer preparation does not yet reproduce all fiscally significant header and order metadata, so the generated preview can differ from the standard posted export. Problem-solution fitFit: Strong The new API shape directly supports side-effect-free preparation and serialization with a caller-supplied preview progressive number. The remaining gaps are in parity with the standard payload rather than in the overall design. SuggestionsS1 (🔴 High): Populate all standard fiscal header fields S2 (🔴 High): Build order and shipment metadata rows S3 (🔴 High): Calculate the invoice discount FlowField Risk assessment and necessityRisk: This code produces fiscal XML in a financially sensitive area. Missing discounts, tax representative data, or linked order/document references can make the preview materially different from the payload generated after posting; the new SaaS surface itself is additive and does not break existing callers. Necessity: A side-effect-free preview API is useful and avoids duplicating the serializer. The scope is justified, but the preparation path must include the same fiscal metadata as the standard export before it is safe to expose as an authoritative preview.
|
…rosoft#13014) Calculate invoice discount FlowField; share tax representative resolution and order/shipment buffer writers; build available source document references without fabricating posting-only DDT IDs; expand regression coverage for header metadata, customer order references and shipped orders. Verified with test codeunit 144200 (65 tests: 46 passed, 19 pre-existing environment failures).
|
Thanks for the detailed review. I've pushed follow-up commit S1: Fiscal header: Preview now resolves the tax representative from temporary posting-preview VAT entries, with the same company-information fallback as posted export. Applied-document links dependent on the posted customer-ledger entry cannot reliably be inferred before posting, so preview deliberately does not fabricate them. S2: Order and shipment data: Preview prepares available order/shipment references and reuses the standard buffer writers. XML regressions now compare S3: Invoice discount: The source Validation: Codeunit Please re-review, particularly whether the explicit preview boundary for posting-only applied-document and shipment identifiers meets the intended scope of #12334. |
Good Sense Reviewer - Round 2Recommendation: Request ChangesWhat this PR doesThe follow-up now calculates the invoice-discount FlowField, copies tax-representative data from posting preview, and builds order and shipment metadata. The discount fix is correct, but two parity gaps remain: known document applications are still omitted, and the shipment scan can include fully invoiced shipment lines from earlier invoices. Status of previous suggestions
New observations (commits since round 1)None - the remaining shipment concern is part of S2. Risk assessment and necessityRisk: The preview can still omit Necessity: The side-effect-free preview API remains useful and the chosen reuse of standard serialization is appropriate. The remaining work should narrow source references to the pending invoice and map application data that is already known before posting.
|
…ain DDT references to pending invoice quantities
…DTs (microsoft#13014) Preserve known credit-memo Applies-to Doc. No. fiscal references, exclude fully invoiced historical shipment lines from preview, fix unsupported Min call, and cover fiscal XML application and shipment metadata with regression tests. Codeunit 144200 verified: 68 tests, 49 passed including all 23 preview tests, 19 known environment failures (11 missing XSD, 8 missing error-message page field).
|
Thanks for the Round 2 review. I've pushed follow-up commits addressing the remaining S1 and S2 concerns. S1: Known applications: The preview now resolves direct credit-memo applications using S2: Shipment references: Preview now considers only sales-order lines being invoiced, excludes fully invoiced historical shipments, and limits shipment references to the quantities relevant to the pending invoice. A regression test verifies that an already-invoiced DDT is excluded while the pending shipment is retained. Validation: Codeunit The existing standard FatturaPA XML serializer remains unchanged. Please re-review the updated implementation. |
What & why
The Italian FatturaPA implementation provides the standard outbound XML serializer, but extensions cannot currently prepare and generate the same payload for an unposted sales document through a SaaS-safe API without reproducing substantial parts of the standard logic or invoking posting/export functionality with persistent side effects.
This change introduces a preview-safe preparation path for unposted Sales Orders, Sales Invoices and Sales Credit Memos, allowing extensions to generate the standard FatturaPA XML before posting or transmitting the document.
The implementation:
FatturaPA Preview Mgt.to prepare temporaryFattura HeaderandFattura Linerecords from an unposted sales document, accepting a caller-supplied previewProgressivoInvio.Export FatturaPA Document.GenerateXMLFile(...)serializer by making the required temporary-buffer APIs SaaS-callable.The preview does not consume the actual FatturaPA progressive-number series, post the sales document, transmit XML, or initialize the Fattura Document Type setup catalog through the new read-only lookup path.
No new database tables or fields are introduced. The preview API operates on existing temporary FatturaPA buffers and uses Microsoft's existing outbound serializer rather than duplicating XML generation.
Linked work
Fixes #12334
Related: #11633 ÔÇö FatturaPA fiscal-regime setup initialization. A subsequent change can move Fattura Document Type catalog initialization into the company initialization/upgrade lifecycle once the relevant setup-management work is available. This PR keeps the existing posted-export initialization behavior unchanged.
How I validated this
What I tested and the outcome
144200 "FatturaPA Test"on October 19, 2026.ImportoTotaleDocumento.The eight remaining failures are confined to existing
*WithMissingFieldstests. All fail inLibrary - Error Message.LoadErrorMessages()because field ID2074815070is missing from the test page. This same failure was present before the preview changes and remained unchanged throughout the test runs.The final PR branch also retains the current upstream correction to the XSD test-file path. This adjustment does not alter production behavior.
Risk & compatibility
OnPremrestrictions are removed from the existing temporary-buffer/serialization boundary, and the new preview preparation procedures are callable by extensions.ProgressivoInvio; the real transmission identifier remains the responsibility of the standard export workflow.The change preserves the existing FatturaPA XML serializer as the authoritative implementation, allowing preview consumers to inherit standard XML generation behavior and future serializer improvements.
Fixes AB#655979