From 0fc01b2316f78235e8df8e354b77a006f37d768d Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 18 Nov 2020 08:16:37 +0100 Subject: [PATCH] 1419 - Claim update discount hotfix --- modules/claim/front/detail/index.html | 4 +-- modules/claim/front/detail/index.js | 25 +++++++++---------- .../back/methods/ticket/updateDiscount.js | 8 ++++-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/modules/claim/front/detail/index.html b/modules/claim/front/detail/index.html index e364801bf..690fb6fad 100644 --- a/modules/claim/front/detail/index.html +++ b/modules/claim/front/detail/index.html @@ -55,8 +55,8 @@ {{::saleClaimed.sale.price | currency: 'EUR':2}} - {{saleClaimed.sale.discount}} % diff --git a/modules/claim/front/detail/index.js b/modules/claim/front/detail/index.js index 9f6767318..4e0017baa 100644 --- a/modules/claim/front/detail/index.js +++ b/modules/claim/front/detail/index.js @@ -54,6 +54,10 @@ class Controller extends Section { this.updateNewPrice(); } + get isClaimManager() { + return this.aclService.hasAny(['claimManager']); + } + openAddSalesDialog() { this.getClaimableFromTicket(); this.$.addSales.show(); @@ -131,17 +135,6 @@ class Controller extends Section { return total; } - showEditPopover(event, saleClaimed) { - if (this.isEditable) { - if (!this.aclService.hasAny(['claimManager'])) - return this.vnApp.showError(this.$t('Insuficient permisos')); - - this.saleClaimed = saleClaimed; - this.$.editPopover.parent = event.target; - this.$.editPopover.show(); - } - } - getSalespersonMana() { this.$http.get(`Tickets/${this.claim.ticketFk}/getSalesPersonMana`).then(res => { this.mana = res.data; @@ -164,6 +157,14 @@ class Controller extends Section { }); } + showEditPopover(event, saleClaimed) { + if (this.aclService.hasAny(['claimManager'])) { + this.saleClaimed = saleClaimed; + this.$.editPopover.parent = event.target; + this.$.editPopover.show(); + } + } + updateDiscount() { const claimedSale = this.saleClaimed.sale; if (this.newDiscount != claimedSale.discount) { @@ -176,8 +177,6 @@ class Controller extends Section { this.clearDiscount(); this.vnApp.showSuccess(this.$t('Data saved!')); - }).catch(err => { - this.vnApp.showError(err.message); }); } diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index 7c9f9ae48..1bebaae8d 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -70,13 +70,17 @@ module.exports = Self => { const userId = ctx.req.accessToken.userId; const isLocked = await models.Ticket.isLocked(id); - const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson'); + const roles = await models.Account.getRoles(userId); + const hasAllowedRoles = roles.filter(role => + role == 'salesPerson' || role == 'claimManager' + ); + const state = await Self.app.models.TicketState.findOne({ where: {ticketFk: id} }); const alertLevel = state ? state.alertLevel : null; - if (isLocked || (!isSalesPerson && alertLevel > 0)) + if (isLocked || (!hasAllowedRoles && alertLevel > 0)) throw new UserError(`The sales of this ticket can't be modified`); const usesMana = await models.WorkerMana.findOne({