feat: refs #7704 Major changes #2717

Merged
guillermo merged 18 commits from 7704-itemMinimalQuantity into dev 2024-07-12 07:43:46 +00:00
1 changed files with 20 additions and 1 deletions
Showing only changes of commit 910071bde0 - Show all commits

View File

@ -211,7 +211,7 @@ describe('sale model ', () => {
}
});
it('should throw an error if the quantity is greater than the minimum quantity of the item but is out of range', async() => {
it('should throw an error if the quantity is lower than the minimum quantity of the item and is in range', async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
const saleId = 25;
@ -233,6 +233,25 @@ describe('sale model ', () => {
expect(e).toEqual(new Error('The amount cannot be less than the minimum'));
}
});
it('should update the quantity if the quantity is lower than the minimum quantity of the item and is out of the range', async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
const saleId = 17;
const newQuantity = 8;
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
if (sqlStatement.includes('catalog_calcFromItem')) {
sqlStatement = `
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY SELECT 1 as grouping, 100000 as price;`;
params = null;
}
return models.Ticket.rawSql(sqlStatement, params, opts);
});
await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts);
});
});
});