Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
Joan Sanchez 2018-07-03 15:01:19 +02:00
commit 28a2c45c46
7 changed files with 87 additions and 27 deletions

View File

@ -0,0 +1,41 @@
import './index.js';
describe('Ticket', () => {
describe('Component vnTicketCreate', () => {
let $componentController;
let $scope;
let controller;
let $state;
beforeEach(() => {
angular.mock.module('ticket');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$scope.card = {createTicket: () => {}};
$state = _$state_;
$state.go = () => {};
controller = $componentController('vnTicketCreate', {$scope: $scope, $state: $state});
}));
describe('onSubmit()', () => {
it(`should call createTicket()`, () => {
spyOn(controller.$.card, 'createTicket');
controller.onSubmit();
expect(controller.$.card.createTicket).toHaveBeenCalledWith();
});
xit(`should call go()`, () => {
spyOn(controller.$state, 'go');
controller.onSubmit();
expect(controller.$state.go).toHaveBeenCalledWith();
});
});
});
});

View File

@ -59,10 +59,11 @@
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="sale in index.model.instances track by sale.id"> <tr ng-repeat="sale in index.model.instances track by sale.id">
<td ng-show="sale.disponible" ><vn-icon icon="icon-reserved"></vn-icon></td> <td><vn-icon ng-show="sale.reserved" icon="icon-reserved"></vn-icon></td>
<!-- <td> <!-- <td>
<vn-icon icon="warning"></vn-icon> <vn-icon ng-show="sale.disponible" icon="warning"></vn-icon>
<vn-icon icon="icon-reserved"></vn-icon> <vn-icon ng-show="sale.disponible" icon="warning"></vn-icon>
<vn-icon ng-show="sale.disponible" icon="icon-reserved"></vn-icon>
</td> --> </td> -->
<td number> <td number>
<vn-check <vn-check

View File

@ -302,13 +302,6 @@ class Controller extends FilterTicketList {
} }
} }
/**
* Mark sale as reserved
*/
markAsReserved() {
this.setReserved(true);
}
/** /**
* Unmark sale as reserved * Unmark sale as reserved
*/ */
@ -317,21 +310,17 @@ class Controller extends FilterTicketList {
} }
/** /**
* Mark/Unmark sale as reserved from selected lines * Mark sale as reserved
* @param {Boolean} reserved reserved
*/ */
markAsReserved() {
this.setReserved(true);
}
setReserved(reserved) { setReserved(reserved) {
let data = { let sales = this.getCheckedLines();
delete: [], let params = {sales: sales, ticketFk: this.ticket.id, reserved: reserved};
create: [],
update: this.getCheckedLines()
};
data.update.forEach(line => { this.$http.post(`/ticket/api/Sales/reserve`, params).then(() => {
line.reserved = reserved;
});
this.$http.post(`/ticket/api/Sales/crudSale`, data).then(() => {
this.$.index.accept(); this.$.index.accept();
}); });
} }

View File

@ -1,3 +0,0 @@
module.exports = Self => {
Self.installCrudModel('crudSale');
};

View File

@ -0,0 +1,32 @@
module.exports = Self => {
Self.remoteMethod('reserve', {
description: 'Change the state of a ticket',
accessType: '',
accepts: [{
arg: 'params',
type: 'object',
required: true,
description: '[sales IDs], actualTicketFk, reserved',
http: {source: 'body'}
}],
returns: {
type: 'string',
root: true
},
http: {
path: `/reserve`,
verb: 'post'
}
});
Self.reserve = async params => {
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk);
if (!thisTicketIsEditable)
throw new Error(`The sales of this ticket can't be modified`);
for (let i = 0; i < params.sales.length; i++) {
await Self.app.models.Sale.update({id: params.sales[i].id}, {reserved: params.reserved});
}
};
};

View File

@ -2,8 +2,8 @@ module.exports = Self => {
require('../methods/sale/filter')(Self); require('../methods/sale/filter')(Self);
require('../methods/sale/saleComponentFilter')(Self); require('../methods/sale/saleComponentFilter')(Self);
require('../methods/sale/priceDifference')(Self); require('../methods/sale/priceDifference')(Self);
require('../methods/sale/crudSale')(Self);
require('../methods/sale/moveToTicket')(Self); require('../methods/sale/moveToTicket')(Self);
require('../methods/sale/reserve')(Self);
require('../methods/sale/moveToNewTicket')(Self); require('../methods/sale/moveToNewTicket')(Self);
require('../methods/sale/removes')(Self); require('../methods/sale/removes')(Self);
require('../methods/sale/updateDiscount')(Self); require('../methods/sale/updateDiscount')(Self);

View File

@ -25,7 +25,7 @@
"type": "Number" "type": "Number"
}, },
"reserved": { "reserved": {
"type": "Number" "type": "boolean"
}, },
"isPicked": { "isPicked": {
"type": "Number" "type": "Number"