From 94480a81890b59440d3eeaf5f33241f62fec81f5 Mon Sep 17 00:00:00 2001 From: Bernat Date: Wed, 24 Apr 2019 07:43:11 +0200 Subject: [PATCH] #1329 fix test and fixtures, update ticket-service --- db/dump/fixtures.sql | 7 ++++--- .../05-ticket-module/13_create_ticket_services.spec.js | 2 +- loopback/locale/es.json | 2 +- modules/ticket/back/models/ticket-service.js | 7 ++++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 1d075939f..09387acee 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1217,9 +1217,10 @@ INSERT INTO `vn`.`ticketRequest`(`id`, `description`, `requesterFk`, `atenderFk` INSERT INTO `vn`.`ticketService`(`id`, `description`, `quantity`, `price`, `taxClassFk`, `ticketFk`) VALUES - (1, 'delivery charge', 1, 2.00, 1, 1), - (2, 'training course', 1, 10.00, 1, 2), - (3, 'delivery charge', 1, 5.50, 1, 11); + (1, 'Documentos', 1, 2.00, 1, 1), + (2, 'Porte Agencia', 1, 10.00, 1, 2), + (3, 'Documentos', 1, 5.50, 1, 11), + (4, 'Documentos', 1, 2.00, 1, 9); INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `warehouseFk`, `agencyModeFk`, `travelingDays`, `price`, `bonus`) diff --git a/e2e/paths/05-ticket-module/13_create_ticket_services.spec.js b/e2e/paths/05-ticket-module/13_create_ticket_services.spec.js index 5a35ba337..5b6bfff49 100644 --- a/e2e/paths/05-ticket-module/13_create_ticket_services.spec.js +++ b/e2e/paths/05-ticket-module/13_create_ticket_services.spec.js @@ -7,7 +7,7 @@ describe('Ticket services path', () => { beforeAll(() => { nightmare .loginAndModule('employee', 'ticket') - .accessToSearchResult('1') + .accessToSearchResult(9) .accessToSection('ticket.card.service'); }); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index e275cbb93..e842c760c 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -82,5 +82,5 @@ "This ticket can't be invoiced": "Este ticket no puede ser facturado", "That item is not available on that day": "El item no esta disponible para esa fecha", "That item doesn't exists": "That item doesn't exists", - "You cannot add services to an invoiced ticket": "No puedes añadir servicios a un ticket facturado" + "You cannot add or modify services to an invoiced ticket": "No puedes añadir o modificar servicios a un ticket facturado" } \ No newline at end of file diff --git a/modules/ticket/back/models/ticket-service.js b/modules/ticket/back/models/ticket-service.js index 3f54a960e..751885116 100644 --- a/modules/ticket/back/models/ticket-service.js +++ b/modules/ticket/back/models/ticket-service.js @@ -2,11 +2,12 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.observe('before save', async ctx => { - if (ctx.isNewInstance) { - let ticketId = ctx.instance.ticketFk; + let changes = ctx.currentInstance || ctx.instance; + if (changes) { + let ticketId = changes.ticketFk; let ticket = await Self.app.models.Ticket.findById(ticketId); if (ticket.refFk) - throw new UserError('You cannot add services to an invoiced ticket'); + throw new UserError('You cannot add or modify services to an invoiced ticket'); } }); };