From 146b4f5bcdc350a3da10445c122d43b80e954e58 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 28 Oct 2020 14:12:57 +0100 Subject: [PATCH 1/2] 2534 - Fill sage data before enable taxDataChecked --- .../12_lock_of_verified_data.spec.js | 2 ++ gulpfile.js | 1 + loopback/locale/en.json | 3 ++- loopback/locale/es.json | 3 ++- .../client/specs/updateFiscalData.spec.js | 26 ++++++++++++++++--- .../back/methods/client/updateFiscalData.js | 15 ++++++++--- modules/client/back/models/client.js | 2 +- modules/client/front/fiscal-data/index.html | 8 ++++-- 8 files changed, 49 insertions(+), 11 deletions(-) diff --git a/e2e/paths/02-client/12_lock_of_verified_data.spec.js b/e2e/paths/02-client/12_lock_of_verified_data.spec.js index b90ab7dfc..5d457219e 100644 --- a/e2e/paths/02-client/12_lock_of_verified_data.spec.js +++ b/e2e/paths/02-client/12_lock_of_verified_data.spec.js @@ -57,6 +57,8 @@ describe('Client lock verified data path', () => { }); it('should check the Verified data checkbox', async() => { + await page.autocompleteSearch(selectors.clientFiscalData.sageTax, 'operaciones no sujetas'); + await page.autocompleteSearch(selectors.clientFiscalData.sageTransaction, 'regularización de inversiones'); await page.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox); await page.waitToClick(selectors.clientFiscalData.saveButton); await page.waitToClick(selectors.globalItems.acceptButton); diff --git a/gulpfile.js b/gulpfile.js index 6bd2b3542..67d261d73 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -21,6 +21,7 @@ let buildDir = 'dist'; let backSources = [ '!node_modules', + '!loopback/locale/*.json', 'loopback', 'modules/*/back/**', 'modules/*/back/*', diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 3dfb73833..172da6faf 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -81,5 +81,6 @@ "shipped": "Shipped", "landed": "Landed", "addressFk": "Address", - "companyFk": "Company" + "companyFk": "Company", + "You need to fill sage information before you check verified data": "You need to fill sage information before you check verified data" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index c3fe287eb..7cd362ad8 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -156,5 +156,6 @@ "shipped": "F. envío", "landed": "F. entrega", "addressFk": "Consignatario", - "companyFk": "Empresa" + "companyFk": "Empresa", + "You need to fill sage information before you check verified data": "You need to fill sage information before you check verified data" } \ No newline at end of file diff --git a/modules/client/back/methods/client/specs/updateFiscalData.spec.js b/modules/client/back/methods/client/specs/updateFiscalData.spec.js index 288183fb6..9c73e29ec 100644 --- a/modules/client/back/methods/client/specs/updateFiscalData.spec.js +++ b/modules/client/back/methods/client/specs/updateFiscalData.spec.js @@ -2,8 +2,9 @@ const app = require('vn-loopback/server/server'); describe('Client updateFiscalData', () => { const clientId = 101; + const salesAssistantId = 21; + const administrativeId = 5; afterAll(async done => { - const clientId = 101; const ctx = {req: {accessToken: {userId: 5}}}; ctx.args = {postcode: 46460}; @@ -22,11 +23,30 @@ describe('Client updateFiscalData', () => { error = e; }); - expect(error.message).toBeDefined(); + expect(error.message).toEqual(`You can't make changes on a client with verified data`); + }); + + it('should return an error if the user is not d and the isTaxDataChecked value is true', async() => { + const client = await app.models.Client.findById(clientId); + await client.updateAttribute('isTaxDataChecked', false); + + const ctx = {req: {accessToken: {userId: salesAssistantId}}}; + ctx.args = {isTaxDataChecked: true}; + + let error; + await app.models.Client.updateFiscalData(ctx, clientId) + .catch(e => { + error = e; + }); + + expect(error.message).toEqual('You need to fill sage information before you check verified data'); + + // Restores + await client.updateAttribute('isTaxDataChecked', true); }); it('should update the client fiscal data and return the count if changes made', async() => { - const ctx = {req: {accessToken: {userId: 5}}}; + const ctx = {req: {accessToken: {userId: administrativeId}}}; ctx.args = {postcode: 46680}; const client = await app.models.Client.findById(clientId); diff --git a/modules/client/back/methods/client/updateFiscalData.js b/modules/client/back/methods/client/updateFiscalData.js index 48cc6df88..a3d40a4d8 100644 --- a/modules/client/back/methods/client/updateFiscalData.js +++ b/modules/client/back/methods/client/updateFiscalData.js @@ -45,15 +45,15 @@ module.exports = Self => { }, { arg: 'sageTaxTypeFk', - type: 'number' + type: 'any' }, { arg: 'sageTransactionTypeFk', - type: 'number' + type: 'any' }, { arg: 'transferorFk', - type: 'number' + type: 'any' }, { arg: 'hasToInvoiceByAddress', @@ -118,6 +118,15 @@ module.exports = Self => { if (!isSalesAssistant && client.isTaxDataChecked) throw new UserError(`You can't make changes on a client with verified data`); + // Sage data validation + const taxDataChecked = args.isTaxDataChecked; + const sageTaxChecked = client.sageTaxTypeFk || args.sageTaxTypeFk; + const sageTransactionChecked = client.sageTransactionTypeFk || args.sageTransactionTypeFk; + const hasSageData = sageTaxChecked && sageTransactionChecked; + + if (taxDataChecked && !hasSageData) + throw new UserError(`You need to fill sage information before you check verified data`); + if (args.despiteOfClient) { const logRecord = { originFk: clientId, diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 36bc60dfa..6723e865a 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -187,7 +187,7 @@ module.exports = Self => { // Validate socialName format const hasChanges = orgData && changes; - const socialName = changes.socialName || orgData.socialName; + const socialName = changes && changes.socialName || orgData && orgData.socialName; const isTaxDataChecked = hasChanges && (changes.isTaxDataChecked || orgData.isTaxDataChecked); const socialNameChanged = hasChanges diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index 83b82c9ea..cc9e53097 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -30,7 +30,7 @@ data="sageTransactionTypes" order="transaction"> -
+ + info="You can use letters and spaces" + required="true"> -- 2.40.1 From 0570d83a6dacc9bb9f1fb8cfa64027401ad537d6 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 4 Nov 2020 13:38:09 +0100 Subject: [PATCH 2/2] Requested changes --- loopback/locale/es.json | 2 +- .../back/methods/client/specs/updateFiscalData.spec.js | 9 +++++---- modules/client/front/fiscal-data/index.html | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 7cd362ad8..958c06b6d 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -157,5 +157,5 @@ "landed": "F. entrega", "addressFk": "Consignatario", "companyFk": "Empresa", - "You need to fill sage information before you check verified data": "You need to fill sage information before you check verified data" + "You need to fill sage information before you check verified data": "Debes rellenar la información de sage antes de marcar datos comprobados" } \ No newline at end of file diff --git a/modules/client/back/methods/client/specs/updateFiscalData.spec.js b/modules/client/back/methods/client/specs/updateFiscalData.spec.js index 9c73e29ec..0b4425db6 100644 --- a/modules/client/back/methods/client/specs/updateFiscalData.spec.js +++ b/modules/client/back/methods/client/specs/updateFiscalData.spec.js @@ -2,10 +2,11 @@ const app = require('vn-loopback/server/server'); describe('Client updateFiscalData', () => { const clientId = 101; + const employeeId = 1; const salesAssistantId = 21; const administrativeId = 5; afterAll(async done => { - const ctx = {req: {accessToken: {userId: 5}}}; + const ctx = {req: {accessToken: {userId: administrativeId}}}; ctx.args = {postcode: 46460}; await app.models.Client.updateFiscalData(ctx, clientId); @@ -13,8 +14,8 @@ describe('Client updateFiscalData', () => { done(); }); - it('should return an error if the user is not administrative and the isTaxDataChecked value is true', async() => { - const ctx = {req: {accessToken: {userId: 1}}}; + it('should return an error if the user is not salesAssistant and the isTaxDataChecked value is true', async() => { + const ctx = {req: {accessToken: {userId: employeeId}}}; ctx.args = {}; let error; @@ -26,7 +27,7 @@ describe('Client updateFiscalData', () => { expect(error.message).toEqual(`You can't make changes on a client with verified data`); }); - it('should return an error if the user is not d and the isTaxDataChecked value is true', async() => { + it('should return an error if the salesAssistant did not fill the sage data before checking verified data', async() => { const client = await app.models.Client.findById(clientId); await client.updateAttribute('isTaxDataChecked', false); diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index cc9e53097..0523f9fb6 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -30,7 +30,7 @@ data="sageTransactionTypes" order="transaction"> - +