fixed collection tests pollution
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
53f69ae8e5
commit
54d31f15bb
|
@ -1,13 +1,62 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
// #2495 updateCollectionSale reparar polución de unitarios
|
describe('updateCollectionSale()', () => {
|
||||||
xdescribe('updateCollectionSale()', () => {
|
it('should return a new collection', async() => {
|
||||||
it('return a new collection', async() => {
|
const sectorOneWarehouseID = 1;
|
||||||
let ctx = {req: {accessToken: {userId: 106}}};
|
let ctx = {req: {accessToken: {userId: 106}}};
|
||||||
let response = await app.models.Collection.updateCollectionSale(ctx, 1, 5, 5, 5, 1, 4, false, 'UXN', 1, 1);
|
ctx.args = {
|
||||||
|
sale: 1,
|
||||||
|
originalQuantity: 5,
|
||||||
|
quantity: 5,
|
||||||
|
quantityPicked: 5,
|
||||||
|
ticketFk: 1,
|
||||||
|
stateFk: 4,
|
||||||
|
isNicho: false,
|
||||||
|
shelvingFk: 'UXN',
|
||||||
|
itemFk: 1,
|
||||||
|
sectorFk: 1
|
||||||
|
};
|
||||||
|
let originalSaleTracking = await app.models.SaleTracking.findOne({
|
||||||
|
where: {
|
||||||
|
saleFk: ctx.args.sale,
|
||||||
|
stateFk: ctx.args.stateFk
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let itemPlacement = await app.models.ItemPlacement.findOne({
|
||||||
|
where: {
|
||||||
|
itemFk: ctx.args.itemFk,
|
||||||
|
warehouseFk: sectorOneWarehouseID
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const originalSale = await app.models.Sale.findById(ctx.args.sale);
|
||||||
|
const originalItemShelving = await app.models.ItemShelving.findOne({where: {shelvingFk: ctx.args.shelvingFk, itemFk: ctx.args.itemFk}});
|
||||||
|
const originalTicketLastState = await app.models.TicketLastState.findById(ctx.args.ticketFk);
|
||||||
|
|
||||||
|
let response = await app.models.Collection.updateCollectionSale(ctx);
|
||||||
|
|
||||||
expect(response.length).toBeGreaterThan(0);
|
expect(response.length).toBeGreaterThan(0);
|
||||||
expect(response[0][0].id).toEqual(1);
|
expect(response[0][0].id).toEqual(1);
|
||||||
expect(response[0][0].quantity).toEqual(5);
|
expect(response[0][0].quantity).toEqual(5);
|
||||||
|
|
||||||
|
// restores
|
||||||
|
if (originalSaleTracking)
|
||||||
|
await originalSaleTracking.save();
|
||||||
|
else {
|
||||||
|
originalSaleTracking = await app.models.SaleTracking.findOne({
|
||||||
|
where: {
|
||||||
|
saleFk: ctx.args.sale,
|
||||||
|
stateFk: ctx.args.stateFk
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await originalSaleTracking.destroy();
|
||||||
|
}
|
||||||
|
await originalSale.save();
|
||||||
|
const itemShelvingsToDestroy = await app.models.ItemShelving.find({where: {shelvingFk: ctx.args.shelvingFk, itemFk: ctx.args.itemFk}});
|
||||||
|
for (itemShelving of itemShelvingsToDestroy)
|
||||||
|
await itemShelving.destroy();
|
||||||
|
|
||||||
|
await originalItemShelving.save();
|
||||||
|
await originalTicketLastState.save();
|
||||||
|
await itemPlacement.save();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -65,25 +65,26 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.updateCollectionSale = async(ctx, sale, originalQuantity, quantity, quantityPicked, ticketFk, stateFk, isNicho, shelvingFk, itemFk, sectorFk) => {
|
Self.updateCollectionSale = async ctx => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const args = ctx.args;
|
||||||
|
|
||||||
if (originalQuantity == quantity) {
|
if (args.originalQuantity == args.quantity) {
|
||||||
query = `CALL vn.collection_updateSale(?,?,?,?,?)`;
|
query = `CALL vn.collection_updateSale(?,?,?,?,?)`;
|
||||||
await Self.rawSql(query, [sale, originalQuantity, userId, stateFk, ticketFk]);
|
await Self.rawSql(query, [args.sale, args.originalQuantity, userId, args.stateFk, args.ticketFk]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNicho) {
|
if (!args.isNicho) {
|
||||||
query = `CALL vn.collection_faults(?,?,?)`;
|
query = `CALL vn.collection_faults(?,?,?)`;
|
||||||
await Self.rawSql(query, [shelvingFk, quantityPicked, itemFk]);
|
await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, args.itemFk]);
|
||||||
} else {
|
} else {
|
||||||
query = `CALL vn.sector_getWarehouse(?)`;
|
query = `CALL vn.sector_getWarehouse(?)`;
|
||||||
const [result] = await Self.rawSql(query, [sectorFk]);
|
const [result] = await Self.rawSql(query, [args.sectorFk]);
|
||||||
|
|
||||||
query = `CALL vn.itemPlacementSave(?,?,?)`;
|
query = `CALL vn.itemPlacementSave(?,?,?)`;
|
||||||
await Self.rawSql(query, [shelvingFk, quantityPicked, result[0]['warehouseFk']]);
|
await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, result[0]['warehouseFk']]);
|
||||||
}
|
}
|
||||||
query = `CALL vn.sale_updateOriginalQuantity(?,?)`;
|
query = `CALL vn.sale_updateOriginalQuantity(?,?)`;
|
||||||
return await Self.rawSql(query, [sale, quantity]);
|
return await Self.rawSql(query, [args.sale, args.quantity]);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,8 +7,18 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "Number",
|
||||||
|
"id": true
|
||||||
|
},
|
||||||
"code": {
|
"code": {
|
||||||
"type": "String"
|
"type": "String"
|
||||||
|
},
|
||||||
|
"itemFk": {
|
||||||
|
"type": "Number"
|
||||||
|
},
|
||||||
|
"warehouseFk": {
|
||||||
|
"type": "Number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -8,18 +8,24 @@
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"type": "number",
|
"type": "Number",
|
||||||
"id": true,
|
"id": true,
|
||||||
"description": "Identifier"
|
"description": "Identifier"
|
||||||
},
|
},
|
||||||
"shelve": {
|
"shelve": {
|
||||||
"type": "string"
|
"type": "String"
|
||||||
|
},
|
||||||
|
"shelvingFk": {
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"itemFk": {
|
||||||
|
"type": "Number"
|
||||||
},
|
},
|
||||||
"deep": {
|
"deep": {
|
||||||
"type": "number"
|
"type": "Number"
|
||||||
},
|
},
|
||||||
"quantity": {
|
"quantity": {
|
||||||
"type": "number"
|
"type": "Number"
|
||||||
},
|
},
|
||||||
"created": {
|
"created": {
|
||||||
"type": "Date"
|
"type": "Date"
|
||||||
|
|
|
@ -12,6 +12,12 @@
|
||||||
"type": "Number",
|
"type": "Number",
|
||||||
"forceId": false
|
"forceId": false
|
||||||
},
|
},
|
||||||
|
"saleFk": {
|
||||||
|
"type": "Number"
|
||||||
|
},
|
||||||
|
"stateFk": {
|
||||||
|
"type": "Number"
|
||||||
|
},
|
||||||
"isChecked": {
|
"isChecked": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,22 +5,30 @@
|
||||||
"model": "TicketLog",
|
"model": "TicketLog",
|
||||||
"relation": "ticket",
|
"relation": "ticket",
|
||||||
"showField": "stateFk"
|
"showField": "stateFk"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticketTracking"
|
"table": "ticketTracking"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "Number",
|
"type": "Number",
|
||||||
"forceId": false
|
"forceId": false
|
||||||
},
|
},
|
||||||
"created": {
|
"created": {
|
||||||
"type": "Date",
|
"type": "Date"
|
||||||
"required": false
|
},
|
||||||
}
|
"ticketFk": {
|
||||||
|
"type": "Number"
|
||||||
|
},
|
||||||
|
"stateFk": {
|
||||||
|
"type": "Number"
|
||||||
|
},
|
||||||
|
"workerFk": {
|
||||||
|
"type": "Number"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
"ticket": {
|
"ticket": {
|
||||||
|
|
Loading…
Reference in New Issue