Skip to content
Open
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 @@ -196,10 +196,10 @@ codeunit 5522 "Order Planning Mgt."
OnInsertDemandLinesOnAfterReqLineInsert(ReqLine, TempUnplannedDemand);
if Item."No." <> TempUnplannedDemand."Item No." then
Item.Get(TempUnplannedDemand."Item No.");
if Item."Item Tracking Code" <> '' then
OnInsertDemandLinesOnCopyItemTracking(ReqLine, TempUnplannedDemand);
if ReqLine.Quantity > 0 then
PlanningLineMgt.Calculate(ReqLine, 1, true, true, 0);
if Item."Item Tracking Code" <> '' then
OnInsertDemandLinesOnCopyItemTracking(ReqLine, TempUnplannedDemand);
ReqLine.Find('+');
end;

Expand Down
44 changes: 44 additions & 0 deletions src/Layers/W1/Tests/SCM-Planning/SCMOrderPlanningIII.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ codeunit 137088 "SCM Order Planning - III"
NotificationLifecycleMgt: Codeunit "Notification Lifecycle Mgt.";
LibraryVariableStorage: Codeunit "Library - Variable Storage";
LibraryRandom: Codeunit "Library - Random";
LibraryItemTracking: Codeunit "Library - Item Tracking";
VerifyOnGlobal: Option RequisitionLine,Orders;
DemandTypeGlobal: Option Sales,Production;
GlobalChildItemNo: Code[20];
Expand Down Expand Up @@ -3777,6 +3778,49 @@ codeunit 137088 "SCM Order Planning - III"
Assert.AreEqual(200, ReqLine.Quantity, RequisitionLineQuantityMismatchErr);
end;

[Test]
procedure CreatePurchaseOrderFromDropShipmentSalesOrderWithLotTracking()
var
Item: Record Item;
Location: Record Location;
Purchasing: Record Purchasing;
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
ReservationEntry: Record "Reservation Entry";
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
LotNo: Code[50];
Quantity: Decimal;
begin
// [SCENARIO 647806] Create a purchase order from a drop shipment sales order with lot tracking.
Initialize();
LotNo := LibraryUtility.GenerateGUID();
Quantity := LibraryRandom.RandInt(10);

// [GIVEN] A lot-tracked item with a vendor and a drop shipment sales order line with item tracking.
LibraryItemTracking.CreateLotItem(Item);
Item.Validate("Vendor No.", LibraryPurchase.CreateVendorNo());
Item.Modify(true);
LibraryWarehouse.CreateLocation(Location);
LibraryPurchase.CreateDropShipmentPurchasingCode(Purchasing);
CreateSalesOrderWithPurchasingCode(SalesHeader, SalesLine, Item."No.", Purchasing.Code);
SalesLine.Validate("Location Code", Location.Code);
SalesLine.Validate(Quantity, Quantity);
SalesLine.Modify(true);
LibraryItemTracking.CreateSalesOrderItemTracking(ReservationEntry, SalesLine, '', LotNo, Quantity);

// [WHEN] Create a purchase order from the sales order.
CreatePurchaseOrderFromSalesOrder(SalesHeader."No.", true);

// [THEN] The purchase order is created with the lot tracking from the sales line.
FindPurchaseDocumentByItemNo(PurchaseHeader, PurchaseLine, Item."No.");
ReservationEntry.SetSourceFilter(
Database::"Purchase Line", PurchaseLine."Document Type".AsInteger(), PurchaseLine."Document No.", PurchaseLine."Line No.", true);
ReservationEntry.SetSourceFilter('', 0);
ReservationEntry.SetRange("Lot No.", LotNo);
Assert.RecordIsNotEmpty(ReservationEntry);
end;

local procedure Initialize()
var
LibraryERMCountryData: Codeunit "Library - ERM Country Data";
Expand Down
Loading