@things-factory/sales-base 4.3.697 → 4.3.700

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -78,6 +78,8 @@ export const InventoryUtil = {
78
78
  }
79
79
  }
80
80
 
81
+ // optional override for outbound shelf life (from ContactPoint deliverTo)
82
+ const releaseShelfLifeOverrideFilter = filters.find(f => f.name === 'releaseShelfLifeOverride')
81
83
  let queryStrings = `
82
84
  CREATE TEMP TABLE temp_inventory_product_group ON COMMIT DROP AS (
83
85
  SELECT * FROM (
@@ -163,7 +165,19 @@ export const InventoryUtil = {
163
165
  ) bp on i.product_id = bp.product_id
164
166
  WHERE i.bizplace_id IN (${bizplaceIds})
165
167
  AND i.lock_inventory is not true
166
- AND case when i.expiration_date is not null and p.min_outbound_shelf_life is not null then CURRENT_DATE < i.expiration_date - p.min_outbound_shelf_life else true end
168
+ AND case
169
+ when i.expiration_date is not null
170
+ then CURRENT_DATE < i.expiration_date - (
171
+ case
172
+ when $2::integer is not null and $2::integer > 0
173
+ then $2::integer
174
+ when p.min_outbound_shelf_life is not null
175
+ then p.min_outbound_shelf_life
176
+ else 0
177
+ end
178
+ )
179
+ else true
180
+ end
167
181
  ${productDetailWhereClause}
168
182
  ${
169
183
  productFilter
@@ -252,7 +266,10 @@ export const InventoryUtil = {
252
266
  )
253
267
  `
254
268
 
255
- await trxMgr.query(queryStrings, [domain.id])
269
+ await trxMgr.query(queryStrings, [
270
+ domain.id,
271
+ releaseShelfLifeOverrideFilter ? releaseShelfLifeOverrideFilter.value : null
272
+ ])
256
273
 
257
274
  const [{ total }]: any = await trxMgr.query(`select count(*) as total from temp_inventory_product_group`)
258
275
  let items: any[] = []
@@ -295,6 +312,7 @@ export const InventoryUtil = {
295
312
  let cycleCountFilter = filters.find(filter => filter.name == 'cycleCount')?.value
296
313
 
297
314
  const _groupType = filters.find(res => res.name == 'groupType')
315
+ const releaseShelfLifeOverrideFilter = filters.find(filter => filter.name === 'releaseShelfLifeOverride')
298
316
  let queryStrings = `
299
317
  CREATE TEMP TABLE temp_inventory_product_group AS (
300
318
  SELECT * FROM (
@@ -335,7 +353,7 @@ export const InventoryUtil = {
335
353
  AND i.transfer_qty <= 0
336
354
  AND i.transfer_uom_value <= 0
337
355
  AND i.lock_inventory is not true
338
- AND CASE WHEN i.expiration_date IS NOT NULL AND p.min_outbound_shelf_life IS NOT NULL THEN CURRENT_DATE < i.expiration_date - p.min_outbound_shelf_life ELSE true END
356
+ AND CASE WHEN i.expiration_date IS NOT NULL AND COALESCE($2::integer, p.min_outbound_shelf_life) IS NOT NULL THEN CURRENT_DATE < i.expiration_date - COALESCE($2::integer, p.min_outbound_shelf_life) ELSE true END
339
357
  ${
340
358
  cycleCountFilter
341
359
  ? `AND i.id NOT IN (
@@ -425,7 +443,10 @@ export const InventoryUtil = {
425
443
  })
426
444
  }
427
445
 
428
- await trxMgr.query(queryStrings, [domain.id])
446
+ await trxMgr.query(queryStrings, [
447
+ domain.id,
448
+ releaseShelfLifeOverrideFilter ? releaseShelfLifeOverrideFilter.value : null
449
+ ])
429
450
 
430
451
  const [{ total }]: any = await trxMgr.query(
431
452
  `select count(*) as total from temp_inventory_product_group ${filterGroupTypeQuery ? filterGroupTypeQuery : ''}`
@@ -873,7 +894,8 @@ export const InventoryUtil = {
873
894
  recall: boolean = null,
874
895
  cartonId?: string,
875
896
  expirationDate?: Date,
876
- warehouseName?: string
897
+ warehouseName?: string,
898
+ outboundShelfLifeOverride?: number
877
899
  ): Promise<OrderInventory[]> {
878
900
  let strictProduct = 'false'
879
901
 
@@ -918,14 +940,15 @@ export const InventoryUtil = {
918
940
  .andWhere('"iv"."transfer_uom_value" <= 0')
919
941
  .andWhere('"iv"."product_id" = :productId')
920
942
  .andWhere(
921
- 'case when "iv"."expiration_date" is not null and "p"."min_outbound_shelf_life" is not null then CURRENT_DATE < "iv"."expiration_date" - "p"."min_outbound_shelf_life" else true end'
943
+ 'case when "iv"."expiration_date" is not null then CURRENT_DATE < "iv"."expiration_date" - (case when :outboundShelfLifeOverride::integer is not null and :outboundShelfLifeOverride::integer > 0 then :outboundShelfLifeOverride::integer when "p"."min_outbound_shelf_life" is not null then "p"."min_outbound_shelf_life" else 0 end) else true end'
922
944
  )
923
945
  .setParameters({
924
946
  domainId: domain.id,
925
947
  bizplaceId: customerBizplace.id,
926
948
  productId: product.id,
927
949
  status: INVENTORY_STATUS.STORED,
928
- locationTypes
950
+ locationTypes,
951
+ outboundShelfLifeOverride: outboundShelfLifeOverride ?? null
929
952
  })
930
953
 
931
954
  if (batchId) {