refs #4671 uses sale_calculateComponent
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Javi Gallego 2023-09-28 09:22:23 +02:00
parent 7876561188
commit 4ebc812876
1 changed files with 1 additions and 19 deletions

View File

@ -73,28 +73,10 @@ module.exports = Self => {
const usesMana = await models.Sale.usesMana(ctx, myOptions); const usesMana = await models.Sale.usesMana(ctx, myOptions);
const componentCode = usesMana ? 'mana' : 'buyerDiscount'; 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 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.manaSpellersRequery(?)', [userId], myOptions);
await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions); await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions);