Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E-Document Core] - Show Purchase attachments in Peppol #27876

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Apps/W1/EDocument/app/src/Document/EDocument.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.eServices.EDocument;

using System.Telemetry;
using System.Utilities;
using Microsoft.Foundation.Attachment;
using Microsoft.eServices.EDocument.Integration.Send;
using Microsoft.eServices.EDocument.Integration.Receive;
using Microsoft.Bank.Reconciliation;
Expand Down Expand Up @@ -185,6 +186,16 @@ page 6121 "E-Document"
}
#endif
}
area(factboxes)
{
part("Attached Documents List"; "Doc. Attachment List Factbox")
{
Caption = 'Documents';
UpdatePropagation = Both;
SubPageLink = "E-Document Entry No." = field("Entry No"),
"E-Document Attachment" = const(true);
}
}
}
actions
{
Expand Down
11 changes: 11 additions & 0 deletions Apps/W1/EDocument/app/src/Document/EDocuments.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace Microsoft.eServices.EDocument;
using Microsoft.Foundation.Attachment;

page 6122 "E-Documents"
{
Expand Down Expand Up @@ -55,6 +56,16 @@ page 6122 "E-Documents"
}
}
}
area(factboxes)
{
part(DocumentListFactBox; "Doc. Attachment List Factbox")
{
Caption = 'Documents';
UpdatePropagation = Both;
SubPageLink = "E-Document Entry No." = field("Entry No"),
"E-Document Attachment" = const(true);
}
}
}
actions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ codeunit 6169 "E-Doc. Attachment Processor"
end;
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Document Attachment Mgmt", OnAfterGetRefTable, '', false, false)]
local procedure OnAfterGetRefTableForEDocs(var RecRef: RecordRef; DocumentAttachment: Record "Document Attachment")
var
EDocument: Record "E-Document";
begin
case DocumentAttachment."Table ID" of
Database::"E-Document":
begin
RecRef.Open(Database::"E-Document");
if EDocument.Get(DocumentAttachment."No.") then
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the DocumentAttachment."No." really correct here?
Shouldn't it be DocumentAttachment."E-Document Entry No."?

Copy link
Author

Choose a reason for hiding this comment

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

If e-document has no linked document in the attachments table Table ID is equal to E-Document table id and No. is equal to Entry No.
E-Document:
image
Attachments table:
image
If e-document has linked document then attachment record is renamed to have a link with related document.

RecRef.GetTable(EDocument);
end;
end;
end;

var
MissingEDocumentTypeErr: Label 'E-Document type %1 is not supported for attachments', Comment = '%1 - E-Document document type';

Expand Down
126 changes: 126 additions & 0 deletions Apps/W1/EDocument/test/src/Receive/EDocReceiveTest.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,45 @@ codeunit 139628 "E-Doc. Receive Test"
PurchaseHeader.Delete(true);
end;

[Test]
[HandlerFunctions('SelectPOHandlerCancel,ConfirmHandler')]
procedure ReceiveSinglePurchaseInvoice_PEPPOL_WithAttachment_WithoutLinkedOrder()
var
EDocService: Record "E-Document Service";
EDocument: Record "E-Document";
Item: Record Item;
DocumentAttachment: Record "Document Attachment";
VATPostingSetup: Record "VAT Posting Setup";
DocumentVendor: Record Vendor;
begin
// [FEATURE] [E-Document] [Receive]
// [SCENARIO] Receive single e-document with two attachments without linking to purchase order
Initialize();
BindSubscription(EDocImplState);

// [GIVEN] e-Document service to receive one single purchase order
CreateEDocServiceToReceivePurchaseOrder(EDocService);
// [GIVEN] Vendor with VAT Posting Setup
CreateVendorWithVatPostingSetup(DocumentVendor, VATPostingSetup);
// [GIVEN] Item with item reference
CreateItemWithReference(Item, VATPostingSetup);
// [GIVEN] Incoming PEPPOL file
CreateIncomingPEPPOL(DocumentVendor);
// [GIVEN] Purchase order created for vendor
CreatePurchaseOrder(Item, DocumentVendor);

// [WHEN] Running Receive
InvokeReceive(EDocService);

// [THEN] Attachments are imported and linked with e-Document
EDocument.FindLast();
DocumentAttachment.SetRange("No.", Format(EDocument."Entry No"));
DocumentAttachment.SetRange("Table ID", Database::"E-Document");
DocumentAttachment.SetRange("E-Document Entry No.", EDocument."Entry No");
DocumentAttachment.SetRange("E-Document Attachment", true);
Assert.RecordCount(DocumentAttachment, 2);
end;

[ModalPageHandler]
procedure SelectPOHandler(var POList: TestPage "Purchase Order List")
var
Expand Down Expand Up @@ -1437,6 +1476,93 @@ codeunit 139628 "E-Doc. Receive Test"
Assert.AreEqual(PurchHeader."Amount Including VAT", Abs(GenJnlLine.Amount), '');
end;

local procedure CreateEDocServiceToReceivePurchaseOrder(var EDocService: Record "E-Document Service")
begin
LibraryEDoc.CreateTestReceiveServiceForEDoc(EDocService, Enum::"Service Integration"::Mock);
SetDefaultEDocServiceValues(EDocService);
end;

local procedure CreateVendorWithVatPostingSetup(var DocumentVendor: Record Vendor; var VATPostingSetup: Record "VAT Posting Setup")
begin
LibraryPurchase.CreateVendorWithVATRegNo(DocumentVendor);
LibraryERM.CreateVATPostingSetupWithAccounts(VATPostingSetup, Enum::"Tax Calculation Type"::"Normal VAT", 1);
DocumentVendor."VAT Bus. Posting Group" := VATPostingSetup."VAT Bus. Posting Group";
DocumentVendor."Receive E-Document To" := Enum::"E-Document Type"::"Purchase Order";
DocumentVendor.Modify(false);
end;

local procedure CreateItemWithReference(var Item: Record Item; var VATPostingSetup: Record "VAT Posting Setup")
var
ItemReference: Record "Item Reference";
begin
Item.FindFirst();
Item."VAT Prod. Posting Group" := VATPostingSetup."VAT Prod. Posting Group";
Item.Modify(false);
ItemReference.DeleteAll(false);
ItemReference."Item No." := Item."No.";
ItemReference."Reference No." := '1000';
ItemReference.Insert(false);
end;

local procedure CreateIncomingPEPPOL(var DocumentVendor: Record Vendor)
var
TempXMLBuffer: Record "XML Buffer" temporary;
TempBlob: Codeunit "Temp Blob";
Document: Text;
XMLInstream: InStream;
begin
TempXMLBuffer.LoadFromText(EDocReceiveFiles.GetDocument1());
TempXMLBuffer.Reset();
TempXMLBuffer.SetRange(Type, TempXMLBuffer.Type::Element);
TempXMLBuffer.SetRange(Path, '/Invoice/cac:AccountingSupplierParty/cac:Party/cbc:EndpointID');
TempXMLBuffer.FindFirst();
TempXMLBuffer.Value := DocumentVendor."VAT Registration No.";
TempXMLBuffer.Modify();

TempXMLBuffer.Reset();
TempXMLBuffer.FindFirst();
TempXMLBuffer.Save(TempBlob);

TempBlob.CreateInStream(XMLInstream, TextEncoding::UTF8);
XMLInstream.Read(Document);

LibraryVariableStorage.Clear();
LibraryVariableStorage.Enqueue(Document);
LibraryVariableStorage.Enqueue(1);
EDocImplState.SetVariableStorage(LibraryVariableStorage);
end;

local procedure CreatePurchaseOrder(var Item: Record Item; var DocumentVendor: Record Vendor)
begin
LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Order, DocumentVendor."No.");
LibraryPurchase.CreatePurchaseLine(PurchaseLine, PurchaseHeader, PurchaseLine.Type::Item, Item."No.", 10);
PurchaseLine.Validate("Direct Unit Cost", 100);
PurchaseLine.Modify(true);
end;

local procedure InvokeReceive(var EDocService: Record "E-Document Service")
var
EDocServicePage: TestPage "E-Document Service";
begin
EDocServicePage.OpenView();
EDocServicePage.Filter.SetFilter(Code, EDocService.Code);
EDocServicePage.Receive.Invoke();
end;

local procedure SetDefaultEDocServiceValues(var EDocService: Record "E-Document Service")
begin
EDocService."Document Format" := "E-Document Format"::"PEPPOL BIS 3.0";
EDocService."Lookup Account Mapping" := false;
EDocService."Lookup Item GTIN" := false;
EDocService."Lookup Item Reference" := false;
EDocService."Resolve Unit Of Measure" := false;
EDocService."Validate Line Discount" := false;
EDocService."Verify Totals" := false;
EDocService."Use Batch Processing" := false;
EDocService."Validate Receiving Company" := false;
EDocService.Modify(false);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"E-Document Create Purch. Doc.", 'OnBeforeProcessHeaderFieldsAssignment', '', false, false)]
local procedure OnBeforeProcessHeaderFieldsAssignment(var DocumentHeader: RecordRef; var PurchaseField: Record Field);
begin
Expand Down
Loading