From 8f2e29787b2ef3dee96210e283eb6c82bc920e41 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 19 Nov 2021 10:07:33 +0100 Subject: [PATCH 1/2] fix(payMethod): alter colums name --- db/changes/10390-constitution/00-payMethod.sql | 2 ++ db/dump/fixtures.sql | 2 +- modules/client/back/models/client.js | 2 +- modules/client/back/models/pay-method.json | 4 ++-- modules/client/front/billing-data/index.html | 2 +- modules/supplier/back/models/supplier.js | 2 +- modules/supplier/front/billing-data/index.html | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 db/changes/10390-constitution/00-payMethod.sql diff --git a/db/changes/10390-constitution/00-payMethod.sql b/db/changes/10390-constitution/00-payMethod.sql new file mode 100644 index 000000000..6e196af95 --- /dev/null +++ b/db/changes/10390-constitution/00-payMethod.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.payMethod CHANGE ibanRequiredForClients isIbanRequiredForClients tinyint(3) DEFAULT 0 NULL; +ALTER TABLE vn.payMethod CHANGE ibanRequiredForSuppliers isIbanRequiredForSuppliers tinyint(3) DEFAULT 0 NULL; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index b46056135..bb48d40b4 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -217,7 +217,7 @@ 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`, `ibanRequiredForClients`, `ibanRequiredForSuppliers`) +INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `isIbanRequiredForClients`, `isIbanRequiredForSuppliers`) VALUES (1, NULL, 'PayMethod one', 0, 001, 0, 0), (2, NULL, 'PayMethod two', 10, 001, 0, 0), diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index f3591750d..1a4e9bcb3 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -138,7 +138,7 @@ module.exports = Self => { function hasIban(err, done) { Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => { - if (instance && instance.ibanRequiredForClients && !this.iban) + if (instance && instance.isIbanRequiredForClients && !this.iban) err(); done(); }); diff --git a/modules/client/back/models/pay-method.json b/modules/client/back/models/pay-method.json index 0666be7a5..4080a0953 100644 --- a/modules/client/back/models/pay-method.json +++ b/modules/client/back/models/pay-method.json @@ -25,10 +25,10 @@ "outstandingDebt": { "type": "Number" }, - "ibanRequiredForClients": { + "isIbanRequiredForClients": { "type": "boolean" }, - "ibanRequiredForSuppliers": { + "isIbanRequiredForSuppliers": { "type": "boolean" } } diff --git a/modules/client/front/billing-data/index.html b/modules/client/front/billing-data/index.html index 8c7c6cfe9..06d7d7d73 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="['ibanRequiredForClients']" + fields="['isIbanRequiredForClients']" 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.ibanRequiredForSuppliers && !hasIban) + if (payMethod && payMethod.isIbanRequiredForSuppliers && !hasIban) err(); done(); diff --git a/modules/supplier/front/billing-data/index.html b/modules/supplier/front/billing-data/index.html index c1c57e135..238760c1a 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="['ibanRequiredForSuppliers']" + fields="['isIbanRequiredForSuppliers']" initial-data="$ctrl.supplier.payMethod"> Date: Mon, 22 Nov 2021 13:44:22 +0100 Subject: [PATCH 2/2] fix: extracting logic gates to constants --- modules/client/back/models/client.js | 3 ++- modules/supplier/back/models/supplier.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 1a4e9bcb3..b4961771d 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -138,7 +138,8 @@ module.exports = Self => { function hasIban(err, done) { Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => { - if (instance && instance.isIbanRequiredForClients && !this.iban) + const isMissingIban = instance && instance.isIbanRequiredForClients && !this.iban; + if (isMissingIban) err(); done(); }); diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index bab725903..1ac6e3bd2 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -79,8 +79,9 @@ module.exports = Self => { const payMethod = await Self.app.models.PayMethod.findById(this.payMethodFk); const supplierAccount = await Self.app.models.SupplierAccount.findOne({where: {supplierFk: this.id}}); const hasIban = supplierAccount && supplierAccount.iban; + const isMissingIban = payMethod && payMethod.isIbanRequiredForSuppliers && !hasIban; - if (payMethod && payMethod.isIbanRequiredForSuppliers && !hasIban) + if (isMissingIban) err(); done();