From 789e0e65e3172737bc8b8a1dfc8a75d47e23fea6 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 12 Jun 2024 09:12:48 +0200 Subject: [PATCH] fix(sale): rocket is only sent if it has sales --- modules/ticket/back/methods/ticket/state.js | 60 +++++++++++---------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index eede02d74..1e6069b79 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -86,39 +86,41 @@ module.exports = Self => { if (salesPersonFk && newStateOrder >= stateChecked.order) { const sales = await Self.rawSql(` SELECT DISTINCT s.id, - s.itemFk, - s.concept, - s.originalQuantity AS oldQuantity, - s.quantity AS newQuantity + s.itemFk, + s.concept, + s.originalQuantity AS oldQuantity, + s.quantity AS newQuantity FROM vn.sale s - WHERE s.ticketFk = ? - AND s.originalQuantity IS NOT NULL - AND s.originalQuantity <> s.quantity + WHERE s.ticketFk = ? + AND s.originalQuantity IS NOT NULL + AND s.originalQuantity <> s.quantity `, [params.ticketFk], myOptions); - let changes = ''; - const url = await models.Url.getUrl(); - const $t = ctx.req.__; - for (let sale of sales) { - changes += `\r\n-` + $t('Changes in sales', { - itemId: sale.itemFk, - concept: sale.concept, - oldQuantity: sale.oldQuantity, - newQuantity: sale.newQuantity, - itemUrl: `${url}item/${sale.itemFk}/summary` - }); - const currentSale = await models.Sale.findById(sale.id, null, myOptions); - await currentSale.updateAttributes({ - originalQuantity: currentSale.quantity - }, myOptions); - } + if (sales.length) { + let changes = ''; + const url = await models.Url.getUrl(); + const $t = ctx.req.__; + for (let sale of sales) { + changes += `\r\n-` + $t('Changes in sales', { + itemId: sale.itemFk, + concept: sale.concept, + oldQuantity: sale.oldQuantity, + newQuantity: sale.newQuantity, + itemUrl: `${url}item/${sale.itemFk}/summary` + }); + const currentSale = await models.Sale.findById(sale.id, null, myOptions); + await currentSale.updateAttributes({ + originalQuantity: currentSale.quantity + }, myOptions); + } - const message = $t('Changed sale quantity', { - ticketId: ticket.id, - changes: changes, - ticketUrl: `${url}ticket/${ticket.id}/sale` - }); - await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions); + const message = $t('Changed sale quantity', { + ticketId: ticket.id, + changes: changes, + ticketUrl: `${url}ticket/${ticket.id}/sale` + }); + await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions); + } } await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticket.id, params.code], myOptions);