#6276 createNewWarehouse methods migrated from silex to salix #1850

Merged
jorgep merged 158 commits from 6276-createNewWarehouse into dev 2024-03-06 11:32:11 +00:00
6 changed files with 117 additions and 108 deletions
Showing only changes of commit ec7a88c6dd - Show all commits

View File

@ -3094,9 +3094,7 @@ INSERT IGNORE INTO vn.sector
SET id = 9991, SET id = 9991,
description = 'NormalSector', description = 'NormalSector',
warehouseFk = 999, warehouseFk = 999,
isPreviousPreparedByPacking = FALSE,
code = 'NS', code = 'NS',
isPreviousPrepared = FALSE,
isPackagingArea = FALSE, isPackagingArea = FALSE,
sonFk = NULL, sonFk = NULL,
isMain = TRUE, isMain = TRUE,
@ -3106,9 +3104,7 @@ INSERT IGNORE INTO vn.sector
SET id = 9992, SET id = 9992,
description = 'PreviousSector', description = 'PreviousSector',
warehouseFk = 999, warehouseFk = 999,
isPreviousPreparedByPacking = FALSE,
code = 'PS', code = 'PS',
isPreviousPrepared = TRUE,
isPackagingArea = FALSE, isPackagingArea = FALSE,
sonFk = NULL, sonFk = NULL,
isMain = TRUE, isMain = TRUE,
@ -3118,41 +3114,38 @@ INSERT IGNORE INTO vn.sector
SET id = 9993, SET id = 9993,
description = 'MezaninneSector', description = 'MezaninneSector',
warehouseFk = 999, warehouseFk = 999,
isPreviousPreparedByPacking = TRUE,
code = 'MS', code = 'MS',
isPreviousPrepared = FALSE,
isPackagingArea = FALSE, isPackagingArea = FALSE,
sonFk = 9991, sonFk = 9991,
isMain = TRUE, isMain = TRUE,
itemPackingTypeFk = NULL; itemPackingTypeFk = NULL;
REPLACE vn.parking SET id = 9991011, sectorFk = 9991, code = 'A-01-1', pickingOrder = 1;
REPLACE vn.parking SET id = 9991012, sectorFk = 9991, code = 'A-02-2', pickingOrder = 2;
REPLACE vn.parking SET id = 9991013, sectorFk = 9991, code = 'A-03-3', pickingOrder = 3;
REPLACE vn.parking SET id = 9991014, sectorFk = 9991, code = 'A-04-4', pickingOrder = 4;
REPLACE vn.parking SET id = 9991015, sectorFk = 9991, code = 'A-05-5', pickingOrder = 5;
REPLACE vn.parking SET id = 9992011, sectorFk = 9992, code = 'P-01-1', pickingOrder = 6; INSERT INTO vn.parking (id,sectorFk, code, pickingOrder)
REPLACE vn.parking SET id = 9992012, sectorFk = 9992, code = 'P-02-2', pickingOrder = 7; VALUES (4,9991, 'A-01-1', 1),
REPLACE vn.parking SET id = 9992013, sectorFk = 9992, code = 'P-03-3', pickingOrder = 8; (5,9991, 'A-02-2', 2),
(6,9991, 'A-03-3', 3),
(7,9991, 'A-04-4', 4),
Outdated
Review

Diria que es mejor enfoque cambiar el propio insert de vn.parking y de vn.shelving por lo que quieres.
Que hacer un insert que luegos vas a hacer un replaces.
O hacer el insert directamente
(Esto aplica a todos los repalces que haces)

Tampoco acabo de ver el adaptar las fixtures a ids tan altos, como lo ves @jgallego ?

Diria que es mejor enfoque cambiar el propio insert de vn.parking y de vn.shelving por lo que quieres. Que hacer un insert que luegos vas a hacer un replaces. O hacer el insert directamente (Esto aplica a todos los repalces que haces) Tampoco acabo de ver el adaptar las fixtures a ids tan altos, como lo ves @jgallego ?

cuantos menos ids mejor, si se puede cambiar directo en las fixtures mejor, sino intentar evitar el id

cuantos menos ids mejor, si se puede cambiar directo en las fixtures mejor, sino intentar evitar el id

replaces cambiados. Los ids en este caso son necesarios por lo hablado con @sergiodt .

replaces cambiados. Los ids en este caso son necesarios por lo hablado con @sergiodt .
(8,9991, 'A-05-5', 5),
(9,9992, 'P-01-1', 6),
(10,9992, 'P-02-2', 7),
(11,9992, 'P-03-3', 8),
(12,9993, 'M-01-1', 9),
(13,9993, 'M-02-2', 10),
(14,9993, 'M-03-3', 11);
REPLACE vn.parking SET id = 9993011, sectorFk = 9993, code = 'M-01-1', pickingOrder = 9; INSERT INTO vn.shelving (code, parkingFk, priority)
REPLACE vn.parking SET id = 9993012, sectorFk = 9993, code = 'M-02-2', pickingOrder = 10; VALUES ('NAA', 4, 1),
REPLACE vn.parking SET id = 9993013, sectorFk = 9993, code = 'M-03-3', pickingOrder = 11; ('NBB', 5, 1),
('NCC', 6, 1),
REPLACE vn.shelving SET code = 'NAA', parkingFk = 9991011, priority = 1; ('NDD', 7, 1),
REPLACE vn.shelving SET code = 'NBB', parkingFk = 9991012, priority = 1; ('NEE', 8, 1),
REPLACE vn.shelving SET code = 'NCC', parkingFk = 9991013, priority = 1; ('PAA', 9, 1),
REPLACE vn.shelving SET code = 'NDD', parkingFk = 9991014, priority = 1; ('PBB', 10, 1),
REPLACE vn.shelving SET code = 'NEE', parkingFk = 9991015, priority = 1; ('PCC', 11, 1),
('MAA', 12, 1),
REPLACE vn.shelving SET code = 'PAA', parkingFk = 9992011, priority = 1; ('MBB', 13, 1),
REPLACE vn.shelving SET code = 'PBB', parkingFk = 9992012, priority = 1; ('MCC', 14, 1);
REPLACE vn.shelving SET code = 'PCC', parkingFk = 9992013, priority = 1;
REPLACE vn.shelving SET code = 'MAA', parkingFk = 9993011, priority = 1;
REPLACE vn.shelving SET code = 'MBB', parkingFk = 9993012, priority = 1;
REPLACE vn.shelving SET code = 'MCC', parkingFk = 9993013, priority = 1;
INSERT IGNORE INTO vn.itemType INSERT IGNORE INTO vn.itemType
SET id = 999, SET id = 999,
@ -3172,10 +3165,9 @@ INSERT IGNORE INTO vn.travel
landed = CURDATE(), landed = CURDATE(),
warehouseInFk = 999, warehouseInFk = 999,
warehouseOutFk = 1, warehouseOutFk = 1,
isReceived = TRUE, isReceived = TRUE;
agencyFk = 1;
REPLACE vn.entry INSERT INTO vn.entry
SET id = 999, SET id = 999,
supplierFk = 791, supplierFk = 791,
isConfirmed = TRUE, isConfirmed = TRUE,
@ -3183,7 +3175,7 @@ REPLACE vn.entry
travelFk = 99, travelFk = 99,
companyFk = 442; companyFk = 442;
REPLACE vn.ticket INSERT INTO vn.ticket
SET id = 999999, SET id = 999999,
clientFk = 2, clientFk = 2,
warehouseFk = 999, warehouseFk = 999,
@ -3194,7 +3186,7 @@ REPLACE vn.ticket
agencyModeFk = 10, agencyModeFk = 10,
landed = CURDATE(); landed = CURDATE();
REPLACE vn.collection INSERT INTO vn.collection
SET id = 10101010, SET id = 10101010,
workerFk = 9; workerFk = 9;
@ -3203,7 +3195,7 @@ INSERT IGNORE INTO vn.ticketCollection
ticketFk = 999999, ticketFk = 999999,
collectionFk = 10101010; collectionFk = 10101010;
REPLACE vn.item INSERT INTO vn.item
SET id = 999991, SET id = 999991,
name = 'Palito para pinchos', name = 'Palito para pinchos',
`size` = 25, `size` = 25,
@ -3216,7 +3208,7 @@ REPLACE vn.item
weightByPiece = 6, weightByPiece = 6,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT INTO vn.buy
SET id = 9999991, SET id = 9999991,
entryFk = 999, entryFk = 999,
itemFk = 999991, itemFk = 999991,
@ -3233,7 +3225,7 @@ REPLACE vn.buy
minPrice = 1, minPrice = 1,
weight = 50; weight = 50;
REPLACE vn.sale INSERT INTO vn.sale
SET id = 99991, SET id = 99991,
itemFk = 999991, itemFk = 999991,
ticketFk = 999999, ticketFk = 999999,
@ -3242,7 +3234,7 @@ REPLACE vn.sale
price = 1, price = 1,
discount = 0; discount = 0;
REPLACE vn.item INSERT INTO vn.item
SET id = 999992, SET id = 999992,
name = 'Madera verde', name = 'Madera verde',
`size` = 10, `size` = 10,
@ -3255,7 +3247,7 @@ REPLACE vn.item
weightByPiece = 50, weightByPiece = 50,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT INTO vn.buy
SET id = 9999992, SET id = 9999992,
entryFk = 999, entryFk = 999,
itemFk = 999992, itemFk = 999992,
@ -3272,7 +3264,7 @@ REPLACE vn.buy
minPrice = 1, minPrice = 1,
weight = 25; weight = 25;
REPLACE vn.sale INSERT INTO vn.sale
SET id = 99992, SET id = 99992,
itemFk = 999992, itemFk = 999992,
ticketFk = 999999, ticketFk = 999999,
@ -3281,7 +3273,7 @@ REPLACE vn.sale
price = 1, price = 1,
discount = 0; discount = 0;
REPLACE vn.item INSERT INTO vn.item
SET id = 999993, SET id = 999993,
name = 'Madera Roja/Morada', name = 'Madera Roja/Morada',
`size` = 12, `size` = 12,
@ -3294,7 +3286,7 @@ REPLACE vn.item
weightByPiece = 35, weightByPiece = 35,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT INTO vn.buy
SET id = 9999993, SET id = 9999993,
entryFk = 999, entryFk = 999,
itemFk = 999993, itemFk = 999993,
@ -3311,7 +3303,7 @@ REPLACE vn.buy
minPrice = 1, minPrice = 1,
weight = 25; weight = 25;
REPLACE vn.itemShelving INSERT INTO vn.itemShelving
SET id = 9931, SET id = 9931,
itemFk = 999993, itemFk = 999993,
shelvingFk = 'NCC', shelvingFk = 'NCC',
@ -3319,7 +3311,7 @@ REPLACE vn.itemShelving
`grouping` = 5, `grouping` = 5,
packing = 10; packing = 10;
REPLACE vn.sale INSERT INTO vn.sale
SET id = 99993, SET id = 99993,
itemFk = 999993, itemFk = 999993,
ticketFk = 999999, ticketFk = 999999,
@ -3328,7 +3320,7 @@ REPLACE vn.sale
price = 1, price = 1,
discount = 0; discount = 0;
REPLACE vn.item INSERT INTO vn.item
SET id = 999994, SET id = 999994,
name = 'Madera Naranja', name = 'Madera Naranja',
`size` = 18, `size` = 18,
@ -3341,7 +3333,7 @@ REPLACE vn.item
weightByPiece = 160, weightByPiece = 160,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT INTO vn.buy
SET id = 9999994, SET id = 9999994,
entryFk = 999, entryFk = 999,
itemFk = 999994, itemFk = 999994,
@ -3358,7 +3350,7 @@ REPLACE vn.buy
minPrice = 1, minPrice = 1,
weight = 25; weight = 25;
REPLACE vn.sale INSERT INTO vn.sale
SET id = 99994, SET id = 99994,
itemFk = 999994, itemFk = 999994,
ticketFk = 999999, ticketFk = 999999,
@ -3367,7 +3359,7 @@ REPLACE vn.sale
price = 1, price = 1,
discount = 0; discount = 0;
REPLACE vn.item INSERT INTO vn.item
SET id = 999995, SET id = 999995,
name = 'Madera Amarilla', name = 'Madera Amarilla',
`size` = 11, `size` = 11,
@ -3380,7 +3372,7 @@ REPLACE vn.item
weightByPiece = 78, weightByPiece = 78,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT INTO vn.buy
SET id = 9999995, SET id = 9999995,
entryFk = 999, entryFk = 999,
itemFk = 999995, itemFk = 999995,
@ -3397,7 +3389,7 @@ REPLACE vn.buy
minPrice = 1, minPrice = 1,
weight = 35; weight = 35;
REPLACE vn.sale INSERT INTO vn.sale
SET id = 99995, SET id = 99995,
itemFk = 999995, itemFk = 999995,
ticketFk = 999999, ticketFk = 999999,
@ -3407,7 +3399,7 @@ REPLACE vn.sale
discount = 0; discount = 0;
-- Palito naranja -- Palito naranja
REPLACE vn.item INSERT INTO vn.item
SET id = 999998, SET id = 999998,
name = 'Palito naranja', name = 'Palito naranja',
`size` = 11, `size` = 11,
@ -3420,7 +3412,7 @@ REPLACE vn.item
weightByPiece = 78, weightByPiece = 78,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT INTO vn.buy
SET id = 9999998, SET id = 9999998,
entryFk = 999, entryFk = 999,
itemFk = 999998, itemFk = 999998,
@ -3437,7 +3429,7 @@ REPLACE vn.buy
minPrice = 1, minPrice = 1,
weight = 35; weight = 35;
REPLACE vn.sale INSERT INTO vn.sale
SET id = 99998, SET id = 99998,
itemFk = 999998, itemFk = 999998,
ticketFk = 999999, ticketFk = 999999,
@ -3447,7 +3439,7 @@ REPLACE vn.sale
discount = 0; discount = 0;
-- Palito amarillo -- Palito amarillo
REPLACE vn.item INSERT INTO vn.item
SET id = 999999, SET id = 999999,
name = 'Palito amarillo', name = 'Palito amarillo',
`size` = 11, `size` = 11,
@ -3460,7 +3452,7 @@ REPLACE vn.item
weightByPiece = 78, weightByPiece = 78,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT INTO vn.buy
SET id = 9999999, SET id = 9999999,
entryFk = 999, entryFk = 999,
itemFk = 999999, itemFk = 999999,
@ -3477,7 +3469,7 @@ REPLACE vn.buy
minPrice = 1, minPrice = 1,
weight = 35; weight = 35;
REPLACE vn.sale INSERT INTO vn.sale
SET id = 99999, SET id = 99999,
itemFk = 999999, itemFk = 999999,
ticketFk = 999999, ticketFk = 999999,
@ -3487,7 +3479,7 @@ REPLACE vn.sale
discount = 0; discount = 0;
-- Palito azul -- Palito azul
REPLACE vn.item INSERT INTO vn.item
SET id = 1000000, SET id = 1000000,
name = 'Palito azul', name = 'Palito azul',
`size` = 10, `size` = 10,
@ -3500,7 +3492,7 @@ REPLACE vn.item
weightByPiece = 78, weightByPiece = 78,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT INTO vn.buy
SET id = 10000000, SET id = 10000000,
entryFk = 999, entryFk = 999,
itemFk = 1000000, itemFk = 1000000,
@ -3517,7 +3509,7 @@ REPLACE vn.buy
minPrice = 1, minPrice = 1,
weight = 35; weight = 35;
REPLACE vn.sale INSERT INTO vn.sale
SET id = 100000, SET id = 100000,
itemFk = 1000000, itemFk = 1000000,
ticketFk = 999999, ticketFk = 999999,
@ -3527,7 +3519,7 @@ REPLACE vn.sale
discount = 0; discount = 0;
-- Palito rojo -- Palito rojo
REPLACE vn.item INSERT INTO vn.item
SET id = 1000001, SET id = 1000001,
name = 'Palito rojo', name = 'Palito rojo',
`size` = 10, `size` = 10,
@ -3540,7 +3532,7 @@ REPLACE vn.item
weightByPiece = 78, weightByPiece = 78,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT INTO vn.buy
SET id = 10000001, SET id = 10000001,
entryFk = 999, entryFk = 999,
itemFk = 1000001, itemFk = 1000001,
@ -3558,7 +3550,7 @@ REPLACE vn.buy
weight = 35; weight = 35;
REPLACE vn.sale INSERT INTO vn.sale
SET id = 100001, SET id = 100001,
itemFk = 1000001, itemFk = 1000001,
ticketFk = 999999, ticketFk = 999999,
@ -3581,7 +3573,7 @@ INSERT IGNORE INTO vn.item
weightByPiece = 20, weightByPiece = 20,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT vn.buy
SET id = 9999996, SET id = 9999996,
entryFk = 999, entryFk = 999,
itemFk = 999996, itemFk = 999996,
@ -3598,7 +3590,7 @@ REPLACE vn.buy
minPrice = 7, minPrice = 7,
weight = 80; weight = 80;
REPLACE vn.sale INSERT vn.sale
SET id = 99996, SET id = 99996,
itemFk = 999996, itemFk = 999996,
ticketFk = 999999, ticketFk = 999999,
@ -3621,7 +3613,7 @@ INSERT IGNORE INTO vn.item
weightByPiece = 20, weightByPiece = 20,
intrastatFk = 44219999; intrastatFk = 44219999;
REPLACE vn.buy INSERT vn.buy
SET id = 9999997, SET id = 9999997,
entryFk = 999, entryFk = 999,
itemFk = 999997, itemFk = 999997,
@ -3638,7 +3630,7 @@ REPLACE vn.buy
minPrice = 7, minPrice = 7,
weight = 80; weight = 80;
REPLACE vn.sale INSERT vn.sale
SET id = 99997, SET id = 99997,
itemFk = 999997, itemFk = 999997,
ticketFk = 999999, ticketFk = 999999,
@ -3655,25 +3647,25 @@ DELETE ish.* FROM vn.itemShelving ish
JOIN vn.warehouse w ON w.id = s.warehouseFk JOIN vn.warehouse w ON w.id = s.warehouseFk
WHERE w.name = 'TestingWarehouse'; WHERE w.name = 'TestingWarehouse';
REPLACE vn.itemShelving INSERT INTO vn.itemShelving
(id, itemFk, shelvingFk, visible, created, `grouping`, packing, packagingFk, userFk, isChecked) (itemFk, shelvingFk, visible, created, `grouping`, packing, packagingFk, userFk, isChecked)
VALUES VALUES
(9911, 999991, 'NAA', 8, '2023-09-20', 1, 20, NULL, 103, NULL), (999991, 'NAA', 8, '2023-09-20', 1, 20, NULL, 103, NULL),
(9912, 999998, 'NAA', 80, '2023-09-20', 10, 30, NULL, 103, NULL), (999998, 'NAA', 80, '2023-09-20', 10, 30, NULL, 103, NULL),
(9913, 1000001, 'NAA', 6, '2023-09-20', 3, 50, NULL, 103, NULL), (1000001, 'NAA', 6, '2023-09-20', 3, 50, NULL, 103, NULL),
(9914, 1000000, 'NBB', 50, '2023-09-18', 25, 500, NULL, 103, NULL), (1000000, 'NBB', 50, '2023-09-18', 25, 500, NULL, 103, NULL),
(9915, 999993, 'NBB', 25, '2023-09-18', NULL, 10, NULL, 103, NULL), (999993, 'NBB', 25, '2023-09-18', NULL, 10, NULL, 103, NULL),
(9916, 999999, 'NBB', 30, '2023-09-18', 10, 500, NULL, 103, NULL), (999999, 'NBB', 30, '2023-09-18', 10, 500, NULL, 103, NULL),
(9917, 999993, 'NCC', 25, '2023-09-20', 5, 10, NULL, 103, NULL), (999993, 'NCC', 25, '2023-09-20', 5, 10, NULL, 103, NULL),
(9918, 999997, 'NCC', 10, '2023-09-20', NULL, 100, NULL, 103, NULL), (999997, 'NCC', 10, '2023-09-20', NULL, 100, NULL, 103, NULL),
(9919, 999999, 'NCC', 40, '2023-09-20', 10, 500, NULL, 103, NULL), (999999, 'NCC', 40, '2023-09-20', 10, 500, NULL, 103, NULL),
(9920, 999995, 'NDD', 10, '2023-09-19', NULL, 20, NULL, 103, NULL), (999995, 'NDD', 10, '2023-09-19', NULL, 20, NULL, 103, NULL),
(9921, 999994, 'NDD', 48, '2023-09-19', 4, 20, NULL, 103, NULL), (999994, 'NDD', 48, '2023-09-19', 4, 20, NULL, 103, NULL),
(9922, 1000001, 'NEE', 6, '2023-09-21', 3, 50, NULL, 103, NULL), (1000001, 'NEE', 6, '2023-09-21', 3, 50, NULL, 103, NULL),
(9923, 999992, 'NEE', 50, '2023-09-21', NULL, 1, NULL, 103, NULL), (999992, 'NEE', 50, '2023-09-21', NULL, 1, NULL, 103, NULL),
(9924, 1000000, 'NEE', 25, '2023-09-21', 25, 500, NULL, 103, NULL), (1000000, 'NEE', 25, '2023-09-21', 25, 500, NULL, 103, NULL),
(9925, 999996, 'PAA', 5, '2023-09-27', 1, 5, NULL, 103, NULL), (999996, 'PAA', 5, '2023-09-27', 1, 5, NULL, 103, NULL),
(9926, 999997, 'PCC', 10, '2023-09-27', 5, 100, NULL, 103, NULL); (999997, 'PCC', 10, '2023-09-27', 5, 100, NULL, 103, NULL);
-- Previous for Bolas de madera -- Previous for Bolas de madera
INSERT IGNORE INTO vn.sectorCollection INSERT IGNORE INTO vn.sectorCollection
@ -3682,9 +3674,9 @@ INSERT IGNORE INTO vn.sectorCollection
sectorFk = 9992; sectorFk = 9992;
INSERT IGNORE INTO vn.saleGroup INSERT IGNORE INTO vn.saleGroup
SET id = 999, SET id = 4,
userFk = 1, userFk = 1,
parkingFk = 9992011, parkingFk = 9,
sectorFk = 9992; sectorFk = 9992;
INSERT IGNORE INTO vn.sectorCollectionSaleGroup INSERT IGNORE INTO vn.sectorCollectionSaleGroup
@ -3692,13 +3684,14 @@ INSERT IGNORE INTO vn.sectorCollectionSaleGroup
sectorCollectionFk = 99, sectorCollectionFk = 99,
saleGroupFk = 999; saleGroupFk = 999;
REPLACE vn.saleGroupDetail INSERT vn.saleGroupDetail
SET id = 99991, SET id = 99991,
saleFk = 99996, saleFk = 99996,
saleGroupFk = 999; saleGroupFk = 999;
REPLACE vn.saleTracking INSERT INTO vn.saleTracking
SET saleFk = 99996, SET id = 7,
saleFk = 99996,
isChecked = TRUE, isChecked = TRUE,
workerFk = 103, workerFk = 103,
stateFk = 28; stateFk = 28;

View File

@ -268,8 +268,14 @@ class VnMySQL extends MySQL {
arguments, model, ctx, opts, cb); arguments, model, ctx, opts, cb);
} }
isLoggable(model) {
const Model = this.getModelDefinition(model).model;
const {settings} = Model.definition;
return settings.mixins?.Loggable;
}
invokeMethod(method, args, model, ctx, opts, cb) { invokeMethod(method, args, model, ctx, opts, cb) {
jorgep marked this conversation as resolved Outdated
Outdated
Review

Esto te lo ha dicho Juan?
Esto cambia el como se loggean todos los cambios

Esto te lo ha dicho Juan? Esto cambia el como se loggean todos los cambios

@alexm , @jgallego . Me hacía falta para poder utilizar la función account.getMyuserId (o parecido) dentro de los procedimientos. Si no, coge el usuario del sistema. En caso de duda, habría que hablarlo con @juan

Sí @alexm , @jgallego . Me hacía falta para poder utilizar la función account.getMyuserId (o parecido) dentro de los procedimientos. Si no, coge el usuario del sistema. En caso de duda, habría que hablarlo con @juan
Review

De momento he puesto que el modelo SaleBuy sea loggable, tal cual hemos hablado @alexm y yo. Le he preguntado por rocket a @juan a ver que opina... @sergiodt @jgallego .

De momento he puesto que el modelo SaleBuy sea loggable, tal cual hemos hablado @alexm y yo. Le he preguntado por rocket a @juan a ver que opina... @sergiodt @jgallego .

Cambios realizados para que todos tengan acceso acceso a userId, no solo loggable. Revisado con @juan

Cambios realizados para que todos tengan acceso acceso a userId, no solo loggable. Revisado con @juan
if (!opts?.httpCtx) if (!this.isLoggable(model))
return super[method].apply(this, args); return super[method].apply(this, args);
this.invokeMethodP(method, [...args], model, ctx, opts) this.invokeMethodP(method, [...args], model, ctx, opts)

View File

@ -97,6 +97,7 @@ module.exports = Self => {
} }
}, myOptions); }, myOptions);
} }
if (isBuy) if (isBuy)
await models.SaleBuy.create({saleFk, buyFk}, myOptions); await models.SaleBuy.create({saleFk, buyFk}, myOptions);

View File

@ -1,6 +1,9 @@
{ {
"name": "SaleBuy", "name": "SaleBuy",
"base": "VnModel", "base": "VnModel",
"mixins": {
"Loggable": true
},
"options": { "options": {
"mysql": { "mysql": {
"table": "saleBuy" "table": "saleBuy"

View File

@ -3,7 +3,7 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
describe('sale model ', () => { fdescribe('sale model ', () => {
const ctx = { const ctx = {
req: { req: {
accessToken: {userId: 9}, accessToken: {userId: 9},
@ -233,6 +233,25 @@ describe('sale model ', () => {
} }
}); });
it('should change the quantity if it has production role and is not a new instance', async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(9));
const tx = await models.Sale.beginTransaction({});
const options = {transaction: tx};
try {
const saleId = 1;
const newQuantity = 10;
const {quantity} = await models.Collection.setSaleQuantity(saleId, newQuantity, options);
expect(quantity).toEqual(newQuantity);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
describe('newPrice', () => { describe('newPrice', () => {
it('should increase quantity if you have enough available and the new price is the same as the previous one', async() => { it('should increase quantity if you have enough available and the new price is the same as the previous one', async() => {
const ctx = { const ctx = {

View File

@ -11,24 +11,11 @@ module.exports = Self => {
Self.add = async(ctx, options) => { Self.add = async(ctx, options) => {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const myOptions = {}; const myOptions = {};
let tx;
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const isOperator = await Self.findById(user, myOptions); const isOperator = await Self.findById(user, myOptions);
if (!isOperator) await Self.create({workerFk: userId}, myOptions); if (!isOperator) await Self.create({workerFk: userId}, myOptions);
jorgep marked this conversation as resolved Outdated

No sé si esto ya lo hablamos, me suena que sí, pero por asegurar.
Aquí habéis contemplado no crear este método y llamar al create nativo de loopback gestionando el error en caso de que ya exista?

No sé si esto ya lo hablamos, me suena que sí, pero por asegurar. Aquí habéis contemplado no crear este método y llamar al create nativo de loopback gestionando el error en caso de que ya exista?

@jgallego Sí, acabo de hablar con Sergio y hemos quedado en cambiarlo a como dices tú.

@jgallego Sí, acabo de hablar con Sergio y hemos quedado en cambiarlo a como dices tú.
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
}; };
}; };