From 0fa8608d471264e2854d9af237783a8868a9b31e Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 23 Oct 2018 14:56:38 +0200 Subject: [PATCH] hide empty left-menu, swift validation error --- .../src/components/left-menu/left-menu.html | 2 +- services/loopback/common/locale/es.json | 3 ++- services/loopback/common/models/client.js | 25 ++++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/client/salix/src/components/left-menu/left-menu.html b/client/salix/src/components/left-menu/left-menu.html index 08a5be367..50fe2df21 100644 --- a/client/salix/src/components/left-menu/left-menu.html +++ b/client/salix/src/components/left-menu/left-menu.html @@ -1,4 +1,4 @@ - +
    diff --git a/services/loopback/common/locale/es.json b/services/loopback/common/locale/es.json index 4e4f628bf..26e0cb4fb 100644 --- a/services/loopback/common/locale/es.json +++ b/services/loopback/common/locale/es.json @@ -56,5 +56,6 @@ "The sales of this ticket can't be modified": "Los movimientos de este tiquet no pueden ser modificadas", "You can't create an order for a inactive client": "You can't create an order for a inactive client", "You can't create an order for a client that doesn't has tax data verified": "You can't create an order for a client that doesn't has tax data verified", - "You don't have enough privileges": "You don't have enough privileges" + "You don't have enough privileges": "You don't have enough privileges", + "That payment method requires a BIC": "That payment method requires a BIC" } \ No newline at end of file diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js index 7c1bccd5d..124f7e0ae 100644 --- a/services/loopback/common/models/client.js +++ b/services/loopback/common/models/client.js @@ -25,15 +25,18 @@ module.exports = Self => { Self.validatesUniquenessOf('fi', { message: 'TIN must be unique' }); + Self.validatesUniquenessOf('socialName', { message: 'The company name must be unique' }); + Self.validatesFormatOf('email', { message: 'Invalid email', allowNull: true, allowBlank: true, with: /^[\w|.|-]+@[\w|-]+(\.[\w|-]+)*(,[\w|.|-]+@[\w|-]+(\.[\w|-]+)*)*$/ }); + Self.validatesLengthOf('postcode', { allowNull: true, allowBlank: true, @@ -88,18 +91,6 @@ module.exports = Self => { err(); } - Self.validateAsync('payMethodFk', hasIban, { - message: 'That payment method requires an IBAN' - }); - - function hasIban(err, done) { - Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => { - if (instance && instance.ibanRequired && (!this.iban || !this.bankEntityFk)) - err(); - done(); - }); - } - Self.observe('before save', async function(ctx) { let changes = ctx.data || ctx.instance; let orgData = ctx.currentInstance; @@ -140,6 +131,16 @@ module.exports = Self => { }; await Self.app.models.ClientCredit.create(newCredit); } + + if (finalState && finalState.payMethodFk) { + let payMethod = await Self.app.models.PayMethod.findById(finalState.payMethodFk); + + if (payMethod && payMethod.ibanRequired && !finalState.iban) + throw new UserError('That payment method requires an IBAN'); + + if (payMethod && payMethod.ibanRequired && !finalState.bankEntityFk) + throw new UserError('That payment method requires a BIC'); + } }); async function validateCreditChange(ctx, finalState) {