diff --git a/client/salix/src/components/left-menu/left-menu.html b/client/salix/src/components/left-menu/left-menu.html index 08a5be367a..50fe2df21d 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 4e4f628bfb..26e0cb4fbe 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 7c1bccd5d2..124f7e0aec 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) {