diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js new file mode 100644 index 000000000..9d6f10e3c --- /dev/null +++ b/modules/supplier/back/models/supplier-account.js @@ -0,0 +1,22 @@ +const validateIban = require('vn-loopback/util/validateIban'); + +module.exports = Self => { + Self.validateAsync('iban', ibanNeedsValidation, { + message: 'The IBAN does not have the correct format' + }); + + async function ibanNeedsValidation(err, done) { + let filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + let country = await Self.app.models.Country.findOne(filter); + let code = country ? country.code.toLowerCase() : null; + if (code != 'es') + return done(); + + if (!validateIban(this.iban)) + err(); + done(); + } +}; diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index aaab38369..ffd2994ba 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -16,24 +16,18 @@ "id": true, "description": "Identifier" }, - "supplierFk": { - "type": "Number" - }, "iban": { "type": "String" }, "beneficiary": { "type": "String" - }, - "bankEntityFk": { - "type": "Number" } }, "relations": { "supplier": { "type": "belongsTo", "model": "Supplier", - "foreignKey": "supplierFk" + "foreignKey": "supplierFk" }, "bankEntity": { "type": "belongsTo", diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html index be3c6e8be..7264f6f2c 100644 --- a/modules/supplier/front/account/index.html +++ b/modules/supplier/front/account/index.html @@ -1,7 +1,7 @@ -
+ - - + ng-model="supplierAccount.beneficiary" + info="Beneficiary information">