Skip to content
Merged
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 @@ -19,9 +19,6 @@ codeunit 99001519 "Subc. Work Center Extension"
if not RunTrigger then
exit;

SubcontractorPrice.SetCurrentKey("Work Center No.");
SubcontractorPrice.SetRange("Work Center No.", Rec."No.");
if not SubcontractorPrice.IsEmpty() then
SubcontractorPrice.DeleteAll(true);
SubcontractorPrice.DeletePricesForWorkCenter(Rec."No.");
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,15 @@ codeunit 99001532 "Subc. Item Extension"
{
[EventSubscriber(ObjectType::Table, Database::Item, OnAfterDeleteEvent, '', false, false)]
local procedure OnAfterDeleteItem(var Rec: Record Item; RunTrigger: Boolean)
var
SubcontractorPrice: Record "Subcontractor Price";
begin
if Rec.IsTemporary() then
exit;

if not RunTrigger then
exit;

DeleteRelatedSubcontractorPrices(Rec);
end;

local procedure DeleteRelatedSubcontractorPrices(var Item: Record Item)
var
SubcontractorPrice: Record "Subcontractor Price";
begin
SubcontractorPrice.SetCurrentKey("Item No.");
SubcontractorPrice.SetRange("Item No.", Item."No.");
if not SubcontractorPrice.IsEmpty() then
SubcontractorPrice.DeleteAll(true);
SubcontractorPrice.DeletePricesForItem(Rec."No.");
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ codeunit 99001531 "Subc. Vendor Extension"
if not RunTrigger then
exit;

SubcontractorPrice.SetCurrentKey("Vendor No.");
SubcontractorPrice.SetRange("Vendor No.", Rec."No.");
if not SubcontractorPrice.IsEmpty() then
SubcontractorPrice.DeleteAll(true);
SubcontractorPrice.DeletePricesForVendor(Rec."No.");
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ table 99001500 "Subcontractor Price"
key(Key02; "Vendor No.", "Item No.", "Work Center No.", "Variant Code", "Unit of Measure Code", "Currency Code")
{
}
key(Key03; "Work Center No.")
{
}
key(Key04; "Item No.")
{
}
}
fieldgroups
{
Expand Down Expand Up @@ -162,4 +168,28 @@ table 99001500 "Subcontractor Price"
until SubcontractorPrice.Next() = 0;
end;

internal procedure DeletePricesForVendor(VendorNo: Code[20])
begin
SetCurrentKey("Vendor No.");
SetRange("Vendor No.", VendorNo);
if not IsEmpty() then
DeleteAll(true);
end;

internal procedure DeletePricesForWorkCenter(WorkCenterNo: Code[20])
begin
SetCurrentKey("Work Center No.");
SetRange("Work Center No.", WorkCenterNo);
if not IsEmpty() then
DeleteAll(true);
end;

internal procedure DeletePricesForItem(ItemNo: Code[20])
begin
SetCurrentKey("Item No.");
SetRange("Item No.", ItemNo);
if not IsEmpty() then
DeleteAll(true);
end;

}
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,64 @@ Comment = '|%1 = Transfer Order No.';
Assert.AreEqual(SubPurchaseLineFactbox.SubcontractingPrices.Value, Format(SubcontractorPrice.Count()), '');
end;

[Test]
[Scope('OnPrem')]
procedure DeleteWorkCenterWithPricesDeletesRelatedPrices()
var
Item: Record Item;
SubcontractorPrice: Record "Subcontractor Price";
WorkCenter: Record "Work Center";
WorkCenterNo: Code[20];
begin
// [SCENARIO 620643] Deleting a Work Center deletes all associated Subcontractor Prices

// [GIVEN] A work center with a subcontractor and multiple Subcontractor Prices
Initialize();
LibraryMfgManagement.CreateWorkCenterWithCalendar(WorkCenter, 0);
WorkCenter.Validate("Subcontractor No.", LibraryMfgManagement.CreateSubcontractorWithCurrency(''));
WorkCenter.Modify(true);
LibraryInventory.CreateItem(Item);
WorkCenterNo := WorkCenter."No.";
SubcontractingMgmtLibrary.CreateSubContractingPrice(SubcontractorPrice, WorkCenterNo, WorkCenter."Subcontractor No.", Item."No.", '', '', WorkDate(), '', 0, '');
SubcontractingMgmtLibrary.CreateSubContractingPrice(SubcontractorPrice, WorkCenterNo, WorkCenter."Subcontractor No.", Item."No.", '', '', WorkDate(), '', 10, '');

// [WHEN] The work center is deleted
WorkCenter.Delete(true);

// [THEN] All Subcontractor Prices for the work center are deleted
SubcontractorPrice.SetRange("Work Center No.", WorkCenterNo);
Assert.IsTrue(SubcontractorPrice.IsEmpty(), 'Subcontractor prices must be deleted when work center is deleted');
end;

[Test]
[Scope('OnPrem')]
procedure DeleteItemWithPricesDeletesRelatedPrices()
var
Item: Record Item;
SubcontractorPrice: Record "Subcontractor Price";
WorkCenter: Record "Work Center";
ItemNo: Code[20];
begin
// [SCENARIO 620643] Deleting an Item deletes all associated Subcontractor Prices

// [GIVEN] An item with multiple Subcontractor Prices
Initialize();
LibraryMfgManagement.CreateWorkCenterWithCalendar(WorkCenter, 0);
WorkCenter.Validate("Subcontractor No.", LibraryMfgManagement.CreateSubcontractorWithCurrency(''));
WorkCenter.Modify(true);
LibraryInventory.CreateItem(Item);
ItemNo := Item."No.";
SubcontractingMgmtLibrary.CreateSubContractingPrice(SubcontractorPrice, WorkCenter."No.", WorkCenter."Subcontractor No.", ItemNo, '', '', WorkDate(), '', 0, '');
SubcontractingMgmtLibrary.CreateSubContractingPrice(SubcontractorPrice, WorkCenter."No.", WorkCenter."Subcontractor No.", ItemNo, '', '', WorkDate(), '', 10, '');

// [WHEN] The item is deleted
Item.Delete(true);

// [THEN] All Subcontractor Prices for the item are deleted
SubcontractorPrice.SetRange("Item No.", ItemNo);
Assert.IsTrue(SubcontractorPrice.IsEmpty(), 'Subcontractor prices must be deleted when item is deleted');
end;

[Test]
[HandlerFunctions('DoNotConfirmShowCreatedPurchOrderForSubcontracting,SubcontrDispatchingListDefaultRequestPageHandler')]
procedure TestSubcontrDispatchingList()
Expand Down
Loading