Merge pull request 'fix(sale): rocket is only sent if it has sales' (!2580) from 6408-hotFix_sales_length into master
gitea/salix/pipeline/pr-test This commit looks good Details
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2580
Reviewed-by: Carlos Satorres <carlossa@verdnatura.es>
This commit is contained in:
Alex Moreno 2024-06-12 07:33:53 +00:00
commit b31a38e03b
1 changed files with 31 additions and 29 deletions

View File

@ -86,39 +86,41 @@ module.exports = Self => {
if (salesPersonFk && newStateOrder >= stateChecked.order) { if (salesPersonFk && newStateOrder >= stateChecked.order) {
const sales = await Self.rawSql(` const sales = await Self.rawSql(`
SELECT DISTINCT s.id, SELECT DISTINCT s.id,
s.itemFk, s.itemFk,
s.concept, s.concept,
s.originalQuantity AS oldQuantity, s.originalQuantity AS oldQuantity,
s.quantity AS newQuantity s.quantity AS newQuantity
FROM vn.sale s FROM vn.sale s
WHERE s.ticketFk = ? WHERE s.ticketFk = ?
AND s.originalQuantity IS NOT NULL AND s.originalQuantity IS NOT NULL
AND s.originalQuantity <> s.quantity AND s.originalQuantity <> s.quantity
`, [params.ticketFk], myOptions); `, [params.ticketFk], myOptions);
let changes = ''; if (sales.length) {
const url = await models.Url.getUrl(); let changes = '';
const $t = ctx.req.__; const url = await models.Url.getUrl();
for (let sale of sales) { const $t = ctx.req.__;
changes += `\r\n-` + $t('Changes in sales', { for (let sale of sales) {
itemId: sale.itemFk, changes += `\r\n-` + $t('Changes in sales', {
concept: sale.concept, itemId: sale.itemFk,
oldQuantity: sale.oldQuantity, concept: sale.concept,
newQuantity: sale.newQuantity, oldQuantity: sale.oldQuantity,
itemUrl: `${url}item/${sale.itemFk}/summary` newQuantity: sale.newQuantity,
}); itemUrl: `${url}item/${sale.itemFk}/summary`
const currentSale = await models.Sale.findById(sale.id, null, myOptions); });
await currentSale.updateAttributes({ const currentSale = await models.Sale.findById(sale.id, null, myOptions);
originalQuantity: currentSale.quantity await currentSale.updateAttributes({
}, myOptions); originalQuantity: currentSale.quantity
} }, myOptions);
}
const message = $t('Changed sale quantity', { const message = $t('Changed sale quantity', {
ticketId: ticket.id, ticketId: ticket.id,
changes: changes, changes: changes,
ticketUrl: `${url}ticket/${ticket.id}/sale` ticketUrl: `${url}ticket/${ticket.id}/sale`
}); });
await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions); await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions);
}
} }
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticket.id, params.code], myOptions); await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticket.id, params.code], myOptions);