refs #6199 feat(sale_updateQuantity): can upload
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
002329b0a1
commit
da20697052
|
@ -139,7 +139,7 @@ describe('Ticket Edit sale path', () => {
|
|||
await page.type(selectors.ticketSales.firstSaleQuantity, '11\u000d');
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('The new quantity should be smaller than the old one');
|
||||
expect(message.text).toContain('The price of the item changed');
|
||||
});
|
||||
|
||||
it('should remove 1 from the first sale quantity', async() => {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"The default consignee can not be unchecked": "The default consignee can not be unchecked",
|
||||
"Enter an integer different to zero": "Enter an integer different to zero",
|
||||
"Package cannot be blank": "Package cannot be blank",
|
||||
"The new quantity should be smaller than the old one": "The new quantity should be smaller than the old one",
|
||||
"The price of the item changed": "The price of the item changed",
|
||||
"The sales of this ticket can't be modified": "The sales of this ticket can't be modified",
|
||||
"Cannot check Equalization Tax in this NIF/CIF": "Cannot check Equalization Tax in this NIF/CIF",
|
||||
"You can't create an order for a frozen client": "You can't create an order for a frozen client",
|
||||
|
@ -191,4 +191,4 @@
|
|||
"Booking completed": "Booking complete",
|
||||
"The ticket is in preparation": "The ticket [{{ticketId}}]({{{ticketUrl}}}) of the sales person {{salesPersonId}} is in preparation",
|
||||
"You can only add negative amounts in refund tickets": "You can only add negative amounts in refund tickets"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
"The grade must be an integer greater than or equal to zero": "El grade debe ser un entero mayor o igual a cero",
|
||||
"Sample type cannot be blank": "El tipo de plantilla no puede quedar en blanco",
|
||||
"Description cannot be blank": "Se debe rellenar el campo de texto",
|
||||
"The new quantity should be smaller than the old one": "La nueva cantidad debe de ser menor que la anterior",
|
||||
"The price of the item changed": "El precio del artículo cambió",
|
||||
"The value should not be greater than 100%": "El valor no debe de ser mayor de 100%",
|
||||
"The value should be a number": "El valor debe ser un numero",
|
||||
"This order is not editable": "Esta orden no se puede modificar",
|
||||
|
|
|
@ -49,7 +49,7 @@ describe('sale updateQuantity()', () => {
|
|||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toEqual(new Error('The new quantity should be smaller than the old one'));
|
||||
expect(error).toEqual(new Error('The price of the item changed'));
|
||||
});
|
||||
|
||||
it('should add quantity if the quantity is greater than it should be and is role advanced', async() => {
|
||||
|
|
|
@ -35,7 +35,7 @@ module.exports = Self => {
|
|||
const ticket = await models.Ticket.findById(
|
||||
ticketId,
|
||||
{
|
||||
fields: ['id', 'clientFk', 'warehouseFk', 'shipped'],
|
||||
fields: ['id', 'clientFk', 'warehouseFk', 'addressFk', 'agencyModeFk', 'shipped', 'landed'],
|
||||
include: {
|
||||
relation: 'client',
|
||||
scope: {
|
||||
|
@ -68,25 +68,46 @@ module.exports = Self => {
|
|||
|
||||
if (item.family == 'EMB') return;
|
||||
|
||||
const itemInfo = await models.Item.getVisibleAvailable(
|
||||
itemId,
|
||||
ticket.warehouseFk,
|
||||
ticket.shipped,
|
||||
ctx.options
|
||||
);
|
||||
if (newQuantity < item.minQuantity)
|
||||
throw new UserError('The amount cannot be less than the minimum');
|
||||
|
||||
const oldQuantity = instance?.quantity ?? null;
|
||||
const quantityAdded = newQuantity - oldQuantity;
|
||||
if (itemInfo.available < quantityAdded)
|
||||
throw new UserError(`This item is not available`);
|
||||
|
||||
if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return;
|
||||
|
||||
if (newQuantity < item.minQuantity && itemInfo.available != newQuantity)
|
||||
throw new UserError('The amount cannot be less than the minimum');
|
||||
if (ctx.isNewInstance || newQuantity <= oldQuantity) return;
|
||||
|
||||
if (!ctx.isNewInstance && newQuantity > oldQuantity)
|
||||
throw new UserError('The new quantity should be smaller than the old one');
|
||||
await Self.rawSql(`CALL catalog_calcFromItem(?,?,?,?)`, [
|
||||
ticket.landed,
|
||||
ticket.addressFk,
|
||||
ticket.agencyModeFk,
|
||||
itemId
|
||||
],
|
||||
ctx.options);
|
||||
|
||||
const [itemInfo] = await Self.rawSql(`SELECT available FROM tmp.ticketCalculateItem`, null, ctx.options);
|
||||
if (itemInfo?.available < quantityAdded)
|
||||
throw new UserError(`This item is not available`);
|
||||
|
||||
const [saleGrouping] = await Self.rawSql(`
|
||||
SELECT MAX(t.grouping), t.price newPrice
|
||||
FROM tmp.ticketComponentPrice t
|
||||
WHERE t.grouping <= ?`,
|
||||
[quantityAdded],
|
||||
ctx.options);
|
||||
|
||||
await Self.rawSql(`
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.ticketCalculateItem,
|
||||
tmp.ticketComponentPrice,
|
||||
tmp.ticketComponent,
|
||||
tmp.ticketLot,
|
||||
tmp.zoneGetShipped;
|
||||
`, null, ctx.options);
|
||||
|
||||
if (!saleGrouping?.newPrice || instance.price < saleGrouping.newPrice)
|
||||
throw new UserError('The price of the item changed');
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue