diff --git a/loopback/locale/es.json b/loopback/locale/es.json
index f75b1778e..f01da55ac 100644
--- a/loopback/locale/es.json
+++ b/loopback/locale/es.json
@@ -160,5 +160,6 @@
"The social name cannot be empty": "La razón social no puede quedar en blanco",
"The nif cannot be empty": "El NIF no puede quedar en blanco",
"You need to fill sage information before you check verified data": "Debes rellenar la información de sage antes de marcar datos comprobados",
- "ASSIGN_ZONE_FIRST": "Asigna una zona primero"
+ "ASSIGN_ZONE_FIRST": "Asigna una zona primero",
+ "You can not select this payment method without a registered bankery account": "No se puede utilizar este método de pago si no has registrado una cuenta bancaria"
}
\ No newline at end of file
diff --git a/modules/supplier/back/model-config.json b/modules/supplier/back/model-config.json
index 34d152bc6..62c580aca 100644
--- a/modules/supplier/back/model-config.json
+++ b/modules/supplier/back/model-config.json
@@ -10,5 +10,8 @@
},
"SupplierContact": {
"dataSource": "vn"
+ },
+ "SupplierAccount": {
+ "dataSource": "vn"
}
}
diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js
new file mode 100644
index 000000000..1853b1c9a
--- /dev/null
+++ b/modules/supplier/back/models/specs/supplier.spec.js
@@ -0,0 +1,48 @@
+const app = require('vn-loopback/server/server');
+
+describe('loopback model address', () => {
+ let supplierOne;
+ let supplierTwo;
+
+ beforeAll(async done => {
+ supplierOne = await app.models.Supplier.findById(1);
+ supplierTwo = await app.models.Supplier.findById(442);
+
+ done();
+ });
+
+ afterAll(async done => {
+ await supplierOne.updateAttribute('payMethodFk', supplierOne.payMethodFk);
+ await supplierTwo.updateAttribute('payMethodFk', supplierTwo.payMethodFk);
+
+ done();
+ });
+
+ describe('payMethodFk', () => {
+ 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);
+
+ await supplier.updateAttribute('payMethodFk', 4)
+ .catch(e => {
+ error = e;
+
+ expect(error.message).toContain(expectedError);
+ });
+
+ expect(error).toBeDefined();
+ });
+
+ it('should not throw if the payMethod id is valid', async() => {
+ let error;
+ const supplier = await app.models.Supplier.findById(442);
+ await supplier.updateAttribute('payMethodFk', 4)
+ .catch(e => {
+ error = e;
+ });
+
+ expect(error).toBeDefined();
+ });
+ });
+});
diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json
new file mode 100644
index 000000000..237934f8c
--- /dev/null
+++ b/modules/supplier/back/models/supplier-account.json
@@ -0,0 +1,50 @@
+{
+ "name": "SupplierAccount",
+ "base": "VnModel",
+ "options": {
+ "mysql": {
+ "table": "supplierAccount"
+ }
+ },
+ "properties": {
+ "id": {
+ "type": "Number",
+ "id": true,
+ "description": "Identifier"
+ },
+ "supplierFk": {
+ "type": "Number"
+ },
+ "iban": {
+ "type": "String"
+ },
+ "office": {
+ "type": "String"
+ },
+ "DC": {
+ "type": "String"
+ },
+ "number": {
+ "type": "String"
+ },
+ "description": {
+ "type": "String"
+ },
+ "bicSufix": {
+ "type": "String"
+ },
+ "bankEntityFk": {
+ "type": "Number"
+ },
+ "bankFk": {
+ "type": "Number"
+ }
+ },
+ "relations": {
+ "supplier": {
+ "type": "belongsTo",
+ "model": "Supplier",
+ "foreignKey": "supplierFk"
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js
index 37c94c266..73fd9d854 100644
--- a/modules/supplier/back/models/supplier.js
+++ b/modules/supplier/back/models/supplier.js
@@ -70,6 +70,21 @@ module.exports = Self => {
return regexp.test(value);
}
+ Self.validateAsync('payMethodFk', hasSupplierAccount, {
+ message: 'You can not select this payment method without a registered bankery account'
+ });
+
+ async function hasSupplierAccount(err, done) {
+ 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;
+
+ if (payMethod && payMethod.ibanRequired && !hasIban)
+ err();
+
+ done();
+ }
+
Self.observe('before save', async function(ctx) {
let changes = ctx.data || ctx.instance;
let orgData = ctx.currentInstance;
diff --git a/modules/supplier/front/billing-data/index.html b/modules/supplier/front/billing-data/index.html
new file mode 100644
index 000000000..2cb3f7c4b
--- /dev/null
+++ b/modules/supplier/front/billing-data/index.html
@@ -0,0 +1,64 @@
+