Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-11-18 08:20:46 +01:00
commit ac5f30924a
3 changed files with 20 additions and 17 deletions

View File

@ -55,8 +55,8 @@
</vn-td> </vn-td>
<vn-td number>{{::saleClaimed.sale.price | currency: 'EUR':2}}</vn-td> <vn-td number>{{::saleClaimed.sale.price | currency: 'EUR':2}}</vn-td>
<vn-td number> <vn-td number>
<span ng-class="{'link': $ctrl.isEditable}" <span ng-class="{'link': $ctrl.isRewritable && $ctrl.isClaimManager}"
title="{{$ctrl.isEditable ? 'Edit discount' : ''}}" translate-attr="{title: $ctrl.isRewritable && $ctrl.isClaimManager ? 'Edit discount' : ''}"
ng-click="$ctrl.showEditPopover($event, saleClaimed)"> ng-click="$ctrl.showEditPopover($event, saleClaimed)">
{{saleClaimed.sale.discount}} % {{saleClaimed.sale.discount}} %
</span> </span>

View File

@ -54,6 +54,10 @@ class Controller extends Section {
this.updateNewPrice(); this.updateNewPrice();
} }
get isClaimManager() {
return this.aclService.hasAny(['claimManager']);
}
openAddSalesDialog() { openAddSalesDialog() {
this.getClaimableFromTicket(); this.getClaimableFromTicket();
this.$.addSales.show(); this.$.addSales.show();
@ -131,17 +135,6 @@ class Controller extends Section {
return total; 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() { getSalespersonMana() {
this.$http.get(`Tickets/${this.claim.ticketFk}/getSalesPersonMana`).then(res => { this.$http.get(`Tickets/${this.claim.ticketFk}/getSalesPersonMana`).then(res => {
this.mana = res.data; 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() { updateDiscount() {
const claimedSale = this.saleClaimed.sale; const claimedSale = this.saleClaimed.sale;
if (this.newDiscount != claimedSale.discount) { if (this.newDiscount != claimedSale.discount) {
@ -176,8 +177,6 @@ class Controller extends Section {
this.clearDiscount(); this.clearDiscount();
this.vnApp.showSuccess(this.$t('Data saved!')); this.vnApp.showSuccess(this.$t('Data saved!'));
}).catch(err => {
this.vnApp.showError(err.message);
}); });
} }

View File

@ -70,13 +70,17 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const isLocked = await models.Ticket.isLocked(id); 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({ const state = await Self.app.models.TicketState.findOne({
where: {ticketFk: id} where: {ticketFk: id}
}); });
const alertLevel = state ? state.alertLevel : null; 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`); throw new UserError(`The sales of this ticket can't be modified`);
const usesMana = await models.WorkerMana.findOne({ const usesMana = await models.WorkerMana.findOne({