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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ------------------------------------------------------------------------------------------------
namespace Microsoft.Manufacturing.Subcontracting;

using Microsoft.Inventory.Item;
using Microsoft.Inventory.Location;
using Microsoft.Inventory.Planning;
using Microsoft.Warehouse.Structure;
Expand All @@ -20,8 +21,14 @@ tableextension 99001503 "Subc. Planning Comp Ext." extends "Planning Component"
ToolTip = 'Specifies the Type of Subcontracting that is assigned to the Planning Component.';
trigger OnValidate()
var
Item: Record Item;
SubcontractingManagement: Codeunit "Subcontracting Management";
begin
if "Subcontracting Type" = "Subcontracting Type"::Transfer then
if "Item No." <> '' then begin
Item.Get("Item No.");
Item.TestField(Type, Item.Type::Inventory);
end;
SubcontractingManagement.UpdateSubcontractingTypeForPlanningComponent(Rec);
end;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ------------------------------------------------------------------------------------------------
namespace Microsoft.Manufacturing.Subcontracting;

using Microsoft.Inventory.Item;
using Microsoft.Manufacturing.ProductionBOM;

tableextension 99001531 "Subc. Prod BOM Line Ext." extends "Production BOM Line"
Expand All @@ -16,6 +17,16 @@ tableextension 99001531 "Subc. Prod BOM Line Ext." extends "Production BOM Line"
Caption = 'Subcontracting Type';
DataClassification = CustomerContent;
ToolTip = 'Specifies the Type of Subcontracting that is assigned to the Production BOM Line.';
trigger OnValidate()
var
Item: Record Item;
begin
if "Subcontracting Type" = "Subcontracting Type"::Transfer then
if (Type = Type::Item) and ("No." <> '') then begin
Item.Get("No.");
Item.TestField(Type, Item.Type::Inventory);
end;
end;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ------------------------------------------------------------------------------------------------
namespace Microsoft.Manufacturing.Subcontracting;

using Microsoft.Inventory.Item;
using Microsoft.Inventory.Ledger;
using Microsoft.Inventory.Location;
using Microsoft.Inventory.Transfer;
Expand All @@ -23,8 +24,14 @@ tableextension 99001502 "Subc. Prod Order Comp Ext." extends "Prod. Order Compon
ToolTip = 'Specifies the Type of Subcontracting that is assigned to the Production Order Component.';
trigger OnValidate()
var
Item: Record Item;
SubcontractingManagement: Codeunit "Subcontracting Management";
begin
if "Subcontracting Type" = "Subcontracting Type"::Transfer then
if "Item No." <> '' then begin
Item.Get("Item No.");
Item.TestField(Type, Item.Type::Inventory);
end;
SubcontractingManagement.UpdateSubcontractingTypeForProdOrderComponent(Rec);
end;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace Microsoft.Manufacturing.Subcontracting.Test;

using Microsoft.Inventory.Item;
using Microsoft.Manufacturing.Document;
using Microsoft.Manufacturing.ProductionBOM;
using Microsoft.Manufacturing.Subcontracting;

codeunit 149916 "Subc. Non-Inv Item Valid. Test"
{
// [FEATURE] Subcontracting Type Transfer validation for Non-Inventory items
Subtype = Test;
TestPermissions = Disabled;

[Test]
procedure NonInventoryItemCannotBeSetToTransferOnProdBOMLine()
var
ProductionBOMHeader: Record "Production BOM Header";
ProductionBOMLine: Record "Production BOM Line";
Item: Record Item;
begin
// [SCENARIO 624295] Setting Subcontracting Type = Transfer on a Production BOM Line with a Non-Inventory item must raise an error.

// [GIVEN] A Non-Inventory item and a Production BOM with a line for that item
CreateNonInventoryItem(Item);
CreateProductionBOMWithItem(ProductionBOMHeader, ProductionBOMLine, Item);

// [WHEN] Setting Subcontracting Type to Transfer on the BOM line
asserterror ProductionBOMLine.Validate("Subcontracting Type", "Subcontracting Type"::Transfer);

// [THEN] An error is raised indicating the item type must be Inventory
Assert.ExpectedErrorCode('TestField');
Assert.ExpectedError('Type must be equal to');
end;

[Test]
procedure InventoryItemCanBeSetToTransferOnProdBOMLine()
var
ProductionBOMHeader: Record "Production BOM Header";
ProductionBOMLine: Record "Production BOM Line";
Item: Record Item;
begin
// [SCENARIO 624295] Setting Subcontracting Type = Transfer on a Production BOM Line with an Inventory item must succeed.

// [GIVEN] An Inventory item and a Production BOM with a line for that item
CreateInventoryItem(Item);
CreateProductionBOMWithItem(ProductionBOMHeader, ProductionBOMLine, Item);

// [WHEN] Setting Subcontracting Type to Transfer on the BOM line
ProductionBOMLine.Validate("Subcontracting Type", "Subcontracting Type"::Transfer);

// [THEN] No error is raised
Assert.AreEqual("Subcontracting Type"::Transfer, ProductionBOMLine."Subcontracting Type", 'Subcontracting Type should be Transfer');
end;

[Test]
procedure NonInventoryItemCannotBeSetToTransferOnProdOrderComponent()
var
ProdOrderComponent: Record "Prod. Order Component";
Item: Record Item;
begin
// [SCENARIO 624295] Setting Subcontracting Type = Transfer on a Prod. Order Component with a Non-Inventory item must raise an error.

// [GIVEN] A Non-Inventory item and a Prod. Order Component for that item
CreateNonInventoryItem(Item);
CreateProdOrderComponent(ProdOrderComponent, Item);

// [WHEN] Setting Subcontracting Type to Transfer on the component
asserterror ProdOrderComponent.Validate("Subcontracting Type", "Subcontracting Type"::Transfer);

// [THEN] An error is raised indicating the item type must be Inventory
Assert.ExpectedErrorCode('TestField');
Assert.ExpectedError('Type must be equal to');
end;

[Test]
procedure NonInventoryItemCanBeSetToPurchaseOnProdBOMLine()
var
ProductionBOMHeader: Record "Production BOM Header";
ProductionBOMLine: Record "Production BOM Line";
Item: Record Item;
begin
// [SCENARIO 624295] Setting Subcontracting Type = Purchase on a Production BOM Line with a Non-Inventory item must succeed (only Transfer is blocked).

// [GIVEN] A Non-Inventory item and a Production BOM with a line for that item
CreateNonInventoryItem(Item);
CreateProductionBOMWithItem(ProductionBOMHeader, ProductionBOMLine, Item);

// [WHEN] Setting Subcontracting Type to Purchase on the BOM line
ProductionBOMLine.Validate("Subcontracting Type", "Subcontracting Type"::Purchase);

// [THEN] No error is raised
Assert.AreEqual("Subcontracting Type"::Purchase, ProductionBOMLine."Subcontracting Type", 'Subcontracting Type should be Purchase');
end;

local procedure CreateNonInventoryItem(var Item: Record Item)
begin
LibraryInventory.CreateItem(Item);
Item.Validate(Type, Item.Type::"Non-Inventory");
Item.Modify(true);
end;

local procedure CreateInventoryItem(var Item: Record Item)
begin
LibraryInventory.CreateItem(Item);
end;

local procedure CreateProductionBOMWithItem(var ProductionBOMHeader: Record "Production BOM Header"; var ProductionBOMLine: Record "Production BOM Line"; Item: Record Item)
begin
LibraryManufacturing.CreateProductionBOMHeader(ProductionBOMHeader, Item."Base Unit of Measure");
LibraryManufacturing.CreateProductionBOMLine(ProductionBOMHeader, ProductionBOMLine, '', ProductionBOMLine.Type::Item, Item."No.", 1);
end;

local procedure CreateProdOrderComponent(var ProdOrderComponent: Record "Prod. Order Component"; Item: Record Item)
var
ProductionOrder: Record "Production Order";
ProductionOrderLine: Record "Prod. Order Line";
ParentItem: Record Item;
begin
LibraryInventory.CreateItem(ParentItem);
LibraryManufacturing.CreateProductionOrder(
ProductionOrder, "Production Order Status"::Released, ProductionOrder."Source Type"::Item, ParentItem."No.", 1);
LibraryManufacturing.CreateProdOrderLine(ProductionOrderLine, ProductionOrder.Status, ProductionOrder."No.", ParentItem."No.", '', '', 1);

ProdOrderComponent.Init();
ProdOrderComponent.Status := ProductionOrder.Status;
ProdOrderComponent."Prod. Order No." := ProductionOrder."No.";
ProdOrderComponent."Prod. Order Line No." := ProductionOrderLine."Line No.";
ProdOrderComponent."Line No." := 10000;
ProdOrderComponent.Validate("Item No.", Item."No.");
ProdOrderComponent.Insert(true);
end;

var
Assert: Codeunit Assert;
LibraryInventory: Codeunit "Library - Inventory";
LibraryManufacturing: Codeunit "Library - Manufacturing";
}
Loading