BCApps icon indicating copy to clipboard operation
BCApps copied to clipboard

[Bug]: [DE] ZUGFeRD export fills ShipToTradeParty from the Sell-to address instead of the Ship-to address

Open pri-kise opened this issue 1 month ago • 6 comments

Describe the issue

The ZUGFeRD export in the E-Document for Germany app (codeunit 13917 "Export ZUGFeRD Document") writes the Sell-to customer's name and address into the deliver-to party ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty (EN 16931 BG-13 / BG-15). It should use the document's Ship-to name and address. Only the delivery GLN (BT-71) is taken from the Ship-to Code.

So whenever goods are delivered to an address other than the Sell-to address (a Ship-to Code, or an alternate shipping address entered on the document), the ZUGFeRD invoice states the wrong deliver-to party and address. Ship-to Address 2 is never exported.

Current mapping in both InsertApplicableHeaderTradeDelivery overloads (ExportZUGFeRDDocument.Codeunit.al#L763-L817):

Element under ram:ShipToTradeParty EN 16931 Exported today Should be
ram:Name BT-70 Sell-to Customer Name Ship-to Name
ram:PostalTradeAddress/ram:LineOne BT-75 Sell-to Address Ship-to Address
ram:PostalTradeAddress/ram:LineTwo BT-76 (not exported) Ship-to Address 2
ram:PostalTradeAddress/ram:CityName BT-77 Sell-to City Ship-to City
ram:PostalTradeAddress/ram:PostcodeCode BT-78 Sell-to Post Code Ship-to Post Code
ram:PostalTradeAddress/ram:CountryID BT-80 Sell-to Country/Region Code Ship-to Country/Region Code
ram:GlobalID BT-71 Ship-to GLN, else customer GLN unchanged

Affected documents: posted sales invoices, sales credit memos, service invoices and service credit memos. Service documents are copied into sales headers by field number (TransferRecordFields), and the Ship-to fields (12–17, 91–93) have the same numbers in all four posted header tables.

The XRechnung export in the same app already builds the delivery address from the Ship-to fields (InsertDelivery, ExportXRechnungDocument.Codeunit.al#L997-L1037), and so does the W1 PEPPOL BIS 3.0 export (GetDeliveryAddress). ZUGFeRD is the only format that uses the Sell-to fields.

Expected behavior

ram:ShipToTradeParty is built from the posted document's Ship-to fields:

  • ram:Name = Ship-to Name
  • ram:PostalTradeAddress:
    • ram:PostcodeCode = Ship-to Post Code
    • ram:LineOne = Ship-to Address
    • ram:LineTwo = Ship-to Address 2 (only when not blank, as for the buyer address)
    • ram:CityName = Ship-to City
    • ram:CountryID = ISO code of Ship-to Country/Region Code (falls back to the company's country when blank, as today)
  • ram:GlobalID stays as it is (Ship-to GLN, else customer GLN, only when the customer uses GLN in electronic documents).

When no alternate shipping address is used, Business Central copies the Sell-to address into the Ship-to fields, so the output stays the same as today.

Steps to reproduce

  1. Set up E-Documents for Germany so that posted sales documents for a customer are exported through an E-Document Service with document format ZUGFeRD.
  2. Customer C has address A. Create a Ship-to Address S for C with a different name, address, address 2, post code, city and country/region.
  3. Create a sales invoice for C, set Ship-to Code = S and post it. (Choosing Alternate Shipping Address and typing an address on the document shows the same problem.)
  4. Export the E-Document and open the XML embedded in the ZUGFeRD PDF (xrechnung.xml).
  5. Check rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeDelivery/ram:ShipToTradeParty.

Actual: ram:Name, ram:LineOne, ram:PostcodeCode, ram:CityName and ram:CountryID contain customer C's Sell-to data instead of S. ram:LineTwo is missing. For comparison: the XRechnung export of the same invoice shows S in cac:Delivery/cac:DeliveryLocation/cac:Address.

Sales credit memos, service invoices and service credit memos behave the same way.

Additional context

Proposed fix (local to codeunit 13917 "Export ZUGFeRD Document"):

  • Replace the duplicated code in the two InsertApplicableHeaderTradeDelivery overloads with one local procedure that builds ram:ShipToTradeParty from the Ship-to fields. The existing GLN logic (InsertDeliveryGLN) stays unchanged.
  • Keep the element order of the CII TradeAddressType: PostcodeCode, LineOne, LineTwo, CityName, CountryID.
  • No changes to public procedures, events, tables or the XRechnung export.

Tests (codeunit 13922 "ZUGFeRD XML Document Tests"): today only ShipToTradeParty/ram:GlobalID is covered. I will add tests for a sales invoice, sales credit memo, service invoice and service credit memo whose Ship-to name and address differ from the Sell-to customer. I will also add tests for an address typed on the document without a Ship-to Code, and for a blank Ship-to Address 2.

Note: the XRechnung rules BR-DE-10 and BR-DE-11 (fatal) require city and post code in the deliver-to address. After the fix, a Ship-to address without city or post code fails these rules in ZUGFeRD, as it already does in the XRechnung UBL export (cac:DeliveryLocation/cac:Address).

I will provide a fix for a bug

  • [x] I will provide a fix for a bug

pri-kise avatar Oct 07 '26 06:10 pri-kise

:robot: AI triage completed. Product group, please validate the triage report (Microsoft internal access only, use Ctrl+Click to open in new tab).


Was this triage helpful? React with :thumbsup: or :thumbsdown: on this comment to provide feedback.

github-actions[bot] avatar Oct 07 '26 06:10 github-actions[bot]

Hello @pri-kise, and dear Microsoft,

Do you know if Microsoft will release ZUGFeRD and your other PEPPOL/EN16931 changes, which are already on main, with the next BC CU?

Mike-1984 avatar Oct 07 '26 12:10 Mike-1984

Let me ping the owning team for a verdict.

JesperSchulz avatar Nov 03 '26 13:11 JesperSchulz

@pri-kise, all these ZUGFeRD issues and PRs are getting me all confused 🤣 You linked a PR, then closed it as duplicate of another merged PR. Does that mean this issue is resolved?

JesperSchulz avatar Nov 19 '26 09:11 JesperSchulz

Just received confirmation that this is resolved and can be closed.

JesperSchulz avatar Nov 19 '26 09:11 JesperSchulz

Sorry for the confusion. I've forgot to close the issue. I agreed with @miljance to ingegrate this fix into his PR that was created at a similiar time and touched the same area in those exports (the ship-to block).

To avoid merge conflicts we agreed to combine the two fixes.

pri-kise avatar Nov 19 '26 11:11 pri-kise