refs #5774 feat: solo se pueden añadir cantidades negativas si es un ticket de abono
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
8b92b35e29
commit
cf559b2ba5
|
@ -2833,7 +2833,8 @@ INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk
|
|||
|
||||
INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`)
|
||||
VALUES
|
||||
(1, 12);
|
||||
(1, 12),
|
||||
(8, 10);
|
||||
|
||||
INSERT INTO `vn`.`deviceProductionModels` (`code`)
|
||||
VALUES
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
"The current ticket can't be modified": "El ticket actual no puede ser modificado",
|
||||
"The current claim can't be modified": "La reclamación actual no puede ser modificada",
|
||||
"The sales of this ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas",
|
||||
"The sales do not exists": "La(s) línea(s) seleccionada(s) no existe(n)",
|
||||
"The sales do not exists": "La(s) línea(s) seleccionada(s) no existe(n)",
|
||||
"Please select at least one sale": "Por favor selecciona al menos una linea",
|
||||
"All sales must belong to the same ticket": "Todas las lineas deben pertenecer al mismo ticket",
|
||||
"NO_ZONE_FOR_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada",
|
||||
|
@ -293,5 +293,6 @@
|
|||
"comercialName": "Comercial",
|
||||
"Invalid NIF for VIES": "Invalid NIF for VIES",
|
||||
"Ticket does not exist": "Este ticket no existe",
|
||||
"Ticket is already signed": "Este ticket ya ha sido firmado"
|
||||
"Ticket is already signed": "Este ticket ya ha sido firmado",
|
||||
"You can only add negative amounts in refund tickets": "Solo se puede añadir cantidades negativas en tickets abono"
|
||||
}
|
||||
|
|
|
@ -110,4 +110,53 @@ describe('sale updateQuantity()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error if the quantity is negative and it is not a refund ticket', async() => {
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 1},
|
||||
headers: {origin: 'localhost:5000'},
|
||||
__: () => {}
|
||||
}
|
||||
};
|
||||
const saleId = 17;
|
||||
const newQuantity = -10;
|
||||
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
|
||||
let error;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
await models.Sale.updateQuantity(ctx, saleId, newQuantity, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toEqual(new Error('You can only add negative amounts in refund tickets'));
|
||||
});
|
||||
|
||||
it('should update a negative quantity when is a ticket refund', async() => {
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
const saleId = 13;
|
||||
const newQuantity = -10;
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
await models.Sale.updateQuantity(ctx, saleId, newQuantity, options);
|
||||
|
||||
const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options);
|
||||
|
||||
expect(modifiedLine.quantity).toEqual(newQuantity);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -68,6 +68,13 @@ module.exports = Self => {
|
|||
if (newQuantity > sale.quantity && !isRoleAdvanced)
|
||||
throw new UserError('The new quantity should be smaller than the old one');
|
||||
|
||||
const ticketRefund = await models.TicketRefund.findOne({
|
||||
where: {refundTicketFk: sale.ticketFk},
|
||||
fields: ['id']}
|
||||
, myOptions);
|
||||
if (newQuantity < 0 && !ticketRefund)
|
||||
throw new UserError('You can only add negative amounts in refund tickets');
|
||||
|
||||
const oldQuantity = sale.quantity;
|
||||
const result = await sale.updateAttributes({quantity: newQuantity}, myOptions);
|
||||
|
||||
|
|
Loading…
Reference in New Issue