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
104 changes: 104 additions & 0 deletions src/Layers/BE/Tests/SCM-Manufacturing/SCMManufacturing70.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -3798,6 +3798,110 @@ codeunit 137063 "SCM Manufacturing 7.0"
Assert.AreEqual(SKURoutingHeader."No.", ProdOrderLine."Routing No.", ProductionRoutingErr);
end;

[Test]
[Scope('OnPrem')]
procedure RefreshProdOrderWithoutCalcLinesSkipsHeaderVariantCheck()
var
Item: Record Item;
Item2: Record Item;
Item3: Record Item;
ItemVariant: Record "Item Variant";
ProdOrderComponent: Record "Prod. Order Component";
ProdOrderLine: Record "Prod. Order Line";
ProductionBOMHeader: Record "Production BOM Header";
ProductionOrder: Record "Production Order";
RoutingHeader: Record "Routing Header";
RoutingLine: Record "Routing Line";
WorkCenter: Record "Work Center";
begin
// [SCENARIO 633092] Refreshing a Released Production Order with Calc. Lines = No does not require a header
// Variant Code even when the source item has "Variant Mandatory if Exists" = Yes, because the existing lines
// carry their own variant codes (fashion/apparel pattern with a blank header variant and variant-specific lines).
Initialize();

// [GIVEN] Create Work Center.
CreateWorkCenter(WorkCenter);

// [GIVEN] Create a manufactured Item and its component items.
CreateMultipleItems(
Item, Item2, Item3, Item."Replenishment System"::"Prod. Order", Item3."Replenishment System"::"Prod. Order",
Item."Reordering Policy"::Order, false);
UpdateItem(Item, Item.FieldNo("Manufacturing Policy"), Item."Manufacturing Policy"::"Make-to-Order");

// [GIVEN] Create Production BOM and Routing and assign them to the Item.
LibraryManufacturing.CreateCertifiedProductionBOM(ProductionBOMHeader, Item2."No.", 1);
CreateRoutingWithMultipleRoutingLine(RoutingHeader, WorkCenter."No.", RoutingHeader.Type::Serial, RoutingLine.Type::"Work Center");
UpdateItem(Item, Item.FieldNo("Production BOM No."), ProductionBOMHeader."No.");
UpdateItem(Item, Item.FieldNo("Routing No."), RoutingHeader."No.");

// [GIVEN] A variant exists for the Item and the variant is mandatory.
LibraryInventory.CreateItemVariant(ItemVariant, Item."No.");
UpdateItem(Item, Item.FieldNo("Variant Mandatory if Exists"), Item."Variant Mandatory if Exists"::Yes);

// [GIVEN] Create a Released Production Order for the Item with a blank header Variant Code.
LibraryManufacturing.CreateProductionOrder(
ProductionOrder, ProductionOrder.Status::Released, ProductionOrder."Source Type"::Item, Item."No.", 100);

// [GIVEN] Create a Prod. Order Line carrying the specific Variant Code is added manually.
LibraryManufacturing.CreateProdOrderLine(
ProdOrderLine, ProductionOrder.Status, ProductionOrder."No.", Item."No.", ItemVariant.Code, '', 100);

// [WHEN] Refresh with Calc. Lines = No, Calc. Routings = Yes, Calc. Components = Yes.
LibraryManufacturing.RefreshProdOrder(ProductionOrder, false, false, true, true, false);

// [THEN] Verify no error is raised and components are generated for the variant-specific line.
FindProdOrderComponent(ProdOrderComponent, ProductionOrder, Item2."No.");
Assert.RecordIsNotEmpty(ProdOrderComponent);
end;

[Test]
procedure RefreshProdOrderWithCalcLinesRequiresHeaderVariantCheck()
var
Item: Record Item;
Item2: Record Item;
Item3: Record Item;
ItemVariant: Record "Item Variant";
ProductionBOMHeader: Record "Production BOM Header";
ProductionOrder: Record "Production Order";
RoutingHeader: Record "Routing Header";
RoutingLine: Record "Routing Line";
WorkCenter: Record "Work Center";
begin
// [SCENARIO 633092] Refreshing a Released Production Order with Calc. Lines = Yes still requires a header
// Variant Code when the source item has "Variant Mandatory if Exists" = Yes, because the lines are calculated
// from the header and would otherwise be created without a mandatory variant.
Initialize();

// [GIVEN] Create Work Center.
CreateWorkCenter(WorkCenter);

// [GIVEN] Create a manufactured Item and its component items.
CreateMultipleItems(
Item, Item2, Item3, Item."Replenishment System"::"Prod. Order", Item3."Replenishment System"::"Prod. Order",
Item."Reordering Policy"::Order, false);
UpdateItem(Item, Item.FieldNo("Manufacturing Policy"), Item."Manufacturing Policy"::"Make-to-Order");

// [GIVEN] Create Production BOM and Routing and assign them to the Item.
LibraryManufacturing.CreateCertifiedProductionBOM(ProductionBOMHeader, Item2."No.", 1);
CreateRoutingWithMultipleRoutingLine(RoutingHeader, WorkCenter."No.", RoutingHeader.Type::Serial, RoutingLine.Type::"Work Center");
UpdateItem(Item, Item.FieldNo("Production BOM No."), ProductionBOMHeader."No.");
UpdateItem(Item, Item.FieldNo("Routing No."), RoutingHeader."No.");

// [GIVEN] A variant exists for the Item and the variant is mandatory.
LibraryInventory.CreateItemVariant(ItemVariant, Item."No.");
UpdateItem(Item, Item.FieldNo("Variant Mandatory if Exists"), Item."Variant Mandatory if Exists"::Yes);

// [GIVEN] Create a Released Production Order for the Item with a blank header Variant Code.
LibraryManufacturing.CreateProductionOrder(
ProductionOrder, ProductionOrder.Status::Released, ProductionOrder."Source Type"::Item, Item."No.", 100);

// [WHEN] Refresh with Calc. Lines = Yes, Calc. Routings = Yes, Calc. Components = Yes.
asserterror LibraryManufacturing.RefreshProdOrder(ProductionOrder, false, true, true, true, false);

// [THEN] Verify an error is raised because the mandatory header Variant Code is blank.
Assert.ExpectedTestFieldError(ProductionOrder.FieldCaption("Variant Code"), '');
end;

local procedure Initialize()
var
LibraryERMCountryData: Codeunit "Library - ERM Country Data";
Expand Down
104 changes: 104 additions & 0 deletions src/Layers/IT/Tests/SCM-Manufacturing/SCMManufacturing70.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -3792,6 +3792,110 @@ codeunit 137063 "SCM Manufacturing 7.0"
Assert.AreEqual(SKURoutingHeader."No.", ProdOrderLine."Routing No.", ProductionRoutingErr);
end;

[Test]
[Scope('OnPrem')]
procedure RefreshProdOrderWithoutCalcLinesSkipsHeaderVariantCheck()
var
Item: Record Item;
Item2: Record Item;
Item3: Record Item;
ItemVariant: Record "Item Variant";
ProdOrderComponent: Record "Prod. Order Component";
ProdOrderLine: Record "Prod. Order Line";
ProductionBOMHeader: Record "Production BOM Header";
ProductionOrder: Record "Production Order";
RoutingHeader: Record "Routing Header";
RoutingLine: Record "Routing Line";
WorkCenter: Record "Work Center";
begin
// [SCENARIO 633092] Refreshing a Released Production Order with Calc. Lines = No does not require a header
// Variant Code even when the source item has "Variant Mandatory if Exists" = Yes, because the existing lines
// carry their own variant codes (fashion/apparel pattern with a blank header variant and variant-specific lines).
Initialize();

// [GIVEN] Create Work Center.
CreateWorkCenter(WorkCenter);

// [GIVEN] Create a manufactured Item and its component items.
CreateMultipleItems(
Item, Item2, Item3, Item."Replenishment System"::"Prod. Order", Item3."Replenishment System"::"Prod. Order",
Item."Reordering Policy"::Order, false);
UpdateItem(Item, Item.FieldNo("Manufacturing Policy"), Item."Manufacturing Policy"::"Make-to-Order");

// [GIVEN] Create Production BOM and Routing and assign them to the Item.
LibraryManufacturing.CreateCertifiedProductionBOM(ProductionBOMHeader, Item2."No.", 1);
CreateRoutingWithMultipleRoutingLine(RoutingHeader, WorkCenter."No.", RoutingHeader.Type::Serial, RoutingLine.Type::"Work Center");
UpdateItem(Item, Item.FieldNo("Production BOM No."), ProductionBOMHeader."No.");
UpdateItem(Item, Item.FieldNo("Routing No."), RoutingHeader."No.");

// [GIVEN] A variant exists for the Item and the variant is mandatory.
LibraryInventory.CreateItemVariant(ItemVariant, Item."No.");
UpdateItem(Item, Item.FieldNo("Variant Mandatory if Exists"), Item."Variant Mandatory if Exists"::Yes);

// [GIVEN] Create a Released Production Order for the Item with a blank header Variant Code.
LibraryManufacturing.CreateProductionOrder(
ProductionOrder, ProductionOrder.Status::Released, ProductionOrder."Source Type"::Item, Item."No.", 100);

// [GIVEN] Create a Prod. Order Line carrying the specific Variant Code is added manually.
LibraryManufacturing.CreateProdOrderLine(
ProdOrderLine, ProductionOrder.Status, ProductionOrder."No.", Item."No.", ItemVariant.Code, '', 100);

// [WHEN] Refresh with Calc. Lines = No, Calc. Routings = Yes, Calc. Components = Yes.
LibraryManufacturing.RefreshProdOrder(ProductionOrder, false, false, true, true, false);

// [THEN] Verify no error is raised and components are generated for the variant-specific line.
FindProdOrderComponent(ProdOrderComponent, ProductionOrder, Item2."No.");
Assert.RecordIsNotEmpty(ProdOrderComponent);
end;

[Test]
procedure RefreshProdOrderWithCalcLinesRequiresHeaderVariantCheck()
var
Item: Record Item;
Item2: Record Item;
Item3: Record Item;
ItemVariant: Record "Item Variant";
ProductionBOMHeader: Record "Production BOM Header";
ProductionOrder: Record "Production Order";
RoutingHeader: Record "Routing Header";
RoutingLine: Record "Routing Line";
WorkCenter: Record "Work Center";
begin
// [SCENARIO 633092] Refreshing a Released Production Order with Calc. Lines = Yes still requires a header
// Variant Code when the source item has "Variant Mandatory if Exists" = Yes, because the lines are calculated
// from the header and would otherwise be created without a mandatory variant.
Initialize();

// [GIVEN] Create Work Center.
CreateWorkCenter(WorkCenter);

// [GIVEN] Create a manufactured Item and its component items.
CreateMultipleItems(
Item, Item2, Item3, Item."Replenishment System"::"Prod. Order", Item3."Replenishment System"::"Prod. Order",
Item."Reordering Policy"::Order, false);
UpdateItem(Item, Item.FieldNo("Manufacturing Policy"), Item."Manufacturing Policy"::"Make-to-Order");

// [GIVEN] Create Production BOM and Routing and assign them to the Item.
LibraryManufacturing.CreateCertifiedProductionBOM(ProductionBOMHeader, Item2."No.", 1);
CreateRoutingWithMultipleRoutingLine(RoutingHeader, WorkCenter."No.", RoutingHeader.Type::Serial, RoutingLine.Type::"Work Center");
UpdateItem(Item, Item.FieldNo("Production BOM No."), ProductionBOMHeader."No.");
UpdateItem(Item, Item.FieldNo("Routing No."), RoutingHeader."No.");

// [GIVEN] A variant exists for the Item and the variant is mandatory.
LibraryInventory.CreateItemVariant(ItemVariant, Item."No.");
UpdateItem(Item, Item.FieldNo("Variant Mandatory if Exists"), Item."Variant Mandatory if Exists"::Yes);

// [GIVEN] Create a Released Production Order for the Item with a blank header Variant Code.
LibraryManufacturing.CreateProductionOrder(
ProductionOrder, ProductionOrder.Status::Released, ProductionOrder."Source Type"::Item, Item."No.", 100);

// [WHEN] Refresh with Calc. Lines = Yes, Calc. Routings = Yes, Calc. Components = Yes.
asserterror LibraryManufacturing.RefreshProdOrder(ProductionOrder, false, true, true, true, false);

// [THEN] Verify an error is raised because the mandatory header Variant Code is blank.
Assert.ExpectedTestFieldError(ProductionOrder.FieldCaption("Variant Code"), '');
end;

local procedure Initialize()
var
LibraryERMCountryData: Codeunit "Library - ERM Country Data";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ report 99001025 "Refresh Production Order"
CurrReport.Skip();

TestField("Due Date");
CheckVariantCodeMandatory("Production Order");

if CalcLines then
if IsComponentPicked("Production Order") then begin
Expand Down Expand Up @@ -400,6 +401,23 @@ report 99001025 "Refresh Production Order"
exit(not ProdOrderComponent.IsEmpty());
end;

local procedure CheckVariantCodeMandatory(var ProductionOrder: Record "Production Order")
var
Item: Record Item;
IsHandled: Boolean;
begin
if not CalcLines then
exit;
if ProductionOrder."Source Type" <> ProductionOrder."Source Type"::Item then
exit;
if Item.IsVariantMandatory(true, ProductionOrder."Source No.") then begin
IsHandled := false;
OnBeforeCheckVariantCodeMandatory(ProductionOrder, IsHandled);
if not IsHandled then
ProductionOrder.TestField("Variant Code");
end;
end;

local procedure GetRoutingNo(ProductionOrder: Record "Production Order") RoutingNo: Code[20]
var
Item: Record Item;
Expand Down Expand Up @@ -480,6 +498,11 @@ report 99001025 "Refresh Production Order"
begin
end;

[IntegrationEvent(false, false)]
local procedure OnBeforeCheckVariantCodeMandatory(var ProductionOrder: Record "Production Order"; var IsHandled: Boolean)
begin
end;

[IntegrationEvent(false, false)]
local procedure OnProductionOrderOnAfterGetRecordOnAfterCalcRoutingsOrComponents(var ProductionOrder: Record "Production Order"; CalcLines: Boolean; CalcRoutings: Boolean; CalcComponents: Boolean; var ErrorOccured: Boolean)
begin
Expand Down
Loading
Loading