diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index 62e4ebd42..9849b9318 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -73,28 +73,10 @@ module.exports = Self => { const usesMana = await models.Sale.usesMana(ctx, myOptions); const componentCode = usesMana ? 'mana' : 'buyerDiscount'; - const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions); - const componentId = discount.id; - const componentValue = newPrice - sale.price; - const where = { - componentFk: componentId, - saleFk: id - }; - const saleComponent = await models.SaleComponent.findOne({where}, myOptions); - if (saleComponent) { - await models.SaleComponent.updateAll(where, { - value: saleComponent.value + componentValue - }, myOptions); - } else { - await models.SaleComponent.create({ - saleFk: id, - componentFk: componentId, - value: componentValue - }, myOptions); - } await sale.updateAttributes({price: newPrice}, myOptions); + await Self.rawSql('CALL vn.sale_calculateComponent(?, ?)', [id, componentCode], myOptions); await Self.rawSql('CALL vn.manaSpellersRequery(?)', [userId], myOptions); await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions);