From d6278e0df906d4d8b46c815cddd52baa481639fd Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 4 Mar 2020 09:26:12 +0100 Subject: [PATCH] 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 | 24 +++++++++- .../methods/ticket/specs/makeInvoice.spec.js | 12 ++++- 4 files changed, 70 insertions(+), 29 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 9d9b84da4..1f34738e0 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 52c2ee29e..7b92fb308 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: () => {}}; 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();