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