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) {
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);