Bug #571 usuario con privilegios cambia el estado de un ticket bloqueado

This commit is contained in:
gerard 2018-08-02 10:54:03 +02:00
parent b6cc14065e
commit 49ea108771
5 changed files with 27 additions and 25 deletions

View File

@ -125,7 +125,7 @@
</vn-td> </vn-td>
<vn-td number> <vn-td number>
{{(sale.quantity * sale.price) - {{(sale.quantity * sale.price) -
((sale.discount * (sale.quantity * sale.price))/100) | currency:' €':2 ((sale.discount * (sale.quantity * sale.price))/100) | currency:'€':2
}} }}
</vn-td> </vn-td>
</vn-tr> </vn-tr>
@ -147,15 +147,15 @@
<section> <section>
<p> <p>
<vn-label translate>Subtotal</vn-label> <vn-label translate>Subtotal</vn-label>
<span>{{$ctrl.subTotal | currency:' €':2}}</span> <span>{{$ctrl.subTotal | currency:'€':2}}</span>
</p> </p>
<p> <p>
<vn-label translate>VAT</vn-label> <vn-label translate>VAT</vn-label>
<span>{{$ctrl.VAT | currency:' €':2}}</span> <span>{{$ctrl.VAT | currency:'€':2}}</span>
</p> </p>
<p> <p>
<vn-label><strong>Total</strong></vn-label> <vn-label><strong>Total</strong></vn-label>
<strong>{{$ctrl.total | currency:' €':2}}</strong> <strong>{{$ctrl.total | currency:'€':2}}</strong>
</p> </p>
</section> </section>
</vn-td> </vn-td>
@ -216,7 +216,7 @@
vn-id="editPricePopover" vn-id="editPricePopover"
on-open="$ctrl.getManaSalespersonMana()"> on-open="$ctrl.getManaSalespersonMana()">
<vn-horizontal pad-medium class="header"> <vn-horizontal pad-medium class="header">
<h5>MANÁ: {{$ctrl.mana | currency:' €':0}}</h5> <h5>MANÁ: {{$ctrl.mana | currency:'€':0}}</h5>
</vn-horizontal> </vn-horizontal>
<div pad-medium> <div pad-medium>
<vn-textfield <vn-textfield
@ -232,7 +232,7 @@
<p class="simulatorTitle" translate>New price</p> <p class="simulatorTitle" translate>New price</p>
<p>{{($ctrl.sale.quantity * $ctrl.editedPrice) <p>{{($ctrl.sale.quantity * $ctrl.editedPrice)
- (($ctrl.sale.discount * ($ctrl.sale.quantity * $ctrl.editedPrice))/100) - (($ctrl.sale.discount * ($ctrl.sale.quantity * $ctrl.editedPrice))/100)
| currency:' €':2}}</p> | currency:'€':2}}</p>
</div> </div>
</div> </div>
</vn-popover> </vn-popover>

View File

@ -114,7 +114,7 @@ class Controller {
onStateChange(value) { onStateChange(value) {
let params = {ticketFk: this.$state.params.id, stateFk: value}; let params = {ticketFk: this.$state.params.id, stateFk: value};
this.$http.post(`/ticket/api/TicketTrackings`, params).then(() => { this.$http.post(`/ticket/api/TicketTrackings/changeState`, params).then(() => {
this.card.reload(); this.card.reload();
this.vnApp.showSuccess(this.translate.instant('Data saved!')); this.vnApp.showSuccess(this.translate.instant('Data saved!'));
}); });
@ -265,6 +265,7 @@ class Controller {
this.$http.post(`/ticket/api/Sales/updatePrice`, {id: this.edit.id, price: this.editedPrice, ticketFk: this.ticket.id}).then(() => { this.$http.post(`/ticket/api/Sales/updatePrice`, {id: this.edit.id, price: this.editedPrice, ticketFk: this.ticket.id}).then(() => {
this.sale.price = this.edit.price; this.sale.price = this.edit.price;
this.$scope.model.refresh(); this.$scope.model.refresh();
this.vnApp.showSuccess(this.translate.instant('Data saved!'));
}); });
} }
this.$scope.editPricePopover.hide(); this.$scope.editPricePopover.hide();
@ -303,8 +304,6 @@ class Controller {
updateQuantity(id, quantity) { updateQuantity(id, quantity) {
this.$http.post(`/ticket/api/Sales/${id}/updateQuantity`, {quantity: parseInt(quantity)}).then(() => { this.$http.post(`/ticket/api/Sales/${id}/updateQuantity`, {quantity: parseInt(quantity)}).then(() => {
this.vnApp.showSuccess(this.translate.instant('Data saved!')); this.vnApp.showSuccess(this.translate.instant('Data saved!'));
}).catch(e => {
this.vnApp.showError(this.translate.instant(e.data.error.message));
}); });
this.$scope.model.refresh(); this.$scope.model.refresh();
} }

View File

@ -1,6 +1,6 @@
import './index.js'; import './index.js';
describe('Ticket', () => { fdescribe('Ticket', () => {
describe('Component vnTicketSale', () => { describe('Component vnTicketSale', () => {
let $componentController; let $componentController;
let controller; let controller;
@ -20,9 +20,7 @@ describe('Ticket', () => {
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$state = _$state_; $state = _$state_;
$state.params.id = 1; $state.params.id = 1;
controller = $componentController('vnTicketSale', {$scope: $scope}, {$state: $state}); $scope.model = {data: [
controller.ticket = {id: 1};
controller.$scope = {model: {data: [
{ {
id: 1, id: 1,
quantity: 5, quantity: 5,
@ -37,11 +35,10 @@ describe('Ticket', () => {
discount: 0, discount: 0,
checked: true checked: true
} }
]}, accept: () => { ]};
return { $scope.addTurn = {show: () => {}};
then: () => {} controller = $componentController('vnTicketSale', {$scope: $scope}, {$state: $state});
}; controller.ticket = {id: 1};
}};
})); }));
describe('getSales()', () => { describe('getSales()', () => {
@ -148,19 +145,22 @@ describe('Ticket', () => {
}); });
}); });
xdescribe('addTurn(day)', () => { describe('addTurn(day)', () => {
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => { it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
controller.$scope.addTurn = {hide: () => {}}; controller.$scope.addTurn = {hide: () => {}};
spyOn(controller.$scope.addTurn, 'hide'); spyOn(controller.$scope.addTurn, 'hide');
controller.showAddTurnDialog();
$httpBackend.expectPATCH(`/ticket/api/TicketWeeklies`).respond();
controller.addTurn(1);
$httpBackend.flush();
expect(controller.$scope.addTurn.show).toHaveBeenCalledWith(); expect(controller.$scope.addTurn.hide).toHaveBeenCalledWith();
}); });
}); });
describe('onStateChange()', () => { describe('onStateChange()', () => {
it('should perform a POST', () => { it('should perform a post and then call a function', () => {
$httpBackend.expectPOST(`/ticket/api/TicketTrackings`).respond(); $httpBackend.expectPOST(`/ticket/api/TicketTrackings/changeState`).respond();
controller.card = {reload: () => {}}; controller.card = {reload: () => {}};
controller.onStateChange(3); controller.onStateChange(3);
$httpBackend.flush(); $httpBackend.flush();

View File

@ -22,6 +22,9 @@ module.exports = Self => {
Self.isEditable = async ticketFk => { Self.isEditable = async ticketFk => {
let state = await Self.app.models.TicketState.findOne({where: {ticketFk: ticketFk}, fields: 'alertLevel'}); let state = await Self.app.models.TicketState.findOne({where: {ticketFk: ticketFk}, fields: 'alertLevel'});
let exists = await Self.app.models.Ticket.findOne({where: {id: ticketFk}, fields: 'isDeleted'}); let exists = await Self.app.models.Ticket.findOne({where: {id: ticketFk}, fields: 'isDeleted'});
return (exists && state == null && exists.isDeleted == 0) || (exists.isDeleted == 0 && state.alertLevel == 0); if (!exists || exists.isDeleted == 1 || state.alertLevel > 0)
return false;
return true;
}; };
}; };

View File

@ -19,7 +19,7 @@ module.exports = Self => {
} }
}); });
Self.changeState = async (params, ctx) => { Self.changeState = async params => {
let isEditable = await Self.app.models.Ticket.isEditable(params.ticketFk); let isEditable = await Self.app.models.Ticket.isEditable(params.ticketFk);
if (isEditable) if (isEditable)
return await Self.app.models.TicketTracking.create(params); return await Self.app.models.TicketTracking.create(params);