CRM0110 Create receipt Store Orders for returning of products

Basic Information

Module Crm.Sales
Code CRM0110
Parent Document SalesOrder
Sub-document StoreOrder
Full Name Create receipt Store orders for returning of products
Status NEW
Deterministic/Non-deterministic Deterministic
Transitional Documents YES
Replace Generation Procedures GenerateStoreOrdersForSalesReturnV2
Processing Orphan Rows Ignore
Introduced In Version
Date of Suspension

Business Logic

The generation procedure is used for creating of Store Orders which have to "inform" the Inventory module for goods receipt, which goods are returned by Sales Orders. The Store Orders generations directly from the Sales Order is necessary as the returned goods are not shipped and no Shipment Order have to be created (even for shippable products), so the Shipment Order cannot be expected to create the Store Order required.

Different Sales Order Lines may have different values in LineStore and RequiredDeliveryDate attributes. The SalesOrderLines are grouped by these attributes and for each group, a separated Store Order is created (only for lines which products are Stocked and the sales order lines which are defined are sales return types (see Sales Order Row Types)).

The Store Order header is created based on the Sales Order header as follows:

StoreOrder.ToParty = 
    if SalesOrder.ShipToCustomer.HasValue 
        then SalesOrder.ShipToCustomer 
        else SalesOrder.Customer
StoreOrder.Store = Store
StoreOrder.MovementType = Receipt
StoreOrder.DueDate = RequiredDeliveryDate
StoreOrder.PlannedReleaseDate = RequiredDeliveryDate
StoreOrder.PlannedCompletionDate = RequiredDeliveryDate
StoreOrder.IssuedByParty = Store.ResponsibleParty
StoreOrder.DocumentCurrency = SalesOrder.DocumentCurrency
Note

The attributes which are not specified here are filled in as described in Standard Document Attributes

Note

The new store order is saved then and only when there is at least one line in it.

Fulfillments

Name SalesOrderLineToStoreOrderLine
Parent Entity SalesOrderLine
Child Entity StoreOrderLine
Parent / Child Relationship StoreOrderLine.ParentDocument = SalesOrder;StoreOrderLine.ParentLineNo = SalesOrderLine.LineNo

Metrics

Fulfillment Name Metric Name Measurement Unit Parent Value Child Value New Record
SalesOrderLineToStoreOrderLine MStandardQuantityBase SalesOrderLine.Product.BaseMeasurementUnit SalesOrderLine.StandardQuantityBase StoreOrderLine.StandardQuantityBase YES
SalesOrderLineToStoreOrderLine MQuantity SalesOrderLine.QuantityUnit SalesOrderLine.Quantity StoreOrderLine.Quantity NO
SalesOrderLineToStoreOrderLine MQuantityBase SalesOrderLine.Product.BaseMeasurementUnit SalesOrderLine.QuantityBase StoreOrderLine.QuantityBase NO
SalesOrderLineToStoreOrderLine MLineCost SalesOrder.DocumentCurrency if (SalesOrderLine.HistoricUnitCost != null) SalesOrderLine.HistoricUnitCost * SalesOrderLine.Quantityelse SUM(StoreTransactionLines[ParentStoreOrderLine.SalesOrderLine == SalesOrderLine.ReturnForSalesOrderLine].LineDocumentCost) * SalesOrderLine.Quantity / SUM(StoreTransactionLines[ParentStoreOrderLine.SalesOrderLine == SalesOrderLine.ReturnForSalesOrderLine].Quantity) StoreOrderLine.LineCost YES

The rows of the new document are created according to the data for fulfilled by Store Orders quantities and costs of the returned goods (defined by the Discrepancy System). For example, for each SalesOrderLine in the SalesOrder for the current Store and RequiredDeliveryDate, where the product is stocked and the row is defined as sales return (according to Sales Order Row Types), the remaining quantities - StoreOrderRemainingQuantity, StoreOrderRemainingQuantityBase and StoreOrderRemainingStandardQuantityBase - and remaining cost - StoreOrderRemainingReturnedCost, are defined. The specific in the unfulfilled quantities calculation is that before the Store Orders creation the quantities in the Sales Order are multiplied by -1. Also the unfulfilled cost calculation of the returned goods is performed as follows:

  1. if the SalesOrderLine has value in HistoricUnitCost attribute or ReturnForSalesOrderLine attribute, than the cost of the returned goods is defined in Calculating Cost For Returned Products;
  2. Otherwise, if none of those attributes has value, the cost is 0.

Then the calculated cost is reduced from the data in the already created StoreOrders for this specific SalesOrderLine.

So if at least one of StoreOrderRemainingStandardQuantityBase or StoreOrderRemainingReturnedCost is different from 0, a new StoreOrderLine is created as follows:

StoreOrderLine.LineNo = SalesOrderLine.LineNo
StoreOrderLine.ParentLineId = SalesOrderLine.SalesOrderLineId
StoreOrderLine.Product = SalesOrderLine.Product
StoreOrderLine.StoreBin = SalesOrderLine.StoreBin
StoreOrderLine.SerialNumber = SalesOrderLine.SerialNumber
StoreOrderLine.Quantity = REMAINING(MQuantity)StoreOrderLine.StandardQuantityBase = REMAINING(MStandardQuantityBase)
StoreOrderLine.QuantityUnit = SalesOrderLine.QuantityUnit
StoreOrderLine.QuantityBase = REMAINING(MQuantityBase)
StoreOrderLine.LineCost = REMAINING(MLineCost)
StoreOrderLine.Lot = SalesOrderLine.Lot
StoreOrderLine.GuaranteePeriodDays = 
    if SalesOrderLine.GuaranteePeriodDays.HasValue 
        then SalesOrderLine.GuaranteePeriodDays 
        else SalesOrderLine.Product.GuaranteePeriodDays
StoreOrderLine.SalesOrderLine = SalesOrderLine
StoreOrderLine.Notes = SalesOrderLine.Notes
StoreOrderLine.PersistLot = SalesOrderLine.PersistLot
StoreOrderLine.ProductVariant = SalesOrderLine.ProductVariant
StoreOrderLine.ParentLineNo = SalesOrderLine.LineNo
Note

Cost Corrections on the issue Store Transaction (the originally issued goods) are not taken into account! Only the document cost is used for calculating the returned cost.