@things-factory/operato-hub 4.3.265 → 4.3.267
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.
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js +124 -141
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-release-order.js +126 -128
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-release-order.js.map +1 -1
- package/dist-server/routers/xilnex-router.js +109 -111
- package/dist-server/routers/xilnex-router.js.map +1 -1
- package/package.json +11 -11
- package/server/routers/api/restful-apis/unstable/add-release-order.ts +154 -174
- package/server/routers/api/restful-apis/v1/warehouse/add-release-order.ts +157 -160
- package/server/routers/xilnex-router.ts +134 -136
|
@@ -1079,106 +1079,105 @@ async function assignToInventory(orderProducts: OrderProduct[], customerBizplace
|
|
|
1079
1079
|
where: { domain, name: 'rule-for-picking-product' }
|
|
1080
1080
|
})
|
|
1081
1081
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1092
|
-
}
|
|
1093
|
-
} else {
|
|
1094
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1082
|
+
const orderInventory = orderProduct.orderInventories[0]
|
|
1083
|
+
let sortings: any = []
|
|
1084
|
+
|
|
1085
|
+
switch (orderInventory.product.pickingStrategy) {
|
|
1086
|
+
case 'LIFO':
|
|
1087
|
+
sortings.push({ name: 'iv.created_at', desc: true })
|
|
1088
|
+
if (pickingProductSetting?.value) {
|
|
1089
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
1090
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1095
1091
|
}
|
|
1092
|
+
} else {
|
|
1093
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1094
|
+
}
|
|
1096
1095
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
}
|
|
1104
|
-
} else {
|
|
1105
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1096
|
+
break
|
|
1097
|
+
case 'FEFO':
|
|
1098
|
+
sortings.push({ name: 'iv.expiration_date', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1099
|
+
if (pickingProductSetting?.value) {
|
|
1100
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
1101
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1106
1102
|
}
|
|
1103
|
+
} else {
|
|
1104
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1105
|
+
}
|
|
1107
1106
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
}
|
|
1115
|
-
} else {
|
|
1116
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1107
|
+
break
|
|
1108
|
+
case 'FMFO':
|
|
1109
|
+
sortings.push({ name: 'iv.manufacture_date', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1110
|
+
if (pickingProductSetting?.value) {
|
|
1111
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
1112
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1117
1113
|
}
|
|
1114
|
+
} else {
|
|
1115
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1116
|
+
}
|
|
1118
1117
|
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
}
|
|
1125
|
-
} else {
|
|
1126
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1118
|
+
break
|
|
1119
|
+
case 'LOCATION':
|
|
1120
|
+
if (pickingProductSetting?.value) {
|
|
1121
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
1122
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1127
1123
|
}
|
|
1124
|
+
} else {
|
|
1125
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1126
|
+
}
|
|
1128
1127
|
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
}
|
|
1137
|
-
} else {
|
|
1138
|
-
sortings.push({ name: 'loc.name', desc: false })
|
|
1139
|
-
sortings.push({ name: 'iv.pallet_id', desc: false })
|
|
1128
|
+
break
|
|
1129
|
+
//Every other case includes 'FIFO' will be applicable for this case
|
|
1130
|
+
default:
|
|
1131
|
+
sortings.push({ name: 'iv.created_at', desc: false })
|
|
1132
|
+
if (pickingProductSetting?.value) {
|
|
1133
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
1134
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1140
1135
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1136
|
+
} else {
|
|
1137
|
+
sortings.push({ name: 'loc.name', desc: false })
|
|
1138
|
+
sortings.push({ name: 'iv.pallet_id', desc: false })
|
|
1139
|
+
}
|
|
1140
|
+
break
|
|
1141
|
+
}
|
|
1143
1142
|
|
|
1144
|
-
|
|
1143
|
+
let queryFilters = []
|
|
1145
1144
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1145
|
+
let queryStrings = queryFilters.reduce(
|
|
1146
|
+
(acc, itm, idx, arr) => {
|
|
1147
|
+
acc.values.push(itm.filters)
|
|
1149
1148
|
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1149
|
+
switch (itm?.operator) {
|
|
1150
|
+
case 'notin':
|
|
1151
|
+
case 'in':
|
|
1152
|
+
acc.query.push(
|
|
1153
|
+
`${itm.query} ${itm.operator == 'notin' ? 'NOT IN' : 'IN'} (${itm.filtes
|
|
1154
|
+
.map((itm, idx) => {
|
|
1155
|
+
return `$${acc.values.length + 1}`
|
|
1156
|
+
})
|
|
1157
|
+
.join(',')})`
|
|
1158
|
+
)
|
|
1159
|
+
break
|
|
1161
1160
|
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
}
|
|
1166
|
-
acc.query.push(`${itm.query} ${itm?.operator ? itm.operator : '='} $${acc.values.length + 1}`)
|
|
1167
|
-
},
|
|
1168
|
-
{
|
|
1169
|
-
query: [],
|
|
1170
|
-
values: []
|
|
1161
|
+
default:
|
|
1162
|
+
acc.query.push(`${itm.query} ${itm?.operator ? itm.operator : '='} $${acc.values.length + 1}`)
|
|
1163
|
+
break
|
|
1171
1164
|
}
|
|
1172
|
-
|
|
1165
|
+
acc.query.push(`${itm.query} ${itm?.operator ? itm.operator : '='} $${acc.values.length + 1}`)
|
|
1166
|
+
},
|
|
1167
|
+
{
|
|
1168
|
+
query: [],
|
|
1169
|
+
values: []
|
|
1170
|
+
}
|
|
1171
|
+
)
|
|
1173
1172
|
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1173
|
+
let sortQuery = sortings
|
|
1174
|
+
.map(itm => {
|
|
1175
|
+
return `${itm.name} ${itm.desc ? 'DESC' : 'ASC'}`
|
|
1176
|
+
})
|
|
1177
|
+
.join(`,`)
|
|
1179
1178
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1179
|
+
let updatedInventories = await tx.getRepository(Inventory).query(
|
|
1180
|
+
`
|
|
1182
1181
|
update inventories tgt set locked_qty = coalesce(locked_qty,0) + src.reserve_qty,
|
|
1183
1182
|
locked_uom_value = coalesce(locked_uom_value,0) + src.reserve_uom_value,
|
|
1184
1183
|
updated_at = NOW(),
|
|
@@ -1195,9 +1194,8 @@ async function assignToInventory(orderProducts: OrderProduct[], customerBizplace
|
|
|
1195
1194
|
sum(qty - locked_qty - release_qty) over (order by sort_seq asc rows between unbounded preceding and current row) as lock_amount
|
|
1196
1195
|
from (
|
|
1197
1196
|
SELECT 0 as sort_seq, null as id, null as pallet_id, null as batch_id, null as batch_id_ref,
|
|
1198
|
-
null as unit, '${orderInventory.uom}' as uom, '${orderInventory.packingType}' as packing_type, '${
|
|
1199
|
-
|
|
1200
|
-
}' as packing_size,
|
|
1197
|
+
null as unit, '${orderInventory.uom}' as uom, '${orderInventory.packingType}' as packing_type, '${orderInventory.packingSize
|
|
1198
|
+
}' as packing_size,
|
|
1201
1199
|
null as manufacture_year, null as carton_id, 0 as uom_value, 0 as locked_uom_value, 0 as qty, 0 as locked_qty, null as created_at,
|
|
1202
1200
|
'${orderInventory.releaseQty}' as release_qty, '${orderInventory.releaseUomValue}' as release_uom_value
|
|
1203
1201
|
UNION
|
|
@@ -1225,60 +1223,60 @@ async function assignToInventory(orderProducts: OrderProduct[], customerBizplace
|
|
|
1225
1223
|
tgt."id", tgt."qty", tgt."pallet_id", tgt."carton_id", tgt."batch_id", tgt."batch_id_ref", tgt."unit",
|
|
1226
1224
|
tgt."uom", tgt."packing_type", tgt."packing_size", tgt."manufacture_year",
|
|
1227
1225
|
tgt."locked_qty", tgt."uom_value", tgt."locked_uom_value", src."reserve_qty", src."reserve_uom_value";`,
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1226
|
+
[
|
|
1227
|
+
user?.id || null,
|
|
1228
|
+
warehouseDomain.id,
|
|
1229
|
+
customerBizplace.id,
|
|
1230
|
+
orderInventory.packingType,
|
|
1231
|
+
orderInventory.packingSize,
|
|
1232
|
+
orderInventory.product.id,
|
|
1233
|
+
INVENTORY_STATUS.STORED,
|
|
1234
|
+
LOCATION_TYPE.QUARANTINE,
|
|
1235
|
+
LOCATION_TYPE.RESERVE,
|
|
1236
|
+
...queryStrings.values
|
|
1237
|
+
]
|
|
1238
|
+
)
|
|
1241
1239
|
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
})
|
|
1240
|
+
let totalAssigned = updatedInventories[0].reduce((acc, inv) => {
|
|
1241
|
+
return acc + inv.reserve_qty
|
|
1242
|
+
}, 0)
|
|
1243
|
+
|
|
1244
|
+
if (orderProduct.releaseQty != totalAssigned) {
|
|
1245
|
+
throw new ValidationError({
|
|
1246
|
+
errorCode: 'INSUFFICIENT_STOCK',
|
|
1247
|
+
message: 'insufficient stock',
|
|
1248
|
+
detail: JSON.stringify({
|
|
1249
|
+
code: 'insufficient stock',
|
|
1250
|
+
sku: orderProduct.product.sku,
|
|
1251
|
+
packingType: orderProduct.packingType,
|
|
1252
|
+
packingSize: orderProduct.packingSize,
|
|
1253
|
+
uom: orderProduct.uom,
|
|
1254
|
+
qty: orderProduct.releaseQty,
|
|
1255
|
+
uom_value: orderProduct.releaseUomValue
|
|
1259
1256
|
})
|
|
1257
|
+
})
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
updatedInventories[0].forEach(inv => {
|
|
1261
|
+
let oi = {
|
|
1262
|
+
...orderInventory,
|
|
1263
|
+
inventory: { id: inv.id },
|
|
1264
|
+
uom: inv.uom,
|
|
1265
|
+
packingType: inv.packing_type,
|
|
1266
|
+
batchId: inv.batch_id,
|
|
1267
|
+
releaseQty: inv.reserve_qty,
|
|
1268
|
+
releaseUomValue: inv.reserve_uom_value,
|
|
1269
|
+
pickedQty: 0,
|
|
1270
|
+
packedQty: 0,
|
|
1271
|
+
type: ORDER_TYPES.RELEASE_OF_GOODS,
|
|
1272
|
+
status: ORDER_INVENTORY_STATUS.PENDING_WORKSHEET,
|
|
1273
|
+
domain: { id: warehouseDomain.id },
|
|
1274
|
+
bizplace: { id: customerBizplace.id }
|
|
1260
1275
|
}
|
|
1261
1276
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
...orderInventory,
|
|
1265
|
-
inventory: { id: inv.id },
|
|
1266
|
-
uom: inv.uom,
|
|
1267
|
-
packingType: inv.packing_type,
|
|
1268
|
-
batchId: inv.batch_id,
|
|
1269
|
-
releaseQty: inv.reserve_qty,
|
|
1270
|
-
releaseUomValue: inv.reserve_uom_value,
|
|
1271
|
-
pickedQty: 0,
|
|
1272
|
-
packedQty: 0,
|
|
1273
|
-
type: ORDER_TYPES.RELEASE_OF_GOODS,
|
|
1274
|
-
status: ORDER_INVENTORY_STATUS.PENDING_WORKSHEET,
|
|
1275
|
-
domain: { id: warehouseDomain.id },
|
|
1276
|
-
bizplace: { id: customerBizplace.id }
|
|
1277
|
-
}
|
|
1277
|
+
assignedOrderInventories.push(oi)
|
|
1278
|
+
})
|
|
1278
1279
|
|
|
1279
|
-
assignedOrderInventories.push(oi)
|
|
1280
|
-
})
|
|
1281
|
-
}
|
|
1282
1280
|
|
|
1283
1281
|
orderProducts[opIdx].orderInventories = assignedOrderInventories
|
|
1284
1282
|
}
|