From 80248238d2f6951333af1c99b83e02eec8f502fa Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 4 Mar 2020 09:26:12 +0100 Subject: [PATCH 1/3] 2164 - Show confirmation only when data is not empty --- db/dump/fixtures.sql | 48 +++++++++---------- modules/client/front/fiscal-data/index.js | 15 +++++- .../client/front/fiscal-data/index.spec.js | 26 +++++++++- .../methods/ticket/specs/makeInvoice.spec.js | 12 ++++- 4 files changed, 71 insertions(+), 30 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 498a9dc7c..31040955c 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -554,30 +554,30 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`) VALUES - (1, 16, 5 , DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (2, 16, 5 , DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (3, 16, 5 , DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), - (4, 16, 5 , DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), - (5, 16, 18, DATE_ADD(CURDATE(), INTERVAL -4 MONTH)), - (6, 16, 18, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (7, 10, 18, CURDATE()), - (8, 5, 19, CURDATE()), - (9, 5, 19, CURDATE()), - (10, 5, 19, CURDATE()), - (11, 3, 19, CURDATE()), - (12, 3, 19, CURDATE()), - (13, 3, 19, CURDATE()), - (14, 3, 19, CURDATE()), - (15, 3, 19, CURDATE()), - (16, 3, 19, CURDATE()), - (17, 3, 19, CURDATE()), - (18, 3, 19, CURDATE()), - (19, 17, 19, CURDATE()), - (20, 1, 19, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), - (21, 1, 19, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), - (22, 1, 19, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), - (23, 16, 21, CURDATE()), - (24, 16, 21, CURDATE()); + (1, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)), + (2, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)), + (3, 16, 5 , DATE_ADD(NOW(), INTERVAL -2 MONTH)), + (4, 16, 5 , DATE_ADD(NOW(), INTERVAL -3 MONTH)), + (5, 16, 18, DATE_ADD(NOW(), INTERVAL -4 MONTH)), + (6, 16, 18, DATE_ADD(NOW(), INTERVAL -1 MONTH)), + (7, 10, 18, NOW()), + (8, 5, 19, NOW()), + (9, 5, 19, NOW()), + (10, 5, 19, NOW()), + (11, 3, 19, NOW()), + (12, 3, 19, NOW()), + (13, 3, 19, NOW()), + (14, 3, 19, NOW()), + (15, 3, 19, NOW()), + (16, 3, 19, NOW()), + (17, 3, 19, NOW()), + (18, 3, 19, NOW()), + (19, 17, 19, NOW()), + (20, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)), + (21, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)), + (22, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)), + (23, 16, 21, NOW()), + (24, 16, 21, NOW()); INSERT INTO `vn`.`stowaway`(`id`, `shipFk`, `created`) VALUES diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index b2602f7a4..b5cd9ce3d 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -5,16 +5,27 @@ export default class Controller extends Component { onSubmit() { const orgData = this.$.watcher.orgData; delete this.client.despiteOfClient; - if (!orgData.isTaxDataChecked && this.client.isTaxDataChecked) + const hasContactData = this.client.email || this.client.phone || this.client.mobile; + if (!orgData.isTaxDataChecked && this.client.isTaxDataChecked && hasContactData) this.checkExistingClient(); else this.save(); } checkExistingClient() { + const findParams = []; + if (this.client.email) + findParams.push({email: this.client.email}); + + if (this.client.phone) + findParams.push({phone: this.client.phone}); + + if (this.client.mobile) + findParams.push({mobile: this.client.mobile}); + const filterObj = { where: { and: [ - {or: [{email: this.client.email}, {phone: this.client.phone}]}, + {or: findParams}, {id: {neq: this.client.id}} ] } diff --git a/modules/client/front/fiscal-data/index.spec.js b/modules/client/front/fiscal-data/index.spec.js index 1e92426ec..1895d231e 100644 --- a/modules/client/front/fiscal-data/index.spec.js +++ b/modules/client/front/fiscal-data/index.spec.js @@ -49,9 +49,31 @@ describe('Client', () => { }); describe('checkExistingClient()', () => { - it('should show a save confirmation when a duplicated client is found and then set the despiteOfClient property', () => { + it(`should make a HTTP GET query filtering by email, phone and mobile`, () => { + controller.client.mobile = 222222222; + const filterObj = { + where: { + and: [ + {or: [ + {email: controller.client.email}, + {phone: controller.client.phone}, + {mobile: controller.client.mobile} + ]}, + {id: {neq: controller.client.id}} + ] + } + }; + const expectedClient = {id: 102}; + const filter = encodeURIComponent(JSON.stringify(filterObj)); + $httpBackend.expect('GET', `Clients/findOne?filter=${filter}`).respond(expectedClient); + controller.checkExistingClient(); + $httpBackend.flush(); + }); + + it(`should show a save confirmation and then set the despiteOfClient property`, () => { controller.$.confirmDuplicatedClient = {show: () => {}}; - spyOn(controller.$.confirmDuplicatedClient, 'show'); + jest.spyOn(controller.$.confirmDuplicatedClient, 'show'); + const filterObj = { where: { and: [ diff --git a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js index 247e7e621..62bc3b5cd 100644 --- a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js +++ b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js @@ -8,8 +8,16 @@ describe('ticket makeInvoice()', () => { let ticket = await app.models.Ticket.findById(11); await ticket.updateAttributes({refFk: null}); - let ticketTracking = await app.models.TicketTracking.findOne({order: 'id DESC', limit: 1}); - await ticketTracking.destroy(); + let ticketTrackings = await app.models.TicketTracking.find({ + where: { + ticketFk: ticketId, + stateFk: {neq: 3} + }, + order: 'id DESC' + }); + + for (let state of ticketTrackings) + await state.destroy(); let invoiceOut = await app.models.InvoiceOut.findById(invoice.invoiceFk); await invoiceOut.destroy(); From 2f511d17182676ecd6fdb3ece7cee46bac7f125d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 4 Mar 2020 09:32:18 +0100 Subject: [PATCH 2/3] Changed format --- modules/client/front/fiscal-data/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index b5cd9ce3d..8afa02288 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -5,8 +5,10 @@ export default class Controller extends Component { onSubmit() { const orgData = this.$.watcher.orgData; delete this.client.despiteOfClient; + const hasContactData = this.client.email || this.client.phone || this.client.mobile; - if (!orgData.isTaxDataChecked && this.client.isTaxDataChecked && hasContactData) + const isDataChecked = !orgData.isTaxDataChecked && this.client.isTaxDataChecked; + if (isDataChecked && hasContactData) this.checkExistingClient(); else this.save(); } From 46f04fa802a0819b3f6fd82efd56fca7a9375902 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 4 Mar 2020 11:17:35 +0100 Subject: [PATCH 3/3] Updated var names --- modules/client/front/fiscal-data/index.js | 4 ++-- modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index 8afa02288..f8e93ab9f 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -7,8 +7,8 @@ export default class Controller extends Component { delete this.client.despiteOfClient; const hasContactData = this.client.email || this.client.phone || this.client.mobile; - const isDataChecked = !orgData.isTaxDataChecked && this.client.isTaxDataChecked; - if (isDataChecked && hasContactData) + const hasChangedTaxData = !orgData.isTaxDataChecked && this.client.isTaxDataChecked; + if (hasChangedTaxData && hasContactData) this.checkExistingClient(); else this.save(); } diff --git a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js index 62bc3b5cd..b91751d5d 100644 --- a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js +++ b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js @@ -3,6 +3,7 @@ const app = require('vn-loopback/server/server'); describe('ticket makeInvoice()', () => { let invoice; let ticketId = 11; + const okState = 3; afterAll(async done => { let ticket = await app.models.Ticket.findById(11); @@ -11,7 +12,7 @@ describe('ticket makeInvoice()', () => { let ticketTrackings = await app.models.TicketTracking.find({ where: { ticketFk: ticketId, - stateFk: {neq: 3} + stateFk: {neq: okState} }, order: 'id DESC' });