Merge pull request '6199_hotFix_isReduction' (!1807) from 6199_hotFix_isReduction into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1807
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Alex Moreno 2023-10-23 08:52:55 +00:00
commit 26aaaff21c
1 changed files with 5 additions and 3 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,
@ -80,16 +81,17 @@ module.exports = Self => {
ctx.options);
const [itemInfo] = await models.Sale.rawSql(`SELECT available FROM tmp.ticketCalculateItem`, null, ctx.options);
const available = itemInfo?.available;
if (!itemInfo?.available || itemInfo.available < quantityAdded)
if ((!isReduction && !available) || available < quantityAdded)
throw new UserError(`This item is not available`);
if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return;
if (newQuantity < item.minQuantity && newQuantity != itemInfo?.available)
if (newQuantity < item.minQuantity && newQuantity != 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