microsoft / microsoft/BCApps

[Event Request][W1][Codeunit][37218][PEPPOL30 Common] Add events to handle unsupported document types

Open
#9,424 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Approved event-request Team: Integrations
Dominant language
AL
Stars
683
Forks
459
Avg merge
3d 26m
Merged PRs (30d)
633

Description

Describe the issue

(moved from issue 30345)

app:

"id": "e1966889-b5fb-4fda-a84c-ea71b590e1a9",
"name": "PEPPOL"

There are the XMLports to export documents to Peppol BIS 3.0 format in the app. The XMLports (as xmlport 37201 "Sales Invoice - PEPPOL30") support interfaces to provide our own providers' implementations to modify their behaviour.
But there are a few places in the code where hardcoded calls of methods from codeunit "PEPPOL30 Common" are used and those method do not support extensibility - there are unsupported-document errors.

We need to support other document types to export. And to avoid making of copies of XMLports we need to be able to process new types of documents by this codeunit.

Expected behavior

We need to replace all code parts

else
    Error(UnsupportedDocumentErr);

with integration events. IsHandled pattern will be used to keep an original unsupported-document logic to raise an error. The events will use the same parameters as methods plus IsHandle variable.

    procedure ConvertPostedHeaderToSalesHeader(var PostedRecRef: RecordRef; var SalesHeader: Record "Sales Header")
    var
        IsHandled: Boolean;
    begin
        case PostedRecRef.Number() of
            else begin
                IsHandled := false;
                OnConvertPostedHeaderToSalesHeader(PostedRecRef, SalesHeader, IsHandled);
                if not IsHandled then
                    Error(UnsupportedDocumentErr);
            end;
        end;
    end;

    procedure ConvertPostedLineToSalesLine(var PostedLineRecRef: RecordRef; var SalesLine: Record "Sales Line")
    var
        IsHandled: Boolean;
    begin
        case PostedLineRecRef.Number() of
            else begin
                IsHandled := false;
                OnConvertPostedLineToSalesLine(PostedLineRecRef, SalesLine, IsHandled);
                if not IsHandled then
                    Error(UnsupportedDocumentErr);
            end;
        end;
    end;

    procedure GetTotals(var PostedDocHeaderRecRef: RecordRef; var PostedDocLineRecRef: RecordRef; var TempVATAmtLine: Record "VAT Amount Line" temporary; var TempVATProductPostingGroup: Record "VAT Product Posting Group" temporary; PEPPOLFormat: Enum "PEPPOL 3.0 Format")
    var
        IsHandled: Boolean;
    begin
        case PostedDocHeaderRecRef.Number() of
            else begin
                IsHandled := false;
                OnGetTotals(PostedDocHeaderRecRef, PostedDocLineRecRef, TempVATAmtLine, TempVATProductPostingGroup, PEPPOLFormat, IsHandled);
                if not IsHandled then
                    Error(UnsupportedDocumentErr);
            end;
        end;
    end;

    procedure SetDocumentAttachmentFilters(var PostedDocHeaderRecRef: RecordRef; var DocumentAttachments: Record "Document Attachment")
    var
        IsHandled: Boolean;
    begin
        case PostedDocHeaderRecRef.Number() of
            else begin
                IsHandled := false;
                OnSetDocumentAttachmentFilters(PostedDocHeaderRecRef, DocumentAttachments, IsHandled);
                if not IsHandled then
                    Error(UnsupportedDocumentErr);
            end;
        end;
    end;

    procedure GetInvoiceRoundingLine(PostedDocHeaderRecRef: RecordRef; var TempSalesLineRounding: Record "Sales Line" temporary; PEPPOLFormat: Enum "PEPPOL 3.0 Format")
    var
        IsHandled: Boolean;
    begin
        case PostedDocHeaderRecRef.Number() of
            else begin
                IsHandled := false;
                OnGetInvoiceRoundingLine(PostedDocHeaderRecRef, TempSalesLineRounding, PEPPOLFormat, IsHandled);
                if not IsHandled then
                    Error(UnsupportedDocumentErr);
            end;
        end;
    end;

    procedure SetFilters(var PostedDocHeaderRecRef: RecordRef; var PostedDocLineRecRef: RecordRef; TempSalesLineRounding: Record "Sales Line" temporary)
    var
        IsHandled: Boolean;
    begin
        case PostedDocHeaderRecRef.Number() of
            else begin
                IsHandled := false;
                OnSetFilters(PostedDocHeaderRecRef, PostedDocLineRecRef, TempSalesLineRounding, IsHandled);
                if not IsHandled then
                    Error(UnsupportedDocumentErr);
            end;
        end;
    end;

    [IntegrationEvent(false, false)]
    local procedure OnConvertPostedHeaderToSalesHeader(var PostedRecRef: RecordRef; var SalesHeader: Record "Sales Header"; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnConvertPostedLineToSalesLine(var PostedDocLineRecRef: RecordRef; var SalesLine: Record "Sales Line"; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnGetTotals(var PostedDocHeaderRecRef: RecordRef; var PostedDocLineRecRef: RecordRef; var VATAmountLine: Record "VAT Amount Line"; var VATProductPostingGroup: Record "VAT Product Posting Group"; PEPPOLFormat: Enum "PEPPOL 3.0 Format"; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnSetDocumentAttachmentFilters(var PostedDocHeaderRecRef: RecordRef; var DocumentAttachments: Record "Document Attachment"; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnGetInvoiceRoundingLine(PostedDocHeaderRecRef: RecordRef; var SalesLineRounding: Record "Sales Line"; PEPPOLFormat: Enum "PEPPOL 3.0 Format"; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnSetFilters(var PostedDocHeaderRecRef: RecordRef; var PostedDocLineRecRef: RecordRef; SalesLineRounding: Record "Sales Line"; var IsHandled: Boolean)
    begin
    end;
Steps to reproduce

(no steps)

Additional context

No response

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 in codeunit "PEPPOL30 Common" and locate each document-type branch ending in Error(UnsupportedDocumentErr). Add the six listed integration events with their shown parameters and preserve the existing unsupported-document error when IsHandled remains false; done means all specified fallback branches support extensibility without copying the XMLports.

Written by the indexing model from the issue text.

Assessment

Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.