Skip to content
Closed
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
40 changes: 28 additions & 12 deletions src/Apps/W1/APIV1/test/src/APIV1PurchaseInvoicesE2E.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ codeunit 139729 "APIV1 - Purchase Invoices E2E"
Vendor.Validate("Payment Terms Code", PaymentTerms.Code);
Vendor.Modify(true);

// [GIVEN] Create Invoice Json with Vendor No and Invoice Date
InvoiceJSON := CreateInvoiceJSON('vendorNumber', VendorNo, 'invoiceDate', WorkDate());
// [GIVEN] Create Invoice Json with dates before the vendor defaults are applied
InvoiceJSON := CreateInvoiceJSON('invoiceDate', WorkDate(), 'postingDate', WorkDate());
InvoiceJSON := LibraryGraphMgt.AddPropertytoJSON(InvoiceJSON, 'vendorNumber', VendorNo);
COMMIT();

// [WHEN] We POST the JSON to the Web Service
Expand All @@ -445,7 +446,30 @@ codeunit 139729 "APIV1 - Purchase Invoices E2E"
PurchaseHeader.SETRANGE("No.", InvoiceNumber);
PurchaseHeader.SETRANGE("Buy-from Vendor No.", VendorNo);
Assert.IsTrue(PurchaseHeader.FINDFIRST(), UnpostedInvoiceExistErr);
Assert.IsTrue(PurchaseHeader."Payment Discount %" <> 0, PaymentDiscountErr);
if PurchaseHeader."Payment Discount %" = 0 then
Assert.IsTrue(HasLocalizedPaymentDiscount(PurchaseHeader."No."), PaymentDiscountErr);
end;

local procedure HasLocalizedPaymentDiscount(DocumentNo: Code[20]): Boolean
var
RecordField: Record Field;
PaymentLineRecordRef: RecordRef;
PaymentLineFieldRef: FieldRef;
begin
RecordField.SetRange(TableNo, 12170);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$\textbf{🟡\ Medium\ Severity\ —\ Style}$

The new RecordRef.Open call and the associated TableNo filter use the numeric table ID 12170 even though the Payment Lines table has a named alias. Use DATABASE::"Payment Lines" for both references so the object dependency remains readable and survives renumbering.

Knowledge:

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.48.6

if RecordField.IsEmpty() then
exit(false);

PaymentLineRecordRef.Open(12170);
PaymentLineFieldRef := PaymentLineRecordRef.Field(10);
PaymentLineFieldRef.SetRange(2);
PaymentLineFieldRef := PaymentLineRecordRef.Field(1);
PaymentLineFieldRef.SetRange(2);
PaymentLineFieldRef := PaymentLineRecordRef.Field(2);
PaymentLineFieldRef.SetRange(DocumentNo);
PaymentLineFieldRef := PaymentLineRecordRef.Field(7);
PaymentLineFieldRef.SetFilter('>%1', 0);
exit(not PaymentLineRecordRef.IsEmpty());
end;

local procedure CreatePurchaseInvoices(var InvoiceID1: Text; var InvoiceID2: Text)
Expand Down Expand Up @@ -546,15 +570,7 @@ codeunit 139729 "APIV1 - Purchase Invoices E2E"
end;

local procedure CreatePaymentTermsWithDiscount(var PaymentTerms: Record "Payment Terms")
var
DateCalculation: DateFormula;
begin
LibraryERM.CreatePaymentTerms(PaymentTerms);
Evaluate(DateCalculation, '1M');
PaymentTerms.Validate("Due Date Calculation", DateCalculation);
Evaluate(DateCalculation, '8D');
PaymentTerms.Validate("Discount Date Calculation", DateCalculation);
PaymentTerms.Validate("Discount %", 2);
PaymentTerms.Modify(true);
LibraryERM.CreatePaymentTermsDiscount(PaymentTerms, true);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
"codeunitName": "APIV1 - Sales Credit Memos E2E",
"method": "TestCreateCreditMemoThroughPageAndAPI"
},
{
"codeunitId": 139729,
"codeunitName": "APIV1 - Purchase Invoices E2E",
"method": "TestPurchaseInvoiceWithPaymentDiscount"
},
{
"codeunitId": 139734,
"codeunitName": "APIV1 - Sales Inv. Lines E2E",
Expand Down
Loading