diff --git a/back/methods/collection/assignCollection.js b/back/methods/collection/assignCollection.js index 3384b325a..c4671e747 100644 --- a/back/methods/collection/assignCollection.js +++ b/back/methods/collection/assignCollection.js @@ -13,16 +13,21 @@ module.exports = Self => { }, }); - Self.assignCollection = async ctx => { + Self.assignCollection = async(ctx, options) => { const userId = ctx.req.accessToken.userId; + const myOptions = {userId}; + const $t = ctx.req.__; - await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk)', [userId]); + if (typeof options == 'object') + Object.assign(myOptions, options); + + await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk)', [userId], myOptions); const [assignedCollection] = await Self.rawSql('SELECT @vCollectionFk'); const {'@vCollectionFk': collectionFk} = assignedCollection; - if (!collectionFk) throw new UserError('No hay tickets para sacar'); - await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk]); + if (!collectionFk) throw new UserError($t('There are not picking tickets')); + await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions); return collectionFk; }; diff --git a/back/methods/collection/getSalesFromTicketOrCollection.js b/back/methods/collection/getSalesFromTicketOrCollection.js index 8fbc0f55b..09ccbafdc 100644 --- a/back/methods/collection/getSalesFromTicketOrCollection.js +++ b/back/methods/collection/getSalesFromTicketOrCollection.js @@ -30,8 +30,8 @@ module.exports = Self => { Self.getSalesFromTicketOrCollection = async(ctx, collectionOrTicketFk, print, source, options) => { const userId = ctx.req.accessToken.userId; - const models = Self.app.models; const myOptions = {userId}; + const $t = ctx.req.__; if (typeof options == 'object') Object.assign(myOptions, options); @@ -53,22 +53,20 @@ module.exports = Self => { if (print) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [id], myOptions); - if (tickets.length) await sendRocketTickets(tickets); + if (tickets.length) await sendRocketTickets(tickets, $t); return getCollection(id, tickets, sales, placements, myOptions); }; - async function sendRocketTickets(tickets) { + async function sendRocketTickets(tickets, $t) { for (let ticket of tickets) { let observations = ticket.observaciones.split(' '); for (let observation of observations) { const salesMan = ticket.salesPersonFk; - if (!observation.startsWith('#') && !observation.startsWith('@')) return; - await models.Chat.send(ctx, observation, - `El ticket ${ticket.ticketFk} del comercial ${salesMan} está en preparación.(mensaje creado automáticamente)` + $t('ticketCommercial', {ticket: ticket.ticketFk, salesMan}) ); } } @@ -83,7 +81,7 @@ module.exports = Self => { const {ticketFk} = ticket; ticket.sales = []; - const barcodes = await getBarcodes(ticketFk); + const barcodes = await getBarcodes(ticketFk, options); await Self.rawSql( 'CALL util.log_add(?, ?, ?, ?, ?, ?, ?, ?)', ['vn', 'ticket', 'Ticket', ticketFk, ticketFk, 'select', null, null], @@ -140,7 +138,7 @@ module.exports = Self => { return collection; } - async function getBarcodes(ticketId) { + async function getBarcodes(ticketId, options) { const query = `SELECT s.id movementId, b.code, @@ -152,7 +150,7 @@ module.exports = Self => { LEFT JOIN vn.travel tr ON tr.id = e.travelFk WHERE s.ticketFk = ? AND tr.landed >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)`; - return Self.rawSql(query, [ticketId]); + return Self.rawSql(query, [ticketId], options); } async function setState(source, id, options) { diff --git a/loopback/locale/en.json b/loopback/locale/en.json index dc3a4afae..5ff31a22f 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -213,6 +213,8 @@ "this state does not exist": "This state does not exist", "The line could not be marked": "The line could not be marked", "The sale can not be tracked": "The sale can not be tracked", - "Shelving not valid": "Shelving not valid" - + "Shelving not valid": "Shelving not valid", + "printerNotExists": "The printer does not exist", + "There are not picking tickets": "There are not picking tickets", + "ticketCommercial": "The ticket {{ ticket }} for the salesperson {{ salesMan }} is in preparation. (automatically generated message)" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 222df46d6..a1d1360a8 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -352,5 +352,7 @@ "The sale can not be tracked": "La línea no puede ser rastreada", "Shelving not valid": "Carro no válido", "Carro no válido": "Carro no válido", - "printerNotExists": "printerNotExists" + "printerNotExists": "No existe la impresora", + "There are not picking tickets": "No hay tickets para sacar", + "ticketCommercial": "El ticket {{ticket}} del comercial {{salesMan}} está en preparación.(mensaje creado automáticamente)" } \ No newline at end of file diff --git a/modules/item/back/methods/item/card.js b/modules/item/back/methods/item/card.js index 45c2ac36c..bc59c8bff 100644 --- a/modules/item/back/methods/item/card.js +++ b/modules/item/back/methods/item/card.js @@ -27,7 +27,7 @@ module.exports = Self => { Self.card = async(itemFk, warehouseFk) => { const models = Self.app.models; - const [result] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [itemFk, warehouseFk]); + const [[itemInfo]] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [itemFk, warehouseFk]); const barcodeItems = await Self.rawSql('SELECT vn.barcodeToItem(?) as realIdItem', [itemFk]); const [realIdItem] = barcodeItems.map(barcodeItem => barcodeItem.realIdItem); @@ -40,12 +40,7 @@ module.exports = Self => { } }); - let itemInfo; - if (result.length) { - itemInfo = {...result[0]}; - itemInfo.barcodes = barcodes; - } - + if (itemInfo) itemInfo.barcodes = barcodes; return itemInfo; }; }; diff --git a/modules/item/back/methods/item/specs/card.spec.js b/modules/item/back/methods/item/specs/card.spec.js index 725a4269d..65004cfa5 100644 --- a/modules/item/back/methods/item/specs/card.spec.js +++ b/modules/item/back/methods/item/specs/card.spec.js @@ -3,10 +3,10 @@ const {models} = require('vn-loopback/server/server'); describe('item card()', () => { const itemFk = 1; const warehouseFk = 1; - it('WIP: should get something', async() => { + it('should get an item with several barcodes', async() => { const card = await models.Item.card(itemFk, warehouseFk); expect(card).toBeDefined(); - expect(card.barcodes); + expect(card.barcodes.length).toBeTruthy(); }); });