Skip to content

Conversation

@pri-kise
Copy link
Contributor

@pri-kise pri-kise commented Oct 6, 2025

Summary

Enable ZUGFeRD export for custom reports.

Work Item(s)

Fixes #29254
AB#609600

@pri-kise
Copy link
Contributor Author

pri-kise commented Oct 6, 2025

This is a first draft on how it would be possible to allow custom reports for the sales invoice for the ZUGfERD format.

A partner would need to add the following the their custom sales invoice/cr. memo report.

  • The code that exists in the report extensions
  • an interface implementation to manual bind events that the custom report knows if the xml should be included
  • an event subscriber to the event OnGetZUGFeRDReportIntegrations

@pri-kise pri-kise changed the title [DRAFT] First draft for usage in custom reports [DRAFT] First draft for ZUGFeRD with custom reports Oct 7, 2025
@pri-kise pri-kise changed the title [DRAFT] First draft for ZUGFeRD with custom reports [DRAFT] First draft for ZUGFeRD Export with custom reports Oct 7, 2025
@pri-kise pri-kise changed the title [DRAFT] First draft for ZUGFeRD Export with custom reports [DRAFT] ZUGFeRD Export with custom reports Oct 7, 2025
@JesperSchulz JesperSchulz added the Finance GitHub request for Finance area label Oct 7, 2025
@pri-kise pri-kise changed the title [DRAFT] ZUGFeRD Export with custom reports ZUGFeRD Export with custom reports Oct 9, 2025
@pri-kise pri-kise force-pushed the feature/zugferd-export-for-custom-reports branch from 64f2740 to a62805c Compare October 9, 2025 09:18
@pri-kise pri-kise marked this pull request as ready for review October 9, 2025 09:19
@pri-kise pri-kise requested a review from a team as a code owner October 9, 2025 09:19
@pri-kise pri-kise requested a review from SVinchi October 9, 2025 09:19
@github-actions github-actions bot added the linked Issue is linked to a Azure Boards work item label Oct 9, 2025
@mynjj mynjj self-assigned this Nov 5, 2025
@mynjj
Copy link

mynjj commented Nov 8, 2025

Cool PR @pri-kise 😄

Pros I see of the approach:

  • Allows extenders to subscribe to any events needed throughout the process, so it's very flexible, even if there are events that the original implementation doesn't consider.

"Coding by convention" observations:

  • implementers of BindSubscriptionForReportIntegration have to bind the subscription, but that is of course in their own best interest, so that's probably fine. Also there's no way of calling BindSubscription on an interface, which would avoid the need of the interface, so this is currently a good solution.
  • Nothing restricts the subscriber to delete all other interfaces in the list: this one could be solved by providing a wrapper codeunit to the event that allows only to add.

One thing I don't like that much is that it's a bit too flexible, and we are losing a bit control of the extensibility story - anything in the stacktrace is now possible to be modified if there's an event and it will only happen when coming from "Export Zugferd Document" which might make things difficult to troubleshoot if things go wrong. I'm usually a bit more conservative and more explicit about what can be modified. That being said, there's nothing wrong with the flexibility, and the scenario may warrant it.

An alternative approach could be keep the manual subscription as it is, but in the events of interest where "Export Zugferd Document" subscribes manually, provide hooks (either via events or interfaces) for implementers.

The main question I have is: do we envision that there will be several events called while running ExportSalesDocument that the main implementation "Export ZUGFeRD Document" doesn't subscribe to, but that extenders want to subscribe to?

We'll have a closer look with Nikola, Milica and Magnus over the week 😃

@JesperSchulz
Copy link
Contributor

@mynjj, I'll create a DevOps PR for us to check that all tests pass etc. I'll add the suggested reviewers.

@JesperSchulz JesperSchulz self-assigned this Nov 10, 2025
@JesperSchulz JesperSchulz added the processing-PR The PR is currently being reviewed label Nov 10, 2025
@github-actions
Copy link
Contributor

Processing this PR. The branch is now locked 🔒 Please don't push updates unless otherwise agreed.

@pri-kise
Copy link
Contributor Author

The code will be refactored to the following design:

Adding the following to codeunit 13917 "Export ZUGFeRD Document" :

    EventSubscriberInstance = Manual;

    /// <summary>
    /// Use this procedure to check if the current report print is for the ZUGFeRD export
    /// </summary>
    /// <returns>true when the XML should be embedded</returns>
    procedure IsZUGFeRDPrintProcess() Result: Boolean
    begin
        Result := false;
        OnIsZUGFeRDPrintProcess(Result);
    end;


    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Export ZUGFeRD Document", OnIsZUGFeRDPrintProcess, '', false, false)]
    local procedure EnableOnIsZUGFeRDPrintProcess(var Result: Boolean)
    begin
        Result := true;
    end;

    [InternalEvent(false)]
    local procedure OnIsZUGFeRDPrintProcess(var Result: Boolean)
    begin
    end;

Note: The event EnableOnIsZUGFeRDPrintProcess would be manually binded as alternative to the current event subscribers OnBeforeInitializePDFSalesInvoice / OnBeforeInitializePDFSalesCrMemo

Instead of the event in the reportextension / report we would simple call the method ExportZUGFeRDDocument.IsZUGFeRDPrintProcess()

@pri-kise pri-kise requested a review from mynjj November 12, 2025 15:58
mynjj
mynjj previously approved these changes Nov 12, 2025
nikolakukrika
nikolakukrika previously approved these changes Nov 12, 2025
@pri-kise pri-kise dismissed stale reviews from nikolakukrika and mynjj via d815166 November 13, 2025 06:33
@JesperSchulz
Copy link
Contributor

Merged the latest changes internally. Giving this another go.

@JesperSchulz JesperSchulz merged commit e25f986 into microsoft:main Nov 24, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Finance GitHub request for Finance area linked Issue is linked to a Azure Boards work item processing-PR The PR is currently being reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ZUGFeRD Export for Custom Reports

5 participants