Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2024-06-12 10:11:14 +02:00
commit b5ecf2e3b5
2 changed files with 38 additions and 32 deletions

View File

@ -72,16 +72,20 @@ module.exports = Self => {
const salesPerson = sale.ticket().client().salesPersonUser(); const salesPerson = sale.ticket().client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const url = await Self.app.models.Url.getUrl(); const url = await Self.app.models.Url.getUrl();
const message = $t('Changed sale quantity', { const change = $t('Changes in sales', {
ticketId: sale.ticket().id,
itemId: sale.itemFk, itemId: sale.itemFk,
concept: sale.concept, concept: sale.concept,
oldQuantity: oldQuantity, oldQuantity: oldQuantity,
newQuantity: newQuantity, newQuantity: newQuantity,
ticketUrl: `${url}ticket/${sale.ticket().id}/sale`,
itemUrl: `${url}item/${sale.itemFk}/summary` itemUrl: `${url}item/${sale.itemFk}/summary`
}); });
const message = $t('Changed sale quantity', {
ticketId: sale.ticket().id,
changes: change,
ticketUrl: `${url}ticket/${sale.ticket().id}/sale`,
});
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message, myOptions); await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message, myOptions);
} }

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