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

View File

@ -268,8 +268,14 @@ class VnMySQL extends MySQL {
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) {
jorgep marked this conversation as resolved
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 .
if (!opts?.httpCtx)
if (!this.isLoggable(model))
return super[method].apply(this, args);
this.invokeMethodP(method, [...args], model, ctx, opts)

View File

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

View File

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

View File

@ -3,7 +3,7 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('sale model ', () => {
fdescribe('sale model ', () => {
const ctx = {
req: {
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', () => {
it('should increase quantity if you have enough available and the new price is the same as the previous one', async() => {
const ctx = {

View File

@ -11,24 +11,11 @@ module.exports = Self => {
Self.add = async(ctx, options) => {
const userId = ctx.req.accessToken.userId;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const isOperator = await Self.findById(user, myOptions);
if (!isOperator) await Self.create({workerFk: userId}, myOptions);
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};