#1719 claim.detail cambiar descuento falla

This commit is contained in:
Carlos Jimenez Ruiz 2019-09-26 10:56:49 +02:00
parent 156c9ec3ab
commit 2a2c5ae3c4
3 changed files with 6 additions and 9 deletions

View File

@ -26,7 +26,7 @@ module.exports = Self => {
where: {ticketFk: id} where: {ticketFk: id}
}); });
let isProductionBoss = await Self.app.models.Account.hasRole(userId, 'productionBoss'); let isProductionBoss = await Self.app.models.Account.hasRole(userId, 'salesAssistant');
let alertLevel = state ? state.alertLevel : null; let alertLevel = state ? state.alertLevel : null;
let ticket = await Self.app.models.Ticket.findById(id, { let ticket = await Self.app.models.Ticket.findById(id, {
fields: ['isDeleted', 'clientFk', 'refFk'], fields: ['isDeleted', 'clientFk', 'refFk'],
@ -42,10 +42,10 @@ module.exports = Self => {
const isDeleted = ticket && ticket.isDeleted; const isDeleted = ticket && ticket.isDeleted;
const isOnDelivery = (alertLevel && alertLevel > 0); const isOnDelivery = (alertLevel && alertLevel > 0);
const isNotNormalClient = ticket && ticket.client().type().code != 'normal'; const isNormalClient = ticket && ticket.client().type().code == 'normal';
const isInvoiced = ticket && ticket.refFk; const isInvoiced = ticket && ticket.refFk;
if (!ticket || (isOnDelivery && isNotNormalClient && !isProductionBoss) || isInvoiced || isDeleted) if (!ticket || isInvoiced || isDeleted || (isOnDelivery && isNormalClient && !isProductionBoss))
return false; return false;
return true; return true;

View File

@ -29,15 +29,14 @@ describe('ticket isEditable()', () => {
expect(result).toEqual(true); expect(result).toEqual(true);
}); });
it('should be able to edit a not deleted or invoiced ticket if the role is productionBoss', async() => { it('should be able to edit a deleted or invoiced ticket if the role is productionBoss', async() => {
let ctx = {req: {accessToken: {userId: 50}}}; let ctx = {req: {accessToken: {userId: 50}}};
let result = await app.models.Ticket.isEditable(ctx, 8); let result = await app.models.Ticket.isEditable(ctx, 8);
expect(result).toEqual(true); expect(result).toEqual(true);
}); });
// #1719 claim.detail cambiar descuento falla con usuario nacho it('should not be able to edit a deleted or invoiced ticket if the role is salesPerson', async() => {
xit('should not be able to edit a not deleted or invoiced ticket if the role is salesPerson', async() => {
let ctx = {req: {accessToken: {userId: 18}}}; let ctx = {req: {accessToken: {userId: 18}}};
let result = await app.models.Ticket.isEditable(ctx, 8); let result = await app.models.Ticket.isEditable(ctx, 8);

View File

@ -42,7 +42,6 @@ module.exports = Self => {
const options = {transaction: tx}; const options = {transaction: tx};
const filter = { const filter = {
fields: ['id', 'ticketFk', 'price'],
where: { where: {
id: {inq: salesIds} id: {inq: salesIds}
}, },
@ -102,8 +101,7 @@ module.exports = Self => {
value: value, value: value,
componentFk: componentId}, options); componentFk: componentId}, options);
const updatedSale = models.Sale.updateAll({id: sale.id}, const updatedSale = sale.updateAttribute('discount', newDiscount, options);
{discount: newDiscount}, options);
promises.push(newComponent, updatedSale); promises.push(newComponent, updatedSale);
} }