fix: maneja si se elimina la sale
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
6f35eb0ce3
commit
5af961ac69
|
@ -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');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue