From e3757e9191dcd2fdbd46074bf9af0789bf96f93e Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 22 Oct 2020 13:00:11 +0200 Subject: [PATCH] changes supplier models --- modules/client/back/models/client.json | 6 +++ .../back/methods/supplier/isAClient.js | 1 - modules/supplier/back/models/supplier.json | 8 +++- modules/supplier/front/card/index.js | 6 +++ modules/supplier/front/descriptor/index.js | 39 +++++++++++-------- 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index 631fce3aa..d39470359 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -186,6 +186,12 @@ "model": "BankEntity", "foreignKey": "bankEntityFk" }, + "supplier": { + "type": "belongsTo", + "model": "Supplier", + "foreignKey": "fi", + "primaryKey": "nif" + }, "defaulters": { "type": "hasMany", "model": "Defaulter", diff --git a/modules/supplier/back/methods/supplier/isAClient.js b/modules/supplier/back/methods/supplier/isAClient.js index ec3bfe3dc..d200d0c84 100644 --- a/modules/supplier/back/methods/supplier/isAClient.js +++ b/modules/supplier/back/methods/supplier/isAClient.js @@ -20,7 +20,6 @@ module.exports = Self => { }); Self.isAClient = async nif => { const client = await Self.app.models.Client.findOne({where: {fi: nif}}); - console.log('client', client); return client; }; }; diff --git a/modules/supplier/back/models/supplier.json b/modules/supplier/back/models/supplier.json index 3c87e4381..8c8952f8f 100644 --- a/modules/supplier/back/models/supplier.json +++ b/modules/supplier/back/models/supplier.json @@ -96,7 +96,13 @@ "type": "belongsTo", "model": "Country", "foreignKey": "countryFk" - } + }, + "client": { + "type": "belongsTo", + "model": "Client", + "foreignKey": "fi", + "primaryKey": "nif" + } }, "acls": [ { diff --git a/modules/supplier/front/card/index.js b/modules/supplier/front/card/index.js index 77fd091a5..613b99cc9 100644 --- a/modules/supplier/front/card/index.js +++ b/modules/supplier/front/card/index.js @@ -28,6 +28,12 @@ class Controller extends ModuleCard { scope: { fields: ['id', 'payDem'] } + }, + { + relation: 'client', + scope: { + fields: ['id', 'fi'] + } } ] }; diff --git a/modules/supplier/front/descriptor/index.js b/modules/supplier/front/descriptor/index.js index 7d4ee750e..90e94b1a3 100644 --- a/modules/supplier/front/descriptor/index.js +++ b/modules/supplier/front/descriptor/index.js @@ -8,7 +8,8 @@ class Controller extends Descriptor { set supplier(value) { this.entity = value; - this.iSupplierAClient(); + console.log('this.entity', this.entity); + // this.iSupplierAClient(); } get entryFilter() { @@ -29,22 +30,22 @@ class Controller extends Descriptor { to }); } - iSupplierAClient() { - if (!this.supplier) return; + // iSupplierAClient() { + // if (!this.supplier) return; - const filter = { - where: {fi: this.supplier.nif} - }; - this.$http.get('Clients/findOne', {filter}).then(res => { - if (res.data) - this.isAClient = res.data; - }).catch(error => { - return this.isAClient = false; - }); - // this.$http.get(`Suppliers/${this.supplier.nif}/isAClient`).then(res => { - // this.isAClient = res.data; - // }); - } + // const filter = { + // where: {fi: this.supplier.nif} + // }; + // this.$http.get('Clients/findOne', {filter}).then(res => { + // if (res.data) + // this.isAClient = res.data; + // }).catch(error => { + // return this.isAClient = false; + // }); + // // this.$http.get(`Suppliers/${this.supplier.nif}/isAClient`).then(res => { + // // this.isAClient = res.data; + // // }); + // } loadData() { const filter = { @@ -72,6 +73,12 @@ class Controller extends Descriptor { scope: { fields: ['id', 'payDem'] } + }, + { + relation: 'client', + scope: { + fields: ['id', 'fi'] + } } ] };