Skip to content
Draft
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
3 changes: 3 additions & 0 deletions src/Apps/W1/APIV1/test/src/APIV1ItemVariantsE2E.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ codeunit 139739 "APIV1 - Item Variants E2E"

var
LibraryGraphMgt: Codeunit "Library - Graph Mgt";
LibraryGraphDocumentTools: Codeunit "Library - Graph Document Tools";
LibraryUtility: Codeunit "Library - Utility";
LibraryRandom: Codeunit "Library - Random";
LibraryInventory: Codeunit "Library - Inventory";
Expand Down Expand Up @@ -459,6 +460,8 @@ codeunit 139739 "APIV1 - Item Variants E2E"
LibrarySales: Codeunit "Library - Sales";
begin
LibrarySales.CreateSalesOrder(SalesHeader);
LibraryGraphDocumentTools.EnsureVATPostingSetupExists(
SalesHeader."VAT Bus. Posting Group", Item."VAT Prod. Posting Group");
LibrarySales.CreateSalesLine(SalesLine, SalesHeader, SalesLine.Type::Item, Item."No.", 2);
SalesLine."Variant Code" := ItemVariant.Code;
SalesLine.Modify();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,8 @@ codeunit 139734 "APIV1 - Sales Inv. Lines E2E"
Assert.AreNotEqual('', InvoiceLineID, 'ID should not be empty');
LineNo := SalesLine."Line No.";
LibraryInventory.CreateItem(Item);
LibraryGraphDocumentTools.EnsureVATPostingSetupExists(
SalesLine."VAT Bus. Posting Group", Item."VAT Prod. Posting Group");

InvoiceLineJSON := STRSUBSTNO('{"itemId":"%1"}', LibraryGraphMgt.StripBrackets(Format(Item.SystemId)));
COMMIT();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ codeunit 139735 "APIV1 - Sales Order Lines E2E"

Assert.AreNotEqual('', OrderId, 'ID should not be empty');
LibraryInventory.CreateItem(Item);
LibraryGraphDocumentTools.EnsureVATPostingSetupExists(
SalesLine."VAT Bus. Posting Group", Item."VAT Prod. Posting Group");

OrderLineJSON := STRSUBSTNO('{"itemId":"%1"}', LibraryGraphMgt.StripBrackets(Format(Item.SystemId)));
COMMIT();
Expand Down
3 changes: 3 additions & 0 deletions src/Apps/W1/APIV2/test/src/APIV2ItemVariantsE2E.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ codeunit 139839 "APIV2 - Item Variants E2E"

var
LibraryGraphMgt: Codeunit "Library - Graph Mgt";
LibraryGraphDocumentTools: Codeunit "Library - Graph Document Tools";
LibraryUtility: Codeunit "Library - Utility";
LibraryRandom: Codeunit "Library - Random";
LibraryInventory: Codeunit "Library - Inventory";
Expand Down Expand Up @@ -452,6 +453,8 @@ codeunit 139839 "APIV2 - Item Variants E2E"
LibrarySales: Codeunit "Library - Sales";
begin
LibrarySales.CreateSalesOrder(SalesHeader);
LibraryGraphDocumentTools.EnsureVATPostingSetupExists(
SalesHeader."VAT Bus. Posting Group", Item."VAT Prod. Posting Group");
LibrarySales.CreateSalesLine(SalesLine, SalesHeader, SalesLine.Type::Item, Item."No.", 2);
SalesLine."Variant Code" := ItemVariant.Code;
SalesLine.Modify();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ codeunit 139852 "APIV2 - Purch. Order Lines E2E"

Assert.AreNotEqual('', OrderId, 'ID should not be empty');
LibraryInventory.CreateItem(Item);
LibraryGraphDocumentTools.EnsureVATPostingSetupExists(
PurchaseLine."VAT Bus. Posting Group", Item."VAT Prod. Posting Group");

OrderLineJSON := StrSubstNo('{"itemId":"%1"}', LibraryGraphMgt.StripBrackets(Item.SystemId));
Commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,8 @@ codeunit 139834 "APIV2 - Sales Inv. Lines E2E"

Assert.AreNotEqual('', InvoiceLineID, 'ID should not be empty');
LibraryInventory.CreateItem(Item);
LibraryGraphDocumentTools.EnsureVATPostingSetupExists(
SalesLine."VAT Bus. Posting Group", Item."VAT Prod. Posting Group");

InvoiceLineJSON := StrSubstNo('{"itemId":"%1"}', LibraryGraphMgt.StripBrackets(Item.SystemId));
Commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,8 @@ codeunit 139835 "APIV2 - Sales Order Lines E2E"

Assert.AreNotEqual('', OrderId, 'ID should not be empty');
LibraryInventory.CreateItem(Item);
LibraryGraphDocumentTools.EnsureVATPostingSetupExists(
SalesLine."VAT Bus. Posting Group", Item."VAT Prod. Posting Group");

OrderLineJSON := StrSubstNo('{"itemId":"%1"}', LibraryGraphMgt.StripBrackets(Item.SystemId));
Commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,6 @@
"codeunitName": "APIV1 - Purchase Invoices E2E",
"method": "TestPurchaseInvoiceWithPaymentDiscount"
},
{
"codeunitId": 139734,
"codeunitName": "APIV1 - Sales Inv. Lines E2E",
"method": "TestGettingLinesWithDifferentTypes"
},
{
"codeunitId": 139734,
"codeunitName": "APIV1 - Sales Inv. Lines E2E",
"method": "TestPatchingTheIdToItemChangesLineType"
},
{
"codeunitId": 139735,
"codeunitName": "APIV1 - Sales Order Lines E2E",
"method": "TestGettingLinesWithDifferentTypes"
},
{
"codeunitId": 139735,
"codeunitName": "APIV1 - Sales Order Lines E2E",
"method": "TestPatchingTheIdToItemChangesLineType"
},
{
"codeunitId": 139739,
"codeunitName": "APIV1 - Item Variants E2E",
"method": "TestDeleteInUse"
},
{
"codeunitId": 139734,
"codeunitName": "APIV1 - Sales Inv. Lines E2E",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,6 @@
"codeunitName": "APIV2 - Sales Credit Memos E2E",
"method": "TestCreateCreditMemoThroughPageAndAPI"
},
{
"codeunitId": 139834,
"codeunitName": "APIV2 - Sales Inv. Lines E2E",
"method": "TestGettingLinesWithDifferentTypes"
},
{
"codeunitId": 139834,
"codeunitName": "APIV2 - Sales Inv. Lines E2E",
"method": "TestPatchingTheIdToItemChangesLineType"
},
{
"codeunitId": 139835,
"codeunitName": "APIV2 - Sales Order Lines E2E",
"method": "TestGettingLinesWithDifferentTypes"
},
{
"codeunitId": 139835,
"codeunitName": "APIV2 - Sales Order Lines E2E",
"method": "TestPatchingTheIdToItemChangesLineType"
},
{
"codeunitId": 139839,
"codeunitName": "APIV2 - Item Variants E2E",
"method": "TestDeleteInUse"
},
{
"codeunitId": 139843,
"codeunitName": "APIV2 - Vendor Payments E2E",
Expand All @@ -89,16 +64,6 @@
"codeunitName": "APIV2 - Purchase Orders E2E",
"method": "TestCreateOrderThroughPageAndAPI"
},
{
"codeunitId": 139852,
"codeunitName": "APIV2 - Purch. Order Lines E2E",
"method": "TestGettingLinesWithDifferentTypes"
},
{
"codeunitId": 139852,
"codeunitName": "APIV2 - Purch. Order Lines E2E",
"method": "TestPatchingTheIdToItemChangesLineType"
},
{
"codeunitId": 139865,
"codeunitName": "APIV2 - Purch. Cr. Memos E2E",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,17 +578,16 @@ codeunit 130619 "Library - Graph Document Tools"
VATBusinessPostingGroup: Record "VAT Business Posting Group";
FixedAsset: Record "Fixed Asset";
GLAccount: Record "G/L Account";
VATPostingSetup: Record "VAT Posting Setup";
begin
LibraryInventory.CreateItemCharge(ItemCharge);
EnsureVATPostingSetupExists(
SalesHeader."VAT Bus. Posting Group", ItemCharge."VAT Prod. Posting Group");
LibrarySales.CreateSalesLine(SalesLineCharge, SalesHeader, SalesLineCharge.Type::"Charge (Item)", ItemCharge."No.", 1);

LibraryERM.FindVATBusinessPostingGroup(VATBusinessPostingGroup);
LibraryResource.CreateResource(Resource, VATBusinessPostingGroup.Code);
VATPostingSetup.SetRange("VAT Bus. Posting Group", SalesHeader."VAT Bus. Posting Group");
VATPostingSetup.SetRange("VAT Prod. Posting Group", Resource."VAT Prod. Posting Group");
if not VATPostingSetup.FINDFIRST() then
LibraryERM.CreateVATPostingSetup(VATPostingSetup, SalesHeader."VAT Bus. Posting Group", Resource."VAT Prod. Posting Group");
EnsureVATPostingSetupExists(
SalesHeader."VAT Bus. Posting Group", Resource."VAT Prod. Posting Group");
LibrarySales.CreateSalesLine(SalesLineResource, SalesHeader, SalesLineResource.Type::Resource, Resource."No.", 1);

LibraryFixedAsset.CreateFixedAsset(FixedAsset);
Expand All @@ -615,6 +614,8 @@ codeunit 130619 "Library - Graph Document Tools"
GLAccount: Record "G/L Account";
begin
LibraryInventory.CreateItemCharge(ItemCharge);
EnsureVATPostingSetupExists(
PurchaseHeader."VAT Bus. Posting Group", ItemCharge."VAT Prod. Posting Group");
LibraryPurchase.CreatePurchaseLine(
PurchaseLineCharge, PurchaseHeader, PurchaseLineCharge.Type::"Charge (Item)", ItemCharge."No.", 1);

Expand All @@ -632,10 +633,27 @@ codeunit 130619 "Library - Graph Document Tools"
GLAccount.SetRange("Direct Posting", true);
#pragma warning restore AA0210
GLAccount.FindFirst();
EnsureVATPostingSetupExists(
PurchaseHeader."VAT Bus. Posting Group", GLAccount."VAT Prod. Posting Group");
LibraryPurchase.CreatePurchaseLine(
PurchaseLineGLAccount, PurchaseHeader, PurchaseLineGLAccount.Type::"G/L Account", GLAccount."No.", 1);
end;

/// <summary>Creates VAT posting setup when the specified posting-group combination does not exist.</summary>
/// <param name="VATBusPostingGroup">VAT business posting group.</param>
/// <param name="VATProdPostingGroup">VAT product posting group.</param>
procedure EnsureVATPostingSetupExists(VATBusPostingGroup: Code[20]; VATProdPostingGroup: Code[20])

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\ —\ Breaking\ Changes}$

The new EnsureVATPostingSetupExists helper has no access modifier or Scope attribute, so it becomes a public API available beyond the test-library boundary even though it is an implementation helper. Restrict it to the existing OnPrem-scoped test-library surface, or otherwise use the narrowest access that supports its callers.

Suggested fix (apply manually — could not be anchored as a one-click suggestion):

[Scope('OnPrem')]
    procedure EnsureVATPostingSetupExists(VATBusPostingGroup: Code[20]; VATProdPostingGroup: Code[20])

Knowledge:

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

var
VATPostingSetup: Record "VAT Posting Setup";
begin
if (VATBusPostingGroup = '') and (VATProdPostingGroup = '') then
exit;
if VATPostingSetup.Get(VATBusPostingGroup, VATProdPostingGroup) then

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\ —\ Error\ Handling}$

This helper must continue to create the VAT posting setup when the combination is missing, but the bare Record.Get raises a runtime error instead of returning false. Consume the Boolean result with an existence check so the CreateVATPostingSetup call can run when no setup exists.

Suggested fix (apply manually — could not be anchored as a one-click suggestion):

if not VATPostingSetup.Get(VATBusPostingGroup, VATProdPostingGroup) then
    LibraryERM.CreateVATPostingSetup(VATPostingSetup, VATBusPostingGroup, VATProdPostingGroup);

Knowledge:

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

exit;

LibraryERM.CreateVATPostingSetup(VATPostingSetup, VATBusPostingGroup, VATProdPostingGroup);
end;

[Scope('OnPrem')]
procedure VerifySalesObjectTxtDescription(SalesLine: Record "Sales Line"; JObjectTxt: Text)
var
Expand Down
Loading