refs #6199 fix(sale_quantity): add isReduction
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
2edfacb91c
commit
cf856a585b
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue