cardus 0.0.99 → 0.0.100
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/index.js +78 -73
- package/index.ts +119 -115
- package/package.json +1 -1
- package/types/index.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -161,7 +161,6 @@ class IntegrationManager {
|
|
|
161
161
|
});
|
|
162
162
|
yield this.insertUserDefaultConfigurationContent({
|
|
163
163
|
user,
|
|
164
|
-
tempShimpmentIds: successfullShipments.map((successfullShipment) => successfullShipment.idEnvioTemporal),
|
|
165
164
|
countryName: country.nombre_pais_en
|
|
166
165
|
});
|
|
167
166
|
// modificamos la agencia, cuando se tenga que hacer
|
|
@@ -200,7 +199,7 @@ class IntegrationManager {
|
|
|
200
199
|
});
|
|
201
200
|
}
|
|
202
201
|
insertUserDefaultConfigurationContent(_a) {
|
|
203
|
-
return __awaiter(this, arguments, void 0, function* ({ user,
|
|
202
|
+
return __awaiter(this, arguments, void 0, function* ({ user, countryName }) {
|
|
204
203
|
const idUsuario = user.id_usuario;
|
|
205
204
|
const { configurationService, llmAPIService } = this.services;
|
|
206
205
|
const insert = (data) => {
|
|
@@ -302,18 +301,22 @@ class IntegrationManager {
|
|
|
302
301
|
insertQuantityRelatedLines(_a) {
|
|
303
302
|
return __awaiter(this, arguments, void 0, function* ({ orders, idUsuario, crearBulto, group, warehouseId, shouldFindWarehouseSkus }) {
|
|
304
303
|
/*
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
304
|
+
En esta funcion se calculan los records a incluir en la tabla de detalles y en las de lineas
|
|
305
|
+
Los detalles, es facil, una por cada bulto (aqui no hay ni "agrupar" ni nada de eso, una por cada bulto y ya esta)
|
|
306
|
+
Las lineas, es mas complicado:
|
|
307
|
+
Creamos una linea por cada linea en el pedido.
|
|
308
|
+
Pero hay TRUCO, puede que haya que agrupar, puede que no, puede que haya que coger el peso y medidas del bulto, puede que del "bulto agrupado", hay que tener en cuenta las cantidades...
|
|
309
|
+
Asi que para ver todo esto, la logica esta dentro de la variable "shouldGroup".
|
|
309
310
|
*/
|
|
311
|
+
var _b;
|
|
310
312
|
const { integrationsService } = this.services;
|
|
311
|
-
const
|
|
313
|
+
const shouldGetMeasuresFromGroupBeingOneLine = !!((_b = (yield integrationsService.getDefaultIntegrationsData({
|
|
312
314
|
id_usuario: idUsuario,
|
|
313
315
|
id_integracion: this.integrationType
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
const createBultoFromLine = (
|
|
316
|
+
}))) === null || _b === void 0 ? void 0 : _b.dimensiones_medidas_configuradas);
|
|
317
|
+
// function to create package from line
|
|
318
|
+
const createBultoFromLine = (_c) => __awaiter(this, [_c], void 0, function* ({ line, idEnvioTemporal }) {
|
|
319
|
+
// funcion para crear bulto
|
|
317
320
|
const result = yield crearBulto({
|
|
318
321
|
lineItems: { idEnvioTemporal, line },
|
|
319
322
|
idUsuario
|
|
@@ -324,80 +327,60 @@ class IntegrationManager {
|
|
|
324
327
|
bulto,
|
|
325
328
|
cantidad,
|
|
326
329
|
idEnvioTemporal,
|
|
327
|
-
forzarAgrupamientoDeLinea: !!forzarAgrupamientoDeLinea
|
|
328
|
-
shouldGroup
|
|
330
|
+
forzarAgrupamientoDeLinea: !!forzarAgrupamientoDeLinea
|
|
329
331
|
};
|
|
330
332
|
}
|
|
331
333
|
return null;
|
|
332
334
|
});
|
|
333
|
-
|
|
334
|
-
|
|
335
|
+
yield Promise.allSettled(
|
|
336
|
+
// por cada pedido/envio
|
|
337
|
+
orders.map((_d) => __awaiter(this, [_d], void 0, function* ({ idEnvioTemporal, lineas }) {
|
|
335
338
|
if (!idEnvioTemporal)
|
|
336
339
|
return;
|
|
337
|
-
//
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const shouldGroup = ((group === null || group === void 0 ? void 0 : group.grouped) === 1 && lineas.length > 1) ||
|
|
341
|
-
((group === null || group === void 0 ? void 0 : group.grouped) === 1 && lineas.length === 1 && measuresFromConfig);
|
|
342
|
-
if (shouldGroup) {
|
|
343
|
-
this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
|
|
344
|
-
}
|
|
345
|
-
lineas.forEach((line) => {
|
|
346
|
-
const bultoPromise = createBultoFromLine({
|
|
340
|
+
// hacemos esto primero, todavia no sabemos si vamos a agrupar (porque necesitamos crear el bulto para eso, ya que la "cantidad" podria influir)
|
|
341
|
+
const bultosYCantidades = (yield Promise.all(lineas.map((line) => __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
const bultoYCantidad = yield createBultoFromLine({
|
|
347
343
|
line,
|
|
348
|
-
idEnvioTemporal
|
|
349
|
-
shouldGroup
|
|
350
|
-
});
|
|
351
|
-
obtenerBultosYCantidades.push(bultoPromise);
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
let bultosYCantidades = yield Promise.all(obtenerBultosYCantidades);
|
|
355
|
-
bultosYCantidades = bultosYCantidades.filter(Boolean);
|
|
356
|
-
if (shouldFindWarehouseSkus) {
|
|
357
|
-
const bultosYCantidadesGroupedByShipment = bultosYCantidades.reduce((acc, curr) => {
|
|
358
|
-
var _a;
|
|
359
|
-
const tempShipmentId = curr === null || curr === void 0 ? void 0 : curr.idEnvioTemporal;
|
|
360
|
-
if (!tempShipmentId)
|
|
361
|
-
return acc;
|
|
362
|
-
(_a = acc[tempShipmentId]) !== null && _a !== void 0 ? _a : (acc[tempShipmentId] = []);
|
|
363
|
-
acc[tempShipmentId].push(curr);
|
|
364
|
-
return acc;
|
|
365
|
-
}, {});
|
|
366
|
-
yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_c) => __awaiter(this, [_c], void 0, function* ([tempShipmentId, bultosYCantidades]) {
|
|
367
|
-
const json_referencias_cantidades = yield this.createJsonQuantityReferencesFromLines({
|
|
368
|
-
idUsuario,
|
|
369
|
-
warehouseId,
|
|
370
|
-
bultosYCantidades
|
|
344
|
+
idEnvioTemporal
|
|
371
345
|
});
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
bultosYCantidades.forEach((each) => {
|
|
381
|
-
if (!each)
|
|
382
|
-
return;
|
|
383
|
-
const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea, shouldGroup } = each;
|
|
384
|
-
try {
|
|
346
|
+
return bultoYCantidad;
|
|
347
|
+
})))).filter(Boolean);
|
|
348
|
+
// sacamos todos los bultos (y cantidad)
|
|
349
|
+
yield Promise.allSettled(bultosYCantidades.map((bultoYCantidad) => __awaiter(this, void 0, void 0, function* () {
|
|
350
|
+
if (!bultoYCantidad)
|
|
351
|
+
return;
|
|
352
|
+
const { bulto, cantidad, idEnvioTemporal, forzarAgrupamientoDeLinea } = bultoYCantidad;
|
|
353
|
+
// metemos los detalles siempre
|
|
385
354
|
this.dataToInsert.details.push({
|
|
386
355
|
id_envio: idEnvioTemporal,
|
|
387
356
|
bulto,
|
|
388
357
|
cantidad
|
|
389
358
|
});
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
359
|
+
// Debe agrupar si:
|
|
360
|
+
// 1. grouped es 1 + hay más de una línea
|
|
361
|
+
// 2. grouped es 1 + hay una línea + configuración integraciones tiene el campo dimensiones_medidas_configuradas a 1 (osea, que queremos que coja las dimensiones del bulto, aunque sea una sola linea)
|
|
362
|
+
// 3. grouped es 1 + hay una lines + cantidad es mayor que 1
|
|
363
|
+
const shouldGroup = (group === null || group === void 0 ? void 0 : group.grouped) === 1 &&
|
|
364
|
+
(lineas.length > 1 ||
|
|
365
|
+
(lineas.length === 1 &&
|
|
366
|
+
shouldGetMeasuresFromGroupBeingOneLine) ||
|
|
367
|
+
(lineas.length === 1 && Number(cantidad) > 1));
|
|
368
|
+
// si agrupamos, metemos solo una linea en "lineas" y cogemos las dimensiones y peso de "group" (lo que el usuario tenga por defecto)
|
|
369
|
+
if (shouldGroup) {
|
|
370
|
+
this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
|
|
371
|
+
// si no agrupamos, cogemos el peso y dimensiones del peso mismo
|
|
395
372
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
373
|
+
else {
|
|
374
|
+
// lo de "forzarAgrupamientoDeLinea" se hizo solo para un usuario (Pegaso) que ya ni siquiera esta. Lo que hace es que siempre mete una linea, sin tener en cuenta la cantidad, pero con las dimensiones que les hemos preparado para ese bulto (que es una suma de todos los bultos reales... un chanchullo)
|
|
375
|
+
if (forzarAgrupamientoDeLinea) {
|
|
376
|
+
this.dataToInsert.lines.push({
|
|
377
|
+
id_envio: idEnvioTemporal,
|
|
378
|
+
bulto
|
|
379
|
+
});
|
|
380
|
+
// y esto para todo el resto de usuarios
|
|
399
381
|
}
|
|
400
382
|
else {
|
|
383
|
+
// creamos una linea por cada una de las unidades de "cantidad" (si cantidad es 5, pues 5 lineas -todas iguales, con el peso y medidas del bulto-)
|
|
401
384
|
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
402
385
|
arrayFake.forEach(() => {
|
|
403
386
|
this.dataToInsert.lines.push({
|
|
@@ -407,11 +390,33 @@ class IntegrationManager {
|
|
|
407
390
|
});
|
|
408
391
|
}
|
|
409
392
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
393
|
+
// para cuando el usuario quiere mapear su sku con la referencia que tenga en almacen
|
|
394
|
+
if (shouldFindWarehouseSkus) {
|
|
395
|
+
const bultosYCantidadesGroupedByShipment = bultosYCantidades.reduce((acc, curr) => {
|
|
396
|
+
var _a;
|
|
397
|
+
const tempShipmentId = curr === null || curr === void 0 ? void 0 : curr.idEnvioTemporal;
|
|
398
|
+
if (!tempShipmentId)
|
|
399
|
+
return acc;
|
|
400
|
+
(_a = acc[tempShipmentId]) !== null && _a !== void 0 ? _a : (acc[tempShipmentId] = []);
|
|
401
|
+
acc[tempShipmentId].push(curr);
|
|
402
|
+
return acc;
|
|
403
|
+
}, {});
|
|
404
|
+
yield Promise.all(Object.entries(bultosYCantidadesGroupedByShipment).map((_e) => __awaiter(this, [_e], void 0, function* ([tempShipmentId, bultosYCantidades]) {
|
|
405
|
+
const json_referencias_cantidades = yield this.createJsonQuantityReferencesFromLines({
|
|
406
|
+
idUsuario,
|
|
407
|
+
warehouseId,
|
|
408
|
+
bultosYCantidades
|
|
409
|
+
});
|
|
410
|
+
if (json_referencias_cantidades.length > 0) {
|
|
411
|
+
this.dataToInsert.jsonQuantityReferences.push({
|
|
412
|
+
id_envio: Number(tempShipmentId),
|
|
413
|
+
json_referencias_cantidades
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
})));
|
|
417
|
+
}
|
|
418
|
+
})));
|
|
419
|
+
})));
|
|
415
420
|
});
|
|
416
421
|
}
|
|
417
422
|
}
|
package/index.ts
CHANGED
|
@@ -218,9 +218,6 @@ export class IntegrationManager {
|
|
|
218
218
|
|
|
219
219
|
await this.insertUserDefaultConfigurationContent({
|
|
220
220
|
user,
|
|
221
|
-
tempShimpmentIds: successfullShipments.map(
|
|
222
|
-
(successfullShipment) => successfullShipment.idEnvioTemporal
|
|
223
|
-
),
|
|
224
221
|
countryName: country.nombre_pais_en
|
|
225
222
|
});
|
|
226
223
|
|
|
@@ -279,11 +276,9 @@ export class IntegrationManager {
|
|
|
279
276
|
|
|
280
277
|
async insertUserDefaultConfigurationContent({
|
|
281
278
|
user,
|
|
282
|
-
tempShimpmentIds,
|
|
283
279
|
countryName
|
|
284
280
|
}: {
|
|
285
281
|
user: Record<string, string | number>;
|
|
286
|
-
tempShimpmentIds: number[];
|
|
287
282
|
countryName: string;
|
|
288
283
|
}) {
|
|
289
284
|
const idUsuario = user.id_usuario as number;
|
|
@@ -517,32 +512,32 @@ export class IntegrationManager {
|
|
|
517
512
|
shouldFindWarehouseSkus: boolean;
|
|
518
513
|
}) {
|
|
519
514
|
/*
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
515
|
+
En esta funcion se calculan los records a incluir en la tabla de detalles y en las de lineas
|
|
516
|
+
Los detalles, es facil, una por cada bulto (aqui no hay ni "agrupar" ni nada de eso, una por cada bulto y ya esta)
|
|
517
|
+
Las lineas, es mas complicado:
|
|
518
|
+
Creamos una linea por cada linea en el pedido.
|
|
519
|
+
Pero hay TRUCO, puede que haya que agrupar, puede que no, puede que haya que coger el peso y medidas del bulto, puede que del "bulto agrupado", hay que tener en cuenta las cantidades...
|
|
520
|
+
Asi que para ver todo esto, la logica esta dentro de la variable "shouldGroup".
|
|
524
521
|
*/
|
|
525
522
|
|
|
526
523
|
const { integrationsService } = this.services;
|
|
527
524
|
|
|
528
|
-
const
|
|
525
|
+
const shouldGetMeasuresFromGroupBeingOneLine = !!(
|
|
529
526
|
await integrationsService.getDefaultIntegrationsData({
|
|
530
527
|
id_usuario: idUsuario,
|
|
531
528
|
id_integracion: this.integrationType
|
|
532
|
-
})
|
|
533
|
-
|
|
534
|
-
const measuresFromConfig =
|
|
535
|
-
!!userIntegrationConfiguration?.dimensiones_medidas_configuradas;
|
|
529
|
+
})
|
|
530
|
+
)?.dimensiones_medidas_configuradas;
|
|
536
531
|
|
|
532
|
+
// function to create package from line
|
|
537
533
|
const createBultoFromLine = async ({
|
|
538
534
|
line,
|
|
539
|
-
idEnvioTemporal
|
|
540
|
-
shouldGroup
|
|
535
|
+
idEnvioTemporal
|
|
541
536
|
}: {
|
|
542
537
|
line: InsertContentShipmentLine;
|
|
543
538
|
idEnvioTemporal: number;
|
|
544
|
-
shouldGroup: boolean;
|
|
545
539
|
}): Promise<BultoYCantidad | null> => {
|
|
540
|
+
// funcion para crear bulto
|
|
546
541
|
const result = await crearBulto({
|
|
547
542
|
lineItems: { idEnvioTemporal, line },
|
|
548
543
|
idUsuario
|
|
@@ -554,115 +549,124 @@ export class IntegrationManager {
|
|
|
554
549
|
bulto,
|
|
555
550
|
cantidad,
|
|
556
551
|
idEnvioTemporal,
|
|
557
|
-
forzarAgrupamientoDeLinea: !!forzarAgrupamientoDeLinea
|
|
558
|
-
shouldGroup
|
|
552
|
+
forzarAgrupamientoDeLinea: !!forzarAgrupamientoDeLinea
|
|
559
553
|
};
|
|
560
554
|
}
|
|
561
555
|
return null;
|
|
562
556
|
};
|
|
563
557
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
// Debe agrupar si:
|
|
570
|
-
// 1. grouped es 1 + hay más de una línea
|
|
571
|
-
// 2. grouped es 1 + hay una línea + configuración integraciones tiene el campo dimensiones_medidas_configuradas a 1
|
|
572
|
-
const shouldGroup =
|
|
573
|
-
(group?.grouped === 1 && lineas.length > 1) ||
|
|
574
|
-
(group?.grouped === 1 && lineas.length === 1 && measuresFromConfig);
|
|
575
|
-
|
|
576
|
-
if (shouldGroup) {
|
|
577
|
-
this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
lineas.forEach((line) => {
|
|
581
|
-
const bultoPromise = createBultoFromLine({
|
|
582
|
-
line,
|
|
583
|
-
idEnvioTemporal,
|
|
584
|
-
shouldGroup
|
|
585
|
-
});
|
|
586
|
-
obtenerBultosYCantidades.push(bultoPromise);
|
|
587
|
-
});
|
|
588
|
-
});
|
|
558
|
+
await Promise.allSettled(
|
|
559
|
+
// por cada pedido/envio
|
|
560
|
+
orders.map(async ({ idEnvioTemporal, lineas }) => {
|
|
561
|
+
if (!idEnvioTemporal) return;
|
|
589
562
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
const tempShipmentId = curr?.idEnvioTemporal;
|
|
598
|
-
if (!tempShipmentId) return acc;
|
|
599
|
-
|
|
600
|
-
acc[tempShipmentId] ??= [];
|
|
601
|
-
acc[tempShipmentId].push(curr);
|
|
602
|
-
|
|
603
|
-
return acc;
|
|
604
|
-
}, {});
|
|
605
|
-
|
|
606
|
-
await Promise.all(
|
|
607
|
-
Object.entries(bultosYCantidadesGroupedByShipment).map(
|
|
608
|
-
async ([tempShipmentId, bultosYCantidades]) => {
|
|
609
|
-
const json_referencias_cantidades =
|
|
610
|
-
await this.createJsonQuantityReferencesFromLines({
|
|
611
|
-
idUsuario,
|
|
612
|
-
warehouseId,
|
|
613
|
-
bultosYCantidades
|
|
563
|
+
// hacemos esto primero, todavia no sabemos si vamos a agrupar (porque necesitamos crear el bulto para eso, ya que la "cantidad" podria influir)
|
|
564
|
+
const bultosYCantidades = (
|
|
565
|
+
await Promise.all(
|
|
566
|
+
lineas.map(async (line) => {
|
|
567
|
+
const bultoYCantidad = await createBultoFromLine({
|
|
568
|
+
line,
|
|
569
|
+
idEnvioTemporal
|
|
614
570
|
});
|
|
571
|
+
return bultoYCantidad;
|
|
572
|
+
})
|
|
573
|
+
)
|
|
574
|
+
).filter(Boolean);
|
|
575
|
+
|
|
576
|
+
// sacamos todos los bultos (y cantidad)
|
|
577
|
+
await Promise.allSettled(
|
|
578
|
+
bultosYCantidades.map(async (bultoYCantidad) => {
|
|
579
|
+
if (!bultoYCantidad) return;
|
|
580
|
+
|
|
581
|
+
const {
|
|
582
|
+
bulto,
|
|
583
|
+
cantidad,
|
|
584
|
+
idEnvioTemporal,
|
|
585
|
+
forzarAgrupamientoDeLinea
|
|
586
|
+
} = bultoYCantidad;
|
|
587
|
+
|
|
588
|
+
// metemos los detalles siempre
|
|
589
|
+
this.dataToInsert.details.push({
|
|
590
|
+
id_envio: idEnvioTemporal,
|
|
591
|
+
bulto,
|
|
592
|
+
cantidad
|
|
593
|
+
});
|
|
615
594
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
595
|
+
// Debe agrupar si:
|
|
596
|
+
// 1. grouped es 1 + hay más de una línea
|
|
597
|
+
// 2. grouped es 1 + hay una línea + configuración integraciones tiene el campo dimensiones_medidas_configuradas a 1 (osea, que queremos que coja las dimensiones del bulto, aunque sea una sola linea)
|
|
598
|
+
// 3. grouped es 1 + hay una lines + cantidad es mayor que 1
|
|
599
|
+
const shouldGroup =
|
|
600
|
+
group?.grouped === 1 &&
|
|
601
|
+
(lineas.length > 1 ||
|
|
602
|
+
(lineas.length === 1 &&
|
|
603
|
+
shouldGetMeasuresFromGroupBeingOneLine) ||
|
|
604
|
+
(lineas.length === 1 && Number(cantidad) > 1));
|
|
605
|
+
|
|
606
|
+
// si agrupamos, metemos solo una linea en "lineas" y cogemos las dimensiones y peso de "group" (lo que el usuario tenga por defecto)
|
|
607
|
+
if (shouldGroup) {
|
|
608
|
+
this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
|
|
609
|
+
// si no agrupamos, cogemos el peso y dimensiones del peso mismo
|
|
610
|
+
} else {
|
|
611
|
+
// lo de "forzarAgrupamientoDeLinea" se hizo solo para un usuario (Pegaso) que ya ni siquiera esta. Lo que hace es que siempre mete una linea, sin tener en cuenta la cantidad, pero con las dimensiones que les hemos preparado para ese bulto (que es una suma de todos los bultos reales... un chanchullo)
|
|
612
|
+
if (forzarAgrupamientoDeLinea) {
|
|
613
|
+
this.dataToInsert.lines.push({
|
|
614
|
+
id_envio: idEnvioTemporal,
|
|
615
|
+
bulto
|
|
616
|
+
});
|
|
617
|
+
// y esto para todo el resto de usuarios
|
|
618
|
+
} else {
|
|
619
|
+
// creamos una linea por cada una de las unidades de "cantidad" (si cantidad es 5, pues 5 lineas -todas iguales, con el peso y medidas del bulto-)
|
|
620
|
+
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
621
|
+
|
|
622
|
+
arrayFake.forEach(() => {
|
|
623
|
+
this.dataToInsert.lines.push({
|
|
624
|
+
id_envio: idEnvioTemporal,
|
|
625
|
+
bulto
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
}
|
|
621
629
|
}
|
|
622
|
-
}
|
|
623
|
-
)
|
|
624
|
-
);
|
|
625
|
-
}
|
|
626
630
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
shouldGroup
|
|
635
|
-
} = each;
|
|
636
|
-
try {
|
|
637
|
-
this.dataToInsert.details.push({
|
|
638
|
-
id_envio: idEnvioTemporal,
|
|
639
|
-
bulto,
|
|
640
|
-
cantidad
|
|
641
|
-
});
|
|
642
|
-
if (!shouldGroup && forzarAgrupamientoDeLinea) {
|
|
643
|
-
this.dataToInsert.lines.push({
|
|
644
|
-
id_envio: idEnvioTemporal,
|
|
645
|
-
bulto
|
|
646
|
-
});
|
|
647
|
-
}
|
|
631
|
+
// para cuando el usuario quiere mapear su sku con la referencia que tenga en almacen
|
|
632
|
+
if (shouldFindWarehouseSkus) {
|
|
633
|
+
const bultosYCantidadesGroupedByShipment =
|
|
634
|
+
bultosYCantidades.reduce<Record<number, BultoYCantidad[]>>(
|
|
635
|
+
(acc, curr) => {
|
|
636
|
+
const tempShipmentId = curr?.idEnvioTemporal;
|
|
637
|
+
if (!tempShipmentId) return acc;
|
|
648
638
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
this.insertTempShipmentGroupLine({ idEnvioTemporal, group });
|
|
652
|
-
} else {
|
|
653
|
-
const arrayFake = Array.from({ length: Number(cantidad) });
|
|
639
|
+
acc[tempShipmentId] ??= [];
|
|
640
|
+
acc[tempShipmentId].push(curr);
|
|
654
641
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
642
|
+
return acc;
|
|
643
|
+
},
|
|
644
|
+
{}
|
|
645
|
+
);
|
|
646
|
+
|
|
647
|
+
await Promise.all(
|
|
648
|
+
Object.entries(bultosYCantidadesGroupedByShipment).map(
|
|
649
|
+
async ([tempShipmentId, bultosYCantidades]) => {
|
|
650
|
+
const json_referencias_cantidades =
|
|
651
|
+
await this.createJsonQuantityReferencesFromLines({
|
|
652
|
+
idUsuario,
|
|
653
|
+
warehouseId,
|
|
654
|
+
bultosYCantidades
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
if (json_referencias_cantidades.length > 0) {
|
|
658
|
+
this.dataToInsert.jsonQuantityReferences.push({
|
|
659
|
+
id_envio: Number(tempShipmentId),
|
|
660
|
+
json_referencias_cantidades
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
)
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
})
|
|
668
|
+
);
|
|
669
|
+
})
|
|
670
|
+
);
|
|
667
671
|
}
|
|
668
672
|
}
|
package/package.json
CHANGED