refs #6199 fix(sale_quantity): add isReduction
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-10-23 09:50:00 +02:00
parent 2edfacb91c
commit cf856a585b
1 changed files with 3 additions and 2 deletions

View File

@ -33,6 +33,7 @@ module.exports = Self => {
const itemId = changes?.itemFk || instance?.itemFk;
const oldQuantity = instance?.quantity ?? null;
const quantityAdded = newQuantity - oldQuantity;
const isReduction = oldQuantity && newQuantity <= oldQuantity;
const ticket = await models.Ticket.findById(
ticketId,
@ -81,7 +82,7 @@ module.exports = Self => {
const [itemInfo] = await models.Sale.rawSql(`SELECT available FROM tmp.ticketCalculateItem`, null, ctx.options);
if (!itemInfo?.available || itemInfo.available < quantityAdded)
if ((!isReduction && !itemInfo?.available) || itemInfo.available < quantityAdded)
throw new UserError(`This item is not available`);
if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return;
@ -89,7 +90,7 @@ module.exports = Self => {
if (newQuantity < item.minQuantity && newQuantity != itemInfo?.available)
throw new UserError('The amount cannot be less than the minimum');
if (ctx.isNewInstance || newQuantity <= oldQuantity) return;
if (ctx.isNewInstance || isReduction) return;
const [saleGrouping] = await models.Sale.rawSql(`
SELECT t.price newPrice