diff --git a/modules/ticket/back/methods/ticket/isEditable.js b/modules/ticket/back/methods/ticket/isEditable.js index 766933d45..06fb2fed2 100644 --- a/modules/ticket/back/methods/ticket/isEditable.js +++ b/modules/ticket/back/methods/ticket/isEditable.js @@ -26,7 +26,7 @@ module.exports = Self => { 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 ticket = await Self.app.models.Ticket.findById(id, { fields: ['isDeleted', 'clientFk', 'refFk'], @@ -42,10 +42,10 @@ module.exports = Self => { const isDeleted = ticket && ticket.isDeleted; 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; - if (!ticket || (isOnDelivery && isNotNormalClient && !isProductionBoss) || isInvoiced || isDeleted) + if (!ticket || isInvoiced || isDeleted || (isOnDelivery && isNormalClient && !isProductionBoss)) return false; return true; diff --git a/modules/ticket/back/methods/ticket/specs/isEditable.spec.js b/modules/ticket/back/methods/ticket/specs/isEditable.spec.js index 3e55c5abd..b64981d02 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditable.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditable.spec.js @@ -29,15 +29,14 @@ describe('ticket isEditable()', () => { 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 result = await app.models.Ticket.isEditable(ctx, 8); expect(result).toEqual(true); }); - // #1719 claim.detail cambiar descuento falla con usuario nacho - xit('should not be able to edit a not deleted or invoiced ticket if the role is salesPerson', async() => { + it('should not be able to edit a deleted or invoiced ticket if the role is salesPerson', async() => { let ctx = {req: {accessToken: {userId: 18}}}; let result = await app.models.Ticket.isEditable(ctx, 8); diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index e4a54d6ba..94ada046f 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -42,7 +42,6 @@ module.exports = Self => { const options = {transaction: tx}; const filter = { - fields: ['id', 'ticketFk', 'price'], where: { id: {inq: salesIds} }, @@ -102,8 +101,7 @@ module.exports = Self => { value: value, componentFk: componentId}, options); - const updatedSale = models.Sale.updateAll({id: sale.id}, - {discount: newDiscount}, options); + const updatedSale = sale.updateAttribute('discount', newDiscount, options); promises.push(newComponent, updatedSale); }