feat: refs #7704 Optimization
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Guillermo Bonet 2024-07-11 10:29:26 +02:00
parent 0416ebedb5
commit 823756d71a
2 changed files with 12 additions and 20 deletions

View File

@ -59,11 +59,8 @@ BEGIN
SELECT quantity INTO vMinQuantity SELECT quantity INTO vMinQuantity
FROM vn.itemMinimumQuantity FROM vn.itemMinimumQuantity
WHERE itemFk = vItem WHERE itemFk = vItem
AND ( AND (util.VN_CURDATE() >= `started`
util.VN_CURDATE() BETWEEN `started` AND `ended` AND (util.VN_CURDATE() <= `ended` OR `ended` IS NULL))
OR
(util.VN_CURDATE() >= `started` AND `ended` IS NULL)
)
AND (warehouseFk = vWarehouse OR warehouseFk IS NULL) AND (warehouseFk = vWarehouse OR warehouseFk IS NULL)
LIMIT 1; LIMIT 1;

View File

@ -83,8 +83,8 @@ module.exports = Self => {
const [itemInfo] = await models.Sale.rawSql(`SELECT available FROM tmp.ticketCalculateItem`, null, ctx.options); const [itemInfo] = await models.Sale.rawSql(`SELECT available FROM tmp.ticketCalculateItem`, null, ctx.options);
const available = itemInfo?.available; const available = itemInfo?.available;
if ((!isReduction && !available) || available < quantityAdded) // if ((!isReduction && !available) || available < quantityAdded)
throw new UserError(`This item is not available`); // throw new UserError(`This item is not available`);
if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return; if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return;
@ -93,21 +93,16 @@ module.exports = Self => {
fields: ['quantity'], fields: ['quantity'],
where: { where: {
itemFk: itemId, itemFk: itemId,
started: {lte: today},
or: [ or: [
{ {ended: {gte: today}},
and: [ {ended: null}
{started: {lte: today}},
{ended: {gte: today}}
]
},
{
and: [
{started: {lte: today}},
{ended: null}
]
}
], ],
warehouseFk: {inq: [ticket.warehouseFk, null]} // eslint-disable-next-line no-dupe-keys
or: [
{warehouseFk: ticket.warehouseFk},
{warehouseFk: null}
]
}, },
limit: 1 limit: 1
}, ctx.options); }, ctx.options);