Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ codeunit 6109 "E-Document Import Helper"
begin
if not Vendor.Get(VendorNo) then
EDocErrorHelper.LogSimpleErrorMessage(EDocument, StrSubstNo(VendorNotFoundErr, EDocument."Bill-to/Pay-to Name"));

if Vendor."Self-Billing Agreement" then
LogErrorIfVendorIsSelfBilling(EDocument, Vendor);
end;

/// <summary>
Expand All @@ -612,6 +615,12 @@ codeunit 6109 "E-Document Import Helper"
exit(ServiceParticipant.Participant);
end;

procedure LogErrorIfVendorIsSelfBilling(var EDocument: Record "E-Document"; Vendor: Record Vendor)
begin
if (EDocument."Direction" = Enum::"E-Document Direction"::"Incoming") then
EDocErrorHelper.LogSimpleErrorMessage(EDocument, StrSubstNo(SelfBillingVendorErr, Vendor."No."));
end;

#if not CLEAN26
/// <summary>
/// Use it to process imported E-Document
Expand Down Expand Up @@ -1000,5 +1009,6 @@ codeunit 6109 "E-Document Import Helper"
UnableToApplyDiscountErr: Label 'The invoice discount of %1 cannot be applied. Invoice discount must be allowed on at least one invoice line and invoice total must not be 0.', Comment = '%1 - a decimal number';
TotalsMismatchErr: Label 'The total amount %1 on the created document is different than the total amount %2 in the electronic document.', Comment = '%1 total amount, %2 expected total amount';
VendorNotFoundErr: Label 'Cannot find vendor ''%1'' based on the vendor''s name, address or VAT registration number on the electronic document. Make sure that a card for the vendor exists with the corresponding name, address or VAT Registration No.', Comment = '%1 Vendor name (e.g. London Postmaster)';
SelfBillingVendorErr: Label 'Inbound E-Document blocked for vendor %1 due to Self-Billing Agreement. Supplier-issued invoices cannot be processed for this vendor.', Comment = '%1 Vendor name (e.g. London Postmaster)';
NotSpecifiedUnitOfMeasureTxt: Label '<NONE>';
}
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,13 @@ codeunit 6140 "E-Doc. Import"
end;

if Vendor.Get(EDocument."Bill-to/Pay-to No.") then
if ValidateEDocumentIsForPurchaseOrder(EDocument, Vendor) then
ReceiveEDocumentToPurchaseOrder(EDocument, EDocService, SourceDocumentHeader, SourceDocumentLine, EDocServiceStatus, Vendor, Window)
if Vendor."Self-Billing Agreement" then
EDocImportHelper.LogErrorIfVendorIsSelfBilling(EDocument, Vendor)
else
ReceiveEDocumentToPurchaseDoc(EDocument, EDocService, SourceDocumentHeader, SourceDocumentLine, EDocServiceStatus, Window, CreateJnlLine)
if ValidateEDocumentIsForPurchaseOrder(EDocument, Vendor) then
ReceiveEDocumentToPurchaseOrder(EDocument, EDocService, SourceDocumentHeader, SourceDocumentLine, EDocServiceStatus, Vendor, Window)
else
ReceiveEDocumentToPurchaseDoc(EDocument, EDocService, SourceDocumentHeader, SourceDocumentLine, EDocServiceStatus, Window, CreateJnlLine)
else
EDocErrorHelper.LogErrorMessage(EDocument, Vendor, Vendor.FieldNo("No."), FailedToFindVendorErr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ codeunit 139628 "E-Doc. Receive Test"
NullGuid: Guid;
GetBasicInfoErr: Label 'Test Get Basic Info From Received Document Error.', Locked = true;
GetCompleteInfoErr: Label 'Test Get Complete Info From Received Document Error.', Locked = true;
IncorrectValueErr: Label 'Incorrect number of E-Document returned.';
SelfBillingVendorErr: Label 'Inbound E-Document blocked for vendor %1 due to Self-Billing Agreement. Supplier-issued invoices cannot be processed for this vendor.', Comment = '%1 Vendor name (e.g. London Postmaster)';
VATRegistrationLbl: Label 'GB123456789';
ImportDataExchDefLbl: Label 'EDOCPEPPOLINVIMP';
EndpointPathLbl: label '/Invoice/cac:AccountingSupplierParty/cac:Party/cbc:EndpointID';

[Test]
procedure ReceiveSinglePurchaseInvoice()
Expand Down Expand Up @@ -3043,4 +3048,94 @@ codeunit 139628 "E-Doc. Receive Test"
end;
#pragma warning restore AL0432
#endif

[Test]
procedure PurchaseOrderMustNotBeCreatedForSelfBillingInvoice()
var
EDocService: Record "E-Document Service";
VATPostingSetup: Record "VAT Posting Setup";
EDocServiceDataExchDef: Record "E-Doc. Service Data Exch. Def.";
TempXMLBuffer: Record "XML Buffer" temporary;
TempBlob: Codeunit "Temp Blob";
EDocImport: Codeunit "E-Doc. Import";
EDocServicesPage: TestPage "E-Document Services";
EDocumentPage: TestPage "E-Document";
Document: Text;
XMLInstream: InStream;
begin
// [SCENARIO 580348] Verify that purchase order is not created for self-billing invoice.
Initialize();
BindSubscription(EDocImplState);

// [GIVEN] Create E-Document Service.
LibraryEDoc.CreateTestReceiveServiceForEDoc(EDocService, Enum::"Service Integration"::"Mock");

// [GIVEN] Reset E-Document Service formats.
EDocServicesPage.OpenView();
EDocServicesPage.Filter.SetFilter(Code, EDocService.Code);
EDocServicesPage.ResetFormats.Invoke();

// [GIVEN] Create vendor with VAT Business Posting Group.
LibraryERM.CreateVATPostingSetupWithAccounts(VATPostingSetup, Enum::"Tax Calculation Type"::"Normal VAT", 1);
Vendor.Get(LibraryPurchase.CreateVendorWithVATBusPostingGroup(VATPostingSetup."VAT Bus. Posting Group"));

// [GIVEN] Update vendor to be self-billing.
Vendor."VAT Registration No." := VATRegistrationLbl;
Vendor."Receive E-Document To" := Enum::"E-Document Type"::"Purchase Invoice";
Vendor."Country/Region Code" := CountryRegion.Code;
Vendor."Self-Billing Agreement" := true;
Vendor.Modify();

// [GIVEN] Create E-Document Service Data Exchange Definition.
EDocService."Document Format" := "E-Document Format"::"Data Exchange";
EDocService."Lookup Account Mapping" := false;
EDocService."Lookup Item GTIN" := false;
EDocService."Lookup Item Reference" := true;
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();

// [GIVEN] Create E-Document Service Data Exchange Definition.
EDocServiceDataExchDef."E-Document Format Code" := EDocService.Code;
EDocServiceDataExchDef."Document Type" := EDocServiceDataExchDef."Document Type"::"Purchase Invoice";
EDocServiceDataExchDef."Impt. Data Exchange Def. Code" := ImportDataExchDefLbl;
if not EDocServiceDataExchDef.Insert() then
EDocServiceDataExchDef.Modify();

// [GIVEN] Modify XML to have vendor VAT number as EndpointID.
TempXMLBuffer.LoadFromText(EDocReceiveFiles.GetDocument1());
TempXMLBuffer.Reset();
TempXMLBuffer.SetRange(Type, TempXMLBuffer.Type::Element);
#pragma warning disable AA0210
TempXMLBuffer.SetRange(Path, EndpointPathLbl);
#pragma warning restore AA0210
TempXMLBuffer.FindFirst();
TempXMLBuffer.Value := Vendor."VAT Registration No.";
TempXMLBuffer.Modify();

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

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

// [GIVEN] Set document in variable storage.
LibraryVariableStorage.Clear();
LibraryVariableStorage.Enqueue(Document);
LibraryVariableStorage.Enqueue(1);
EDocImplState.SetVariableStorage(LibraryVariableStorage);

// [WHEN] Receiving the document.
EDocImport.ReceiveAndProcessAutomatically(EDocService);

// [THEN] Verify that no purchase order is created.
EDocumentPage.OpenView();
EDocumentPage.Last();
Assert.AreEqual(Format(Enum::"E-Document Service Status"::"Imported Document Processing Error"), EDocumentPage.InboundEDocFactbox.Status.Value(), IncorrectValueErr);
EDocumentPage.ErrorMessagesPart.Description.AssertEquals(StrSubstNo(SelfBillingVendorErr, Vendor."No."));
end;
}
Loading