From 395ad1c76d879d705dd4b002548eb6ebad63c852 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 8 Nov 2021 15:04:33 +0100 Subject: [PATCH 1/3] fix(ibanRequired): set different ibanRequired for Client and Supplier --- db/changes/10370-pickles/payMethod.sql | 4 ++++ db/dump/fixtures.sql | 14 +++++++------- db/dump/structure.sql | 3 ++- modules/client/back/models/client.js | 2 +- modules/client/back/models/pay-method.json | 5 ++++- modules/client/front/billing-data/index.html | 2 +- modules/supplier/back/models/supplier.js | 2 +- modules/supplier/front/billing-data/index.html | 2 +- 8 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 db/changes/10370-pickles/payMethod.sql diff --git a/db/changes/10370-pickles/payMethod.sql b/db/changes/10370-pickles/payMethod.sql new file mode 100644 index 0000000000..ac6429b99b --- /dev/null +++ b/db/changes/10370-pickles/payMethod.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.payMethod CHANGE ibanRequired ibanRequiredForClients tinyint(3) DEFAULT 0 NULL; +ALTER TABLE vn.payMethod ADD ibanRequiredForSuppliers tinyint(3) DEFAULT 0 NULL; +ALTER TABLE vn.payMethod CHANGE ibanRequiredForSuppliers ibanRequiredForSuppliers tinyint(3) DEFAULT 0 NULL AFTER ibanRequiredForClients; +UPDATE vn.payMethod SET ibanRequiredForSuppliers = 1 WHERE code = 'wireTransfer'; \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 4c82be9097..fe2da1f38d 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -217,14 +217,14 @@ UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com' UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23; -INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `ibanRequired`) +INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `ibanRequiredForClients`, `ibanRequiredForSuppliers`) VALUES - (1, NULL, 'PayMethod one', 0, 001, 0), - (2, NULL, 'PayMethod two', 10, 001, 0), - (3, 'compensation', 'PayMethod three', 0, 001, 0), - (4, NULL, 'PayMethod with IBAN', 0, 001, 1), - (5, NULL, 'PayMethod five', 10, 001, 0), - (8,'wireTransfer', 'WireTransfer', 5, 001, 1); + (1, NULL, 'PayMethod one', 0, 001, 0, 0), + (2, NULL, 'PayMethod two', 10, 001, 0, 0), + (3, 'compensation', 'PayMethod three', 0, 001, 0, 0), + (4, NULL, 'PayMethod with IBAN', 0, 001, 1, 0), + (5, NULL, 'PayMethod five', 10, 001, 0, 0), + (8,'wireTransfer', 'WireTransfer', 5, 001, 1, 1); INSERT INTO `vn`.`payDem`(`id`, `payDem`) VALUES diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 734a926d19..5a2f9055ff 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -34324,7 +34324,8 @@ CREATE TABLE `payMethod` ( `solution` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `outstandingDebt` tinyint(3) unsigned zerofill NOT NULL DEFAULT '000', `graceDays` int(11) unsigned NOT NULL DEFAULT '0', - `ibanRequired` tinyint(3) DEFAULT '0', + `ibanRequiredForClients` tinyint(3) DEFAULT '0', + `ibanRequiredForSuppliers` tinyint(3) DEFAULT '0', `isNotified` tinyint(3) NOT NULL DEFAULT '1', PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 6519cb979d..4cac16358f 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -129,7 +129,7 @@ module.exports = Self => { function hasIban(err, done) { Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => { - if (instance && instance.ibanRequired && !this.iban) + if (instance && instance.ibanRequiredForClients && !this.iban) err(); done(); }); diff --git a/modules/client/back/models/pay-method.json b/modules/client/back/models/pay-method.json index a025bee477..0666be7a5b 100644 --- a/modules/client/back/models/pay-method.json +++ b/modules/client/back/models/pay-method.json @@ -25,7 +25,10 @@ "outstandingDebt": { "type": "Number" }, - "ibanRequired": { + "ibanRequiredForClients": { + "type": "boolean" + }, + "ibanRequiredForSuppliers": { "type": "boolean" } } diff --git a/modules/client/front/billing-data/index.html b/modules/client/front/billing-data/index.html index ff2e2f157b..8c7c6cfe9d 100644 --- a/modules/client/front/billing-data/index.html +++ b/modules/client/front/billing-data/index.html @@ -19,7 +19,7 @@ vn-acl="salesAssistant" ng-model="$ctrl.client.payMethodFk" data="paymethods" - fields="['ibanRequired']" + fields="['ibanRequiredForClients']" initial-data="$ctrl.client.payMethod"> { const supplierAccount = await Self.app.models.SupplierAccount.findOne({where: {supplierFk: this.id}}); const hasIban = supplierAccount && supplierAccount.iban; - if (payMethod && payMethod.ibanRequired && !hasIban) + if (payMethod && payMethod.ibanRequiredForSuppliers && !hasIban) err(); done(); diff --git a/modules/supplier/front/billing-data/index.html b/modules/supplier/front/billing-data/index.html index 12d3b84b38..c1c57e1357 100644 --- a/modules/supplier/front/billing-data/index.html +++ b/modules/supplier/front/billing-data/index.html @@ -24,7 +24,7 @@ vn-acl="salesAssistant" ng-model="$ctrl.supplier.payMethodFk" data="paymethods" - fields="['ibanRequired']" + fields="['ibanRequiredForSuppliers']" initial-data="$ctrl.supplier.payMethod"> Date: Wed, 10 Nov 2021 08:46:09 +0100 Subject: [PATCH 2/3] update backTest --- db/changes/10370-pickles/{payMethod.sql => 00-payMethod.sql} | 0 modules/supplier/back/models/specs/supplier.spec.js | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) rename db/changes/10370-pickles/{payMethod.sql => 00-payMethod.sql} (100%) diff --git a/db/changes/10370-pickles/payMethod.sql b/db/changes/10370-pickles/00-payMethod.sql similarity index 100% rename from db/changes/10370-pickles/payMethod.sql rename to db/changes/10370-pickles/00-payMethod.sql diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index c3c99e6765..8d022f9b3e 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -20,7 +20,7 @@ describe('loopback model Supplier', () => { const expectedError = 'You can not select this payment method without a registered bankery account'; const supplier = await app.models.Supplier.findById(1); - await supplier.updateAttribute('payMethodFk', 4) + await supplier.updateAttribute('payMethodFk', 8) .catch(e => { error = e; @@ -37,6 +37,7 @@ describe('loopback model Supplier', () => { .catch(e => { error = e; }); + console.log(error); expect(error).toBeDefined(); }); From 41974669e5c82eb1106c15c7e6c495883a978c35 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 10 Nov 2021 15:11:42 +0100 Subject: [PATCH 3/3] fix(testBack): add context --- .../back/models/specs/supplier.spec.js | 27 ++++++++++++++----- .../supplier/back/models/supplier-log.json | 22 +++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 8d022f9b3e..27bd873ad4 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -1,12 +1,13 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); describe('loopback model Supplier', () => { let supplierOne; let supplierTwo; beforeAll(async() => { - supplierOne = await app.models.Supplier.findById(1); - supplierTwo = await app.models.Supplier.findById(442); + supplierOne = await models.Supplier.findById(1); + supplierTwo = await models.Supplier.findById(442); }); afterAll(async() => { @@ -18,7 +19,7 @@ describe('loopback model Supplier', () => { it('should throw an error when attempting to set an invalid payMethod id in the supplier', async() => { let error; const expectedError = 'You can not select this payment method without a registered bankery account'; - const supplier = await app.models.Supplier.findById(1); + const supplier = await models.Supplier.findById(1); await supplier.updateAttribute('payMethodFk', 8) .catch(e => { @@ -31,15 +32,27 @@ describe('loopback model Supplier', () => { }); it('should not throw if the payMethod id is valid', async() => { + const activeCtx = { + accessToken: {userId: 9}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + let error; - const supplier = await app.models.Supplier.findById(442); + const supplier = await models.Supplier.findById(442); await supplier.updateAttribute('payMethodFk', 4) .catch(e => { error = e; }); - console.log(error); - expect(error).toBeDefined(); + expect(error).not.toBeDefined(); }); }); }); diff --git a/modules/supplier/back/models/supplier-log.json b/modules/supplier/back/models/supplier-log.json index 9b66bdf740..7c07fa9d44 100644 --- a/modules/supplier/back/models/supplier-log.json +++ b/modules/supplier/back/models/supplier-log.json @@ -9,40 +9,40 @@ "properties": { "id": { "id": true, - "type": "Number", + "type": "number", "forceId": false }, "originFk": { - "type": "Number", + "type": "number", "required": true }, "userFk": { - "type": "Number" + "type": "number" }, "action": { - "type": "String", + "type": "string", "required": true }, "changedModel": { - "type": "String" + "type": "string" }, "oldInstance": { - "type": "Object" + "type": "object" }, "newInstance": { - "type": "Object" + "type": "object" }, "creationDate": { - "type": "Date" + "type": "date" }, "changedModelId": { - "type": "String" + "type": "string" }, "changedModelValue": { - "type": "String" + "type": "string" }, "description": { - "type": "String" + "type": "string" } }, "relations": {