diff --git a/back/methods/collection/addItem.js b/back/methods/collection/addItem.js index 26eb9cc27..3b2a6921b 100644 --- a/back/methods/collection/addItem.js +++ b/back/methods/collection/addItem.js @@ -6,7 +6,7 @@ module.exports = Self => { accepts: [ { arg: 'code', - type: 'number', + type: 'string', required: true }, { diff --git a/back/methods/collection/spec/addItem.spec.js b/back/methods/collection/spec/addItem.spec.js index 58cc97610..199aae588 100644 --- a/back/methods/collection/spec/addItem.spec.js +++ b/back/methods/collection/spec/addItem.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -fdescribe('collection addItem()', () => { +describe('collection addItem()', () => { const quantity = 3; const ticketFk = 24; const warehouseFk = 1; diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 391034126..e3d08326e 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -205,5 +205,6 @@ "It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}", "Incorrect pin": "Incorrect pin.", "This machine is already in use.": "This machine is already in use.", - "This pallet does not exist": "This pallet does not exist" + "This pallet does not exist": "This pallet does not exist", + "We do not have availability for the selected item": "We do not have availability for the selected item" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index b273f7506..45de30904 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -341,5 +341,6 @@ "No hay tickets para sacar": "No hay tickets para sacar", "There is no zone for these parameters 999999": "There is no zone for these parameters 999999", "This machine is already in use.": "Esta máquina ya está en uso.", - "This pallet does not exist": "Este palet no existe" + "This pallet does not exist": "Este palet no existe", + "We do not have availability for the selected item": "No tenemos disponible el item seleccionado", } \ No newline at end of file diff --git a/modules/item/back/methods/item-shelving/makeMulti.js b/modules/item/back/methods/item-shelving/makeMulti.js index e4393e4de..7d1ee11a0 100644 --- a/modules/item/back/methods/item-shelving/makeMulti.js +++ b/modules/item/back/methods/item-shelving/makeMulti.js @@ -47,10 +47,10 @@ module.exports = Self => { }, 0); discardItems.push(item); - let [result] = await Self.rawSql('SELECT vn.itemPacking(?, ?)', [item, warehouseFk]); + const [result] = await Self.rawSql('SELECT vn.itemPacking(?, ?) itemPacking', [item, warehouseFk]); let packing; - if (result) packing = Object.values(result)[0]; + if (result) packing = result.itemPacking; if (!packing) packing = 1; quantity = quantity * packing; diff --git a/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js b/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js new file mode 100644 index 000000000..f64a815f2 --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/makeMulti.spec.js @@ -0,0 +1,54 @@ +const {models} = require('vn-loopback/server/server'); + +describe('item makeMulti()', () => { + const warehouseFk = 1; + + beforeAll(async() => { + ctx = { + accessToken: {userId: 9}, + req: { + headers: {origin: 'http://localhost'}, + } + }; + }); + + it('should add two new records', async() => { + const shelvingFk = 'ZPP'; + const items = [1, 1, 1, 2]; + const tx = await models.ItemShelving.beginTransaction({}); + const options = {transaction: tx}; + + try { + await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options); + const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); + + expect(itemShelvings.length).toEqual(2); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should update the visible items', async() => { + const shelvingFk = 'GVC'; + const items = [2, 2]; + const tx = await models.ItemShelving.beginTransaction({}); + const options = {transaction: tx}; + try { + const {visible: itemsBefore} = await models.ItemShelving.findOne({ + where: {shelvingFk, itemFk: items[0]} + }, options); + await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options); + const {visible: itemsAfter} = await models.ItemShelving.findOne({ + where: {shelvingFk, itemFk: items[0]} + }, options); + + expect(itemsAfter).toEqual(itemsBefore + 2); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +});