From 6e50c1fad94d8d1712404f14a1058aee09da3faf Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Fri, 27 Sep 2019 16:55:40 +0200 Subject: [PATCH 1/3] #1685 ticket.transferSale --- .../ticket/specs/transferSales.spec.js | 81 +++++++++++++++++-- .../back/methods/ticket/transferSales.js | 2 +- 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/transferSales.spec.js b/modules/ticket/back/methods/ticket/specs/transferSales.spec.js index 17996649e..8bcc8bcda 100644 --- a/modules/ticket/back/methods/ticket/specs/transferSales.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferSales.spec.js @@ -2,9 +2,12 @@ const app = require('vn-loopback/server/server'); describe('sale transferSales()', () => { let createdTicketId; + let createdTicketsIds = []; afterAll(async done => { - await app.models.Ticket.destroyById(createdTicketId); + createdTicketsIds.forEach(async createdTicketId => { + await app.models.Ticket.destroyById(createdTicketId); + }); done(); }); @@ -62,22 +65,23 @@ describe('sale transferSales()', () => { it('should transfer the sales from one ticket to a new one', async() => { const ctx = {req: {accessToken: {userId: 101}}}; let currentTicket = await app.models.Ticket.findById(11); - let currentTicketSales = await app.models.Ticket.getSales(currentTicket.id); + let originalTicketSales = await app.models.Ticket.getSales(currentTicket.id); + salesToRestone = originalTicketSales; - expect(currentTicketSales.length).toEqual(2); + expect(originalTicketSales.length).toEqual(2); const currentTicketId = currentTicket.id; const receiverTicketId = undefined; - const sales = currentTicketSales; let createdTicket = await app.models.Ticket.transferSales( - ctx, currentTicketId, receiverTicketId, sales); + ctx, currentTicketId, receiverTicketId, originalTicketSales); createdTicketId = createdTicket.id; + createdTicketsIds.push(createdTicket.id); - currentTicketSales = await app.models.Ticket.getSales(currentTicket.id); + originalTicketSales = await app.models.Ticket.getSales(currentTicket.id); receiverTicketSales = await app.models.Ticket.getSales(createdTicket.id); - expect(currentTicketSales.length).toEqual(0); + expect(originalTicketSales.length).toEqual(0); expect(receiverTicketSales.length).toEqual(2); }); @@ -108,4 +112,67 @@ describe('sale transferSales()', () => { expect(createdTicketSales.length).toEqual(0); expect(receiverTicketSales.length).toEqual(2); }); + + describe('sale transferPartialSales()', () => { + it('should throw an error in the quantity to transfer exceeds the amount from the original sale', async() => { + const ctx = {req: {accessToken: {userId: 101}}}; + let error; + let currentTicket = await app.models.Ticket.findById(11); + let currentTicketSales = await app.models.Ticket.getSales(currentTicket.id); + + const currentTicketId = currentTicket.id; + const receiverTicketId = undefined; + + currentTicketSales[0].quantity = 99; + + await app.models.Ticket.transferSales( + ctx, currentTicketId, receiverTicketId, currentTicketSales) + .catch(response => { + expect(response.message).toEqual(`Invalid quantity`); + error = response; + }); + + expect(error).toBeDefined(); + }); + + it('should partially transfer the sales from one ticket to a new one', async() => { + const ctx = {req: {accessToken: {userId: 101}}}; + let currentTicket = await app.models.Ticket.findById(11); + let currentTicketSales = []; + let saleToRestore = await app.models.Sale.findById(7); + currentTicketSales.push(saleToRestore); + + expect(currentTicketSales[0].quantity).toEqual(15); + + const currentTicketId = currentTicket.id; + const receiverTicketId = undefined; + + const originalQuantity = currentTicketSales[0].quantity; + currentTicketSales[0].quantity = 1; + let salesToPartiallyTransfer = [currentTicketSales[0]]; + const saleIdToRestore = currentTicketSales[0].id; + + let createdTicket = await app.models.Ticket.transferSales( + ctx, currentTicketId, receiverTicketId, salesToPartiallyTransfer); + + createdTicketId = createdTicket.id; + createdTicketsIds.push(createdTicket.id); + + currentTicketSales = await app.models.Ticket.getSales(currentTicket.id); + receiverTicketSales = await app.models.Ticket.getSales(createdTicket.id); + + expect(currentTicketSales.length).toEqual(2); + expect(currentTicketSales[0].quantity).toEqual(14); + expect(receiverTicketSales.length).toEqual(1); + expect(receiverTicketSales[0].quantity).toEqual(1); + + saleToRestore.updateAttribute('quantity', originalQuantity); + + currentTicketSales = await app.models.Ticket.getSales(currentTicket.id); + + + expect(currentTicketSales[0].quantity).toEqual(15); + expect(currentTicketSales[0].id).toEqual(saleIdToRestore); + }); + }); }); diff --git a/modules/ticket/back/methods/ticket/transferSales.js b/modules/ticket/back/methods/ticket/transferSales.js index 815d5fb4b..c35518878 100644 --- a/modules/ticket/back/methods/ticket/transferSales.js +++ b/modules/ticket/back/methods/ticket/transferSales.js @@ -72,7 +72,7 @@ module.exports = Self => { await models.Sale.updateAll({ id: sale.id }, {ticketFk: ticketId}, options); - } else if (sale.quantity < originalSale.quantity) { + } else if (sale.quantity != originalSale.quantity) { await transferPartialSale( ticketId, originalSale, sale, options); } From a98a8831ed359ba2f3595b8f3a0c52c49dfcd040 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 30 Sep 2019 07:53:38 +0200 Subject: [PATCH 2/3] prevent popover focus propagation #1718 --- front/core/components/popover/popover.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/core/components/popover/popover.js b/front/core/components/popover/popover.js index 0041a8413..0cc2a7490 100644 --- a/front/core/components/popover/popover.js +++ b/front/core/components/popover/popover.js @@ -100,7 +100,7 @@ export default class Popover extends Component { }, 30); this.document.addEventListener('keydown', this.docKeyDownHandler); - this.document.addEventListener('focusin', this.docFocusInHandler); + this.document.addEventListener('focus', this.docFocusInHandler); this.element.addEventListener('mousedown', this.bgMouseDownHandler); this.deregisterCallback = this.$transitions.onStart({}, () => this.hide()); From e380e4466c587ee238870c04de7969b281e2e111 Mon Sep 17 00:00:00 2001 From: Bernat Date: Mon, 30 Sep 2019 08:26:51 +0200 Subject: [PATCH 3/3] =?UTF-8?q?#1717=20route.basic-data=20a=C3=B1adir=20ca?= =?UTF-8?q?mpo=20description?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/helpers/selectors.js | 4 +-- .../08-route-module/02_basic_data.spec.js | 4 +-- modules/route/front/basic-data/index.html | 27 ++++++++++--------- modules/route/front/basic-data/index.js | 16 +++++++++++ modules/route/front/basic-data/locale/es.yml | 1 + modules/route/front/descriptor/index.html | 4 +-- modules/route/front/descriptor/index.js | 1 - modules/route/front/descriptor/locale/es.yml | 3 ++- modules/route/front/routes.json | 4 +-- 9 files changed, 42 insertions(+), 22 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 9be6bc0dd..34926155f 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -652,8 +652,8 @@ export default { kmStartInput: 'vn-route-basic-data vn-input-number[field="$ctrl.route.kmStart"] input', kmEndInput: 'vn-route-basic-data vn-input-number[model="$ctrl.route.kmEnd"] input', createdDateInput: 'vn-route-basic-data vn-date-picker[model="$ctrl.route.created"] > div > input', - startedDateInput: 'vn-route-basic-data vn-date-picker[model="$ctrl.route.started"] > div > input', - finishedDateInput: 'vn-route-basic-data vn-date-picker[model="$ctrl.route.finished"] > div > input', + startedHourInput: 'vn-route-basic-data vn-input-time[model="$ctrl.route.started"] input', + finishedHourInput: 'vn-route-basic-data vn-input-time[model="$ctrl.route.finished"] input', saveButton: 'vn-route-basic-data vn-submit[label="Save"] input' }, routeTickets: { diff --git a/e2e/paths/08-route-module/02_basic_data.spec.js b/e2e/paths/08-route-module/02_basic_data.spec.js index 593a6b186..63ed673d9 100644 --- a/e2e/paths/08-route-module/02_basic_data.spec.js +++ b/e2e/paths/08-route-module/02_basic_data.spec.js @@ -20,8 +20,8 @@ describe('Route basic Data path', () => { .write(selectors.routeBasicData.kmStartInput, 1) .clearInput(selectors.routeBasicData.kmEndInput) .write(selectors.routeBasicData.kmEndInput, 2) - .datePicker(selectors.routeBasicData.startedDateInput, 1, null) - .datePicker(selectors.routeBasicData.finishedDateInput, 1, null) + .write(selectors.routeBasicData.startedHourInput, '0800') + .write(selectors.routeBasicData.finishedHourInput, '1230') .waitToClick(selectors.routeBasicData.saveButton) .waitForLastSnackbar(); diff --git a/modules/route/front/basic-data/index.html b/modules/route/front/basic-data/index.html index da58ead63..5bdcfc1e5 100644 --- a/modules/route/front/basic-data/index.html +++ b/modules/route/front/basic-data/index.html @@ -5,7 +5,7 @@ form="form" save="patch"> -
+ - + + + + + + - - - + label="Description" + field="$ctrl.route.description" vn-focus> + diff --git a/modules/route/front/basic-data/index.js b/modules/route/front/basic-data/index.js index 30e8abfb3..3c64200f4 100644 --- a/modules/route/front/basic-data/index.js +++ b/modules/route/front/basic-data/index.js @@ -1,8 +1,24 @@ import ngModule from '../module'; +class Controller { + constructor($scope, $state) { + this.$scope = $scope; + this.$state = $state; + } + + onSubmit() { + this.$scope.watcher.submit().then(() => { + this.card.reload(); + }); + } +} ngModule.component('vnRouteBasicData', { template: require('./index.html'), + controller: Controller, bindings: { route: '<' + }, + require: { + card: '^vnRouteCard' } }); diff --git a/modules/route/front/basic-data/locale/es.yml b/modules/route/front/basic-data/locale/es.yml index 49bc89294..442a4fa82 100644 --- a/modules/route/front/basic-data/locale/es.yml +++ b/modules/route/front/basic-data/locale/es.yml @@ -2,3 +2,4 @@ Date finished: Fecha fin Date started: Fecha inicio Km start: Km de inicio Km end: Km de fin +Description: DescripciĆ³n \ No newline at end of file diff --git a/modules/route/front/descriptor/index.html b/modules/route/front/descriptor/index.html index dac65333e..1b5576167 100644 --- a/modules/route/front/descriptor/index.html +++ b/modules/route/front/descriptor/index.html @@ -40,7 +40,7 @@ + ng-class="{bright: $ctrl.route.m3 > $ctrl.route.vehicle.m3 && $ctrl.route.vehicle.m3 != NULL}">