fix: maneja si se elimina la sale
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2023-04-21 09:53:21 +02:00
parent 6f35eb0ce3
commit 5af961ac69
1 changed files with 29 additions and 17 deletions

View File

@ -30,35 +30,47 @@ module.exports = Self => {
const ticketLogs = await models.TicketLog.find( const ticketLogs = await models.TicketLog.find(
{ {
where: { where: {
or: [
{
and: [ and: [
{originFk: id}, {originFk: id},
{action: 'update'}, {action: 'update'},
{changedModel: 'Sale'} {changedModel: 'Sale'}
] ]
}, },
{
and: [
{originFk: id},
{action: 'delete'},
{changedModel: 'Sale'}
]
}
]
},
fields: [ fields: [
'oldInstance', 'oldInstance',
'newInstance', 'newInstance',
'changedModelId' 'changedModelId',
'changedModelValue'
], ],
}, myOptions); }, myOptions);
const changes = []; const changes = [];
for (const ticketLog of ticketLogs) {
const oldQuantity = ticketLog.oldInstance.quantity; for (const log of ticketLogs) {
const newQuantity = ticketLog.newInstance.quantity; const oldQuantity = log.oldInstance.quantity;
const newQuantity = log.newInstance?.quantity || 0;
if (oldQuantity || newQuantity) { if (oldQuantity || newQuantity) {
const sale = await models.Sale.findById(ticketLog.changedModelId, null, myOptions); const changeMessage = $t('Change quantity', {
const message = $t('Change quantity', { concept: log.changedModelValue,
concept: sale.concept,
oldQuantity: oldQuantity || 0, oldQuantity: oldQuantity || 0,
newQuantity: newQuantity || 0, newQuantity: newQuantity || 0,
}); });
changes.push(changeMessage);
}
}
changes.push(message);
}
}
return changes.join('\n'); return changes.join('\n');
}; };
}; };