diff --git a/back/methods/collection/spec/updateCollectionSale.spec.js b/back/methods/collection/spec/updateCollectionSale.spec.js index 2f150aba9..83b161a73 100644 --- a/back/methods/collection/spec/updateCollectionSale.spec.js +++ b/back/methods/collection/spec/updateCollectionSale.spec.js @@ -1,13 +1,62 @@ const app = require('vn-loopback/server/server'); -// #2495 updateCollectionSale reparar poluciĆ³n de unitarios -xdescribe('updateCollectionSale()', () => { - it('return a new collection', async() => { +describe('updateCollectionSale()', () => { + it('should return a new collection', async() => { + const sectorOneWarehouseID = 1; 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[0][0].id).toEqual(1); 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(); }); }); diff --git a/back/methods/collection/updateCollectionSale.js b/back/methods/collection/updateCollectionSale.js index 01575c972..608250d18 100644 --- a/back/methods/collection/updateCollectionSale.js +++ b/back/methods/collection/updateCollectionSale.js @@ -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 args = ctx.args; - if (originalQuantity == quantity) { + if (args.originalQuantity == args.quantity) { 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(?,?,?)`; - await Self.rawSql(query, [shelvingFk, quantityPicked, itemFk]); + await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, args.itemFk]); } else { query = `CALL vn.sector_getWarehouse(?)`; - const [result] = await Self.rawSql(query, [sectorFk]); + const [result] = await Self.rawSql(query, [args.sectorFk]); 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(?,?)`; - return await Self.rawSql(query, [sale, quantity]); + return await Self.rawSql(query, [args.sale, args.quantity]); }; }; diff --git a/modules/item/back/models/item-placement.json b/modules/item/back/models/item-placement.json index c2d779fcd..7bbb2dc91 100644 --- a/modules/item/back/models/item-placement.json +++ b/modules/item/back/models/item-placement.json @@ -7,8 +7,18 @@ } }, "properties": { + "id": { + "type": "Number", + "id": true + }, "code": { "type": "String" + }, + "itemFk": { + "type": "Number" + }, + "warehouseFk": { + "type": "Number" } }, "relations": { diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json index 0fcc00f7e..f0391c565 100644 --- a/modules/item/back/models/item-shelving.json +++ b/modules/item/back/models/item-shelving.json @@ -8,18 +8,24 @@ }, "properties": { "id": { - "type": "number", + "type": "Number", "id": true, "description": "Identifier" }, "shelve": { - "type": "string" + "type": "String" + }, + "shelvingFk": { + "type": "String" + }, + "itemFk": { + "type": "Number" }, "deep": { - "type": "number" + "type": "Number" }, "quantity": { - "type": "number" + "type": "Number" }, "created": { "type": "Date" diff --git a/modules/ticket/back/models/sale-tracking.json b/modules/ticket/back/models/sale-tracking.json index 7936f827f..43b0df160 100644 --- a/modules/ticket/back/models/sale-tracking.json +++ b/modules/ticket/back/models/sale-tracking.json @@ -12,6 +12,12 @@ "type": "Number", "forceId": false }, + "saleFk": { + "type": "Number" + }, + "stateFk": { + "type": "Number" + }, "isChecked": { "type": "boolean" }, diff --git a/modules/ticket/back/models/ticket-tracking.json b/modules/ticket/back/models/ticket-tracking.json index 550df7d9c..c2c365013 100644 --- a/modules/ticket/back/models/ticket-tracking.json +++ b/modules/ticket/back/models/ticket-tracking.json @@ -5,22 +5,30 @@ "model": "TicketLog", "relation": "ticket", "showField": "stateFk" - }, - "options": { - "mysql": { - "table": "ticketTracking" - } - }, + }, + "options": { + "mysql": { + "table": "ticketTracking" + } + }, "properties": { - "id": { - "id": true, - "type": "Number", - "forceId": false - }, - "created": { - "type": "Date", - "required": false - } + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "created": { + "type": "Date" + }, + "ticketFk": { + "type": "Number" + }, + "stateFk": { + "type": "Number" + }, + "workerFk": { + "type": "Number" + } }, "relations": { "ticket": {