diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index 7e7c4e06d..a60d732b1 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -133,20 +133,20 @@ module.exports = Self => { } }, myOptions); - let newComponent; + let deletedComponent; if (oldComponent) { const filter = { saleFk: sale.id, componentFk: oldComponent.componentFk }; - await models.SaleComponent.destroyAll(filter, myOptions); + deletedComponent = await models.SaleComponent.destroyAll(filter, myOptions); } - await createSaleComponent(sale.id, value, componentId, myOptions); + const newComponent = await createSaleComponent(sale.id, value, componentId, myOptions); const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions); - promises.push(newComponent, updatedSale); + promises.push(newComponent, updatedSale, deletedComponent); const change = `${oldDiscount}% ➔ *${newDiscount}%*`; changesMade += `\r\n-${sale.itemFk}: ${sale.concept} (${sale.quantity}) ${change}`; @@ -193,7 +193,7 @@ module.exports = Self => { async function createSaleComponent(saleId, value, componentId, myOptions) { const models = Self.app.models; - newComponent = models.SaleComponent.create({ + return models.SaleComponent.create({ saleFk: saleId, value: value, componentFk: componentId