@things-factory/warehouse-base 7.1.29 → 7.1.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/warehouse-base",
3
- "version": "7.1.29",
3
+ "version": "7.1.30",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -26,10 +26,10 @@
26
26
  "dependencies": {
27
27
  "@things-factory/biz-base": "^7.1.24",
28
28
  "@things-factory/id-rule-base": "^7.1.24",
29
- "@things-factory/integration-sellercraft": "^7.1.29",
30
- "@things-factory/marketplace-base": "^7.1.29",
31
- "@things-factory/product-base": "^7.1.25",
29
+ "@things-factory/integration-sellercraft": "^7.1.30",
30
+ "@things-factory/marketplace-base": "^7.1.30",
31
+ "@things-factory/product-base": "^7.1.30",
32
32
  "@things-factory/setting-base": "^7.1.24"
33
33
  },
34
- "gitHead": "f207892ca9a9d0811b62232810c875fdb278f14e"
34
+ "gitHead": "1e985cc6d9db84862cbaf08363442e91e6ab10ba"
35
35
  }
@@ -1,10 +1,12 @@
1
1
  import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
- import { In, MoreThan, SelectQueryBuilder } from 'typeorm'
2
+ import { In, MoreThan, SelectQueryBuilder, Equal } from 'typeorm'
3
3
 
4
4
  import { Bizplace } from '@things-factory/biz-base'
5
5
  import { generateId } from '@things-factory/id-rule-base'
6
6
  import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
7
7
  import { Product } from '@things-factory/product-base'
8
+ // @ts-ignore
9
+ import { ArrivalNotice } from '@things-factory/sales-base'
8
10
 
9
11
  import { INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE, LOCATION_STATUS, RULE_TYPE } from '../../constants'
10
12
  import { SellercraftController } from '../../controllers'
@@ -19,7 +21,10 @@ export class InventoryMutation {
19
21
  @Directive('@privilege(category: "inventory", privilege: "mutation")')
20
22
  @Directive('@transaction')
21
23
  @Mutation(returns => Inventory)
22
- async createInventory(@Arg('inventory') inventory: NewInventory, @Ctx() context: ResolverContext): Promise<Inventory> {
24
+ async createInventory(
25
+ @Arg('inventory') inventory: NewInventory,
26
+ @Ctx() context: ResolverContext
27
+ ): Promise<Inventory> {
23
28
  const { tx } = context.state
24
29
 
25
30
  return await tx.getRepository(Inventory).save({
@@ -61,7 +66,11 @@ export class InventoryMutation {
61
66
  @Directive('@privilege(category: "inventory", privilege: "mutation")')
62
67
  @Directive('@transaction')
63
68
  @Mutation(returns => Inventory)
64
- async updateInventoryRemark(@Arg('id') id: string, @Arg('remark') remark: string, @Ctx() context: ResolverContext): Promise<Inventory> {
69
+ async updateInventoryRemark(
70
+ @Arg('id') id: string,
71
+ @Arg('remark') remark: string,
72
+ @Ctx() context: ResolverContext
73
+ ): Promise<Inventory> {
65
74
  const { domain, user, tx } = context.state
66
75
 
67
76
  const repository = tx.getRepository(Inventory)
@@ -87,14 +96,20 @@ export class InventoryMutation {
87
96
  @Directive('@privilege(category: "inventory", privilege: "mutation")')
88
97
  @Directive('@transaction')
89
98
  @Mutation(returns => [Inventory])
90
- async updateMultipleInventory(@Arg('patches', type => [InventoryPatch]) patches: InventoryPatch[], @Ctx() context: ResolverContext): Promise<Inventory[]> {
99
+ async updateMultipleInventory(
100
+ @Arg('patches', type => [InventoryPatch]) patches: InventoryPatch[],
101
+ @Ctx() context: ResolverContext
102
+ ): Promise<Inventory[]> {
91
103
  return await updateMultipleInventory(patches, context)
92
104
  }
93
105
 
94
106
  @Directive('@privilege(category: "inventory", privilege: "mutation")')
95
107
  @Directive('@transaction')
96
108
  @Mutation(returns => Boolean)
97
- async deleteInventories(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<Boolean> {
109
+ async deleteInventories(
110
+ @Arg('ids', type => [String]) ids: string[],
111
+ @Ctx() context: ResolverContext
112
+ ): Promise<Boolean> {
98
113
  const { tx } = context.state
99
114
 
100
115
  await tx.getRepository(Inventory).delete({
@@ -150,8 +165,15 @@ export class InventoryMutation {
150
165
 
151
166
  let inventory: Inventory = await invQb.getOne()
152
167
  if (!inventory) throw new Error('Inventory not found')
168
+ const arrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
169
+ where: {
170
+ domain: { id: domain.id },
171
+ id: Equal(inventory.refOrderId)
172
+ }
173
+ })
153
174
 
154
- if (qty > inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0)) throw new Error('Transfer quantity exceeded inventory quantity')
175
+ if (qty > inventory.qty - (inventory?.lockedQty > 0 ? inventory.lockedQty : 0))
176
+ throw new Error('Transfer quantity exceeded inventory quantity')
155
177
 
156
178
  if (toLocation.name == inventory.location.name) throw new Error('Inventory is in current location')
157
179
 
@@ -196,14 +218,21 @@ export class InventoryMutation {
196
218
 
197
219
  await transactionInventory.transactionInventory(
198
220
  { ...inventory, qty: inventory.qty - transferQty, uomValue: inventory.uomValue - transferUomValue },
199
- null,
221
+ arrivalNotice,
200
222
  -transferQty,
201
223
  -transferUomValue,
202
224
  INVENTORY_TRANSACTION_TYPE.RELOCATE,
203
225
  reason || null
204
226
  )
205
227
 
206
- await transactionInventory.transactionInventory(newInventory, null, transferQty, transferUomValue, INVENTORY_TRANSACTION_TYPE.RELOCATE, reason || null)
228
+ await transactionInventory.transactionInventory(
229
+ newInventory,
230
+ arrivalNotice,
231
+ transferQty,
232
+ transferUomValue,
233
+ INVENTORY_TRANSACTION_TYPE.RELOCATE,
234
+ reason || null
235
+ )
207
236
 
208
237
  if (sellercraft) {
209
238
  const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
@@ -228,7 +257,14 @@ export class InventoryMutation {
228
257
  })
229
258
  }
230
259
 
231
- await transactionInventory.transactionInventory(inventory, null, 0, 0, INVENTORY_TRANSACTION_TYPE.RELOCATE, reason || null)
260
+ await transactionInventory.transactionInventory(
261
+ inventory,
262
+ arrivalNotice,
263
+ 0,
264
+ 0,
265
+ INVENTORY_TRANSACTION_TYPE.RELOCATE,
266
+ reason || null
267
+ )
232
268
 
233
269
  if (sellercraft) {
234
270
  const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
@@ -264,7 +300,10 @@ export class InventoryMutation {
264
300
  }
265
301
  }
266
302
 
267
- export async function updateMultipleInventory(patches: InventoryPatch[], context: ResolverContext): Promise<Inventory[]> {
303
+ export async function updateMultipleInventory(
304
+ patches: InventoryPatch[],
305
+ context: ResolverContext
306
+ ): Promise<Inventory[]> {
268
307
  const { domain, user, tx } = context.state
269
308
 
270
309
  let results = []
@@ -411,7 +450,12 @@ export async function updateMultipleInventory(patches: InventoryPatch[], context
411
450
  newRecord.product = (await tx.getRepository(Product).findOneBy({ id: newRecord.product.id })) as any
412
451
  }
413
452
 
414
- if ((newRecord.product && newRecord.product.id) || (newRecord.bizplace && newRecord.bizplace.id) || newRecord.batchId || newRecord.packingType) {
453
+ if (
454
+ (newRecord.product && newRecord.product.id) ||
455
+ (newRecord.bizplace && newRecord.bizplace.id) ||
456
+ newRecord.batchId ||
457
+ newRecord.packingType
458
+ ) {
415
459
  if (
416
460
  inventory.bizplace.id !== (newRecord.bizplace ? newRecord.bizplace.id : '') ||
417
461
  inventory.product.id !== (newRecord.product ? newRecord.product.id : '') ||