Преглед на файлове

refactor(core): Extract creation of Sales to default fulfillment process

Michael Bromley преди 3 години
родител
ревизия
883e2dbbad
променени са 1 файла, в които са добавени 11 реда и са изтрити 1 реда
  1. 11 1
      packages/core/src/config/fulfillment/default-fulfillment-process.ts

+ 11 - 1
packages/core/src/config/fulfillment/default-fulfillment-process.ts

@@ -25,7 +25,14 @@ let stockMovementService: import('../../service/index').StockMovementService;
 
 /**
  * @description
- * The default {@link FulfillmentProcess}
+ * The default {@link FulfillmentProcess}. This process includes the following actions:
+ *
+ * - Executes the configured `FulfillmentHandler.onFulfillmentTransition()` before any state
+ *   transition.
+ * - On cancellation of a Fulfillment, creates the necessary {@link Cancellation} & {@link Allocation}
+ *   stock movement records.
+ * - When a Fulfillment transitions from the `Created` to `Pending` state, the necessary
+ *   {@link Sale} stock movements are created.
  *
  * @docsCategory fulfillment
  */
@@ -82,6 +89,9 @@ export const defaultFulfillmentProcess: FulfillmentProcess<FulfillmentState> = {
             // const lines = await groupOrderItemsIntoLines(ctx, orderLineInput);
             await stockMovementService.createAllocationsForOrderLines(ctx, orderLineInput);
         }
+        if (fromState === 'Created' && toState === 'Pending') {
+            await stockMovementService.createSalesForOrder(ctx, fulfillment.orderItems);
+        }
         const historyEntryPromises = orders.map(order =>
             historyService.createHistoryEntryForOrder({
                 orderId: order.id,