From 6cf1e0953d447a0222969541258e615ae1978229 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 30 May 2023 14:49:28 +0200 Subject: [PATCH 01/23] refs #5244 feat: intento de crear el componente workerAutocomplete --- front/core/components/autocomplete/index.html | 4 +- front/core/components/drop-down/index.html | 6 +-- front/core/components/index.js | 1 + .../components/worker-autocomplete/index.html | 9 ++++ .../components/worker-autocomplete/index.js | 49 +++++++++++++++++ .../worker-autocomplete/index.spec.js | 54 +++++++++++++++++++ .../components/worker-autocomplete/style.scss | 30 +++++++++++ modules/ticket/front/tracking/edit/index.html | 17 ++---- 8 files changed, 152 insertions(+), 18 deletions(-) create mode 100755 front/core/components/worker-autocomplete/index.html create mode 100755 front/core/components/worker-autocomplete/index.js create mode 100644 front/core/components/worker-autocomplete/index.spec.js create mode 100755 front/core/components/worker-autocomplete/style.scss diff --git a/front/core/components/autocomplete/index.html b/front/core/components/autocomplete/index.html index 69aac4d43..527ca77e7 100755 --- a/front/core/components/autocomplete/index.html +++ b/front/core/components/autocomplete/index.html @@ -18,7 +18,7 @@ +
- \ No newline at end of file + diff --git a/front/core/components/drop-down/index.html b/front/core/components/drop-down/index.html index ab868f7b5..692b0c87c 100644 --- a/front/core/components/drop-down/index.html +++ b/front/core/components/drop-down/index.html @@ -13,12 +13,12 @@ class="dropdown" ng-click="$ctrl.onContainerClick($event)"> -
{{$ctrl.statusText}}
- \ No newline at end of file + diff --git a/front/core/components/index.js b/front/core/components/index.js index 45d182121..09e0345c7 100644 --- a/front/core/components/index.js +++ b/front/core/components/index.js @@ -51,6 +51,7 @@ import './textarea'; import './th'; import './treeview'; import './wday-picker'; +import './worker-autocomplete'; import './datalist'; import './contextmenu'; import './rating'; diff --git a/front/core/components/worker-autocomplete/index.html b/front/core/components/worker-autocomplete/index.html new file mode 100755 index 000000000..e7a022bc8 --- /dev/null +++ b/front/core/components/worker-autocomplete/index.html @@ -0,0 +1,9 @@ + + diff --git a/front/core/components/worker-autocomplete/index.js b/front/core/components/worker-autocomplete/index.js new file mode 100755 index 000000000..44ffd50e2 --- /dev/null +++ b/front/core/components/worker-autocomplete/index.js @@ -0,0 +1,49 @@ +import ngModule from '../../module'; +import Autocomplete from '../autocomplete'; +import assignProps from '../../lib/assign-props'; +import {mergeWhere} from 'vn-loopback/util/filter'; +import './style.scss'; + +/** + * Input with option selector. + * + * @property {String} showFiled The data field name that should be shown + * @property {String} valueField The data field name that should be used as value + * @property {Array} data Static data for the autocomplete + * @property {Object} intialData An initial data to avoid the server request used to get the selection + * @property {Boolean} multiple Whether to allow multiple selection + * @property {Object} selection Current object selected + * + * @event change Thrown when value is changed + */ +export default class WorkerAutocomplete extends Autocomplete { + constructor($element, $, $compile, $transclude) { + super($element, $, $compile, $transclude); + } + + // $postLink() { + // super.$postLink(); + // this.assignDropdownProps(); + // this.showField = this.$.dropDown.showField; + // this.valueField = this.$.dropDown.valueField; + // this.refreshSelection(); + // } + + // /** + // * @type {any} The autocomplete value. + // */ + // get field() { + // return super.field; + // } + + // set field(value) { + // super.field = value; + // this.refreshSelection(); + // } +} +WorkerAutocomplete.$inject = ['$element', '$scope', '$compile', '$transclude']; + +ngModule.vnComponent('vnWorkerAutocomplete', { + template: require('./index.html'), + controller: WorkerAutocomplete +}); diff --git a/front/core/components/worker-autocomplete/index.spec.js b/front/core/components/worker-autocomplete/index.spec.js new file mode 100644 index 000000000..847761179 --- /dev/null +++ b/front/core/components/worker-autocomplete/index.spec.js @@ -0,0 +1,54 @@ +describe('Component vnAutocomplete', () => { + let $element; + let controller; + let data = {id: 1, name: 'Bruce Wayne'}; + + beforeEach(ngModule('vnCore')); + + beforeEach(inject(($compile, $rootScope) => { + $element = $compile(``)($rootScope); + controller = $element.controller('vnAutocomplete'); + })); + + afterEach(() => { + $element.remove(); + }); + + describe('url() setter', () => { + it(`should set the url property`, () => { + controller.url = '/TestModels'; + + expect(controller.url).toEqual('/TestModels'); + }); + }); + + describe('field() setter/getter', () => { + it(`should set the field property`, () => { + controller.field = 'id'; + + expect(controller.field).toEqual('id'); + }); + }); + + describe('selection property', () => { + beforeEach(() => { + controller.field = data.id; + }); + + it(`should set selection finding an existing item in the initialData property`, () => { + controller.initialData = data; + + expect(controller.selection).toEqual(data); + }); + + it(`should set selection finding an existing item in the data property`, () => { + controller.data = [data]; + + expect(controller.selection).toEqual(data); + }); + + it(`should set selection to null when can't find an existing item in the data property`, () => { + expect(controller.selection).toEqual(null); + }); + }); +}); diff --git a/front/core/components/worker-autocomplete/style.scss b/front/core/components/worker-autocomplete/style.scss new file mode 100755 index 000000000..d76f84f85 --- /dev/null +++ b/front/core/components/worker-autocomplete/style.scss @@ -0,0 +1,30 @@ +@import "effects"; + +.vn-worker-autocomplete { + overflow: hidden; + + & > .container { + cursor: pointer; + + & > .infix > .control { + overflow: hidden; + + & > input { + cursor: pointer; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + text-align: left; + padding-left: 0; + padding-right: 0; + } + } + + & > .icons.pre { + min-width: 22px + } + } + &.readonly > .container > .icons.post { + display: none; + } +} diff --git a/modules/ticket/front/tracking/edit/index.html b/modules/ticket/front/tracking/edit/index.html index c522536b3..18b898012 100644 --- a/modules/ticket/front/tracking/edit/index.html +++ b/modules/ticket/front/tracking/edit/index.html @@ -14,22 +14,13 @@ - - + + @@ -43,4 +34,4 @@ ui-sref="ticket.card.tracking.index"> - \ No newline at end of file + From daeed312d0e403ad7eb00439e01903fcf623e10e Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 30 May 2023 15:16:15 +0200 Subject: [PATCH 02/23] =?UTF-8?q?refs=20#5244=20fix:=20a=C3=B1adido=20vn-d?= =?UTF-8?q?rop-down=20em=20html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/components/worker-autocomplete/index.html | 14 +++++++++++++- modules/ticket/front/tracking/edit/index.html | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/front/core/components/worker-autocomplete/index.html b/front/core/components/worker-autocomplete/index.html index e7a022bc8..fc8ddf640 100755 --- a/front/core/components/worker-autocomplete/index.html +++ b/front/core/components/worker-autocomplete/index.html @@ -2,8 +2,20 @@ vn-one url="Workers/activeWithInheritedRole" ng-model="$ctrl.workerFk" - show-field="nickname" search-function="{firstName: $search}" value-field="id" label="Worker"> + +
+ {{firstName}} {{lastName}} +
+
+ {{nickname}}, {{code}} +
+ + diff --git a/modules/ticket/front/tracking/edit/index.html b/modules/ticket/front/tracking/edit/index.html index 18b898012..3eafed8db 100644 --- a/modules/ticket/front/tracking/edit/index.html +++ b/modules/ticket/front/tracking/edit/index.html @@ -19,7 +19,8 @@ label="State" vn-focus> - + From a539abf3d8bdb959a9cf647deb171278bfd4c6ef Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 31 May 2023 10:15:16 +0200 Subject: [PATCH 03/23] refs #5244 feat: creado back para buscar trabjadores por name. nickname y code --- .../components/worker-autocomplete/index.html | 11 ++-- .../components/worker-autocomplete/index.js | 23 ------- .../components/worker-autocomplete/style.scss | 30 --------- modules/worker/back/methods/worker/search.js | 61 +++++++++++++++++++ modules/worker/back/models/worker.js | 1 + 5 files changed, 69 insertions(+), 57 deletions(-) delete mode 100755 front/core/components/worker-autocomplete/style.scss create mode 100644 modules/worker/back/methods/worker/search.js diff --git a/front/core/components/worker-autocomplete/index.html b/front/core/components/worker-autocomplete/index.html index fc8ddf640..65418aee0 100755 --- a/front/core/components/worker-autocomplete/index.html +++ b/front/core/components/worker-autocomplete/index.html @@ -1,13 +1,16 @@
- {{firstName}} {{lastName}} + {{name}}
{{nickname}}, {{code}} diff --git a/front/core/components/worker-autocomplete/index.js b/front/core/components/worker-autocomplete/index.js index 44ffd50e2..7983f53a5 100755 --- a/front/core/components/worker-autocomplete/index.js +++ b/front/core/components/worker-autocomplete/index.js @@ -1,8 +1,5 @@ import ngModule from '../../module'; import Autocomplete from '../autocomplete'; -import assignProps from '../../lib/assign-props'; -import {mergeWhere} from 'vn-loopback/util/filter'; -import './style.scss'; /** * Input with option selector. @@ -20,26 +17,6 @@ export default class WorkerAutocomplete extends Autocomplete { constructor($element, $, $compile, $transclude) { super($element, $, $compile, $transclude); } - - // $postLink() { - // super.$postLink(); - // this.assignDropdownProps(); - // this.showField = this.$.dropDown.showField; - // this.valueField = this.$.dropDown.valueField; - // this.refreshSelection(); - // } - - // /** - // * @type {any} The autocomplete value. - // */ - // get field() { - // return super.field; - // } - - // set field(value) { - // super.field = value; - // this.refreshSelection(); - // } } WorkerAutocomplete.$inject = ['$element', '$scope', '$compile', '$transclude']; diff --git a/front/core/components/worker-autocomplete/style.scss b/front/core/components/worker-autocomplete/style.scss deleted file mode 100755 index d76f84f85..000000000 --- a/front/core/components/worker-autocomplete/style.scss +++ /dev/null @@ -1,30 +0,0 @@ -@import "effects"; - -.vn-worker-autocomplete { - overflow: hidden; - - & > .container { - cursor: pointer; - - & > .infix > .control { - overflow: hidden; - - & > input { - cursor: pointer; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - text-align: left; - padding-left: 0; - padding-right: 0; - } - } - - & > .icons.pre { - min-width: 22px - } - } - &.readonly > .container > .icons.post { - display: none; - } -} diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js new file mode 100644 index 000000000..1d1742595 --- /dev/null +++ b/modules/worker/back/methods/worker/search.js @@ -0,0 +1,61 @@ +module.exports = Self => { + Self.remoteMethod('search', { + description: 'Returns an array of search from an specified worker', + accepts: [{ + arg: 'filter', + type: 'Object', + description: 'Filter defining where and paginated data', + required: true + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/search`, + verb: 'GET' + } + }); + + Self.search = async filter => { + const models = Self.app.models; + + delete filter.order; + delete filter.fields; + const users = await models.VnUser.find(filter); + + if (filter.where) { + const indexToDelete = 2; + const filterByCode = filter.where.or.splice(indexToDelete, 1)[0]; + + const ids = users.map(user => parseInt(user.id)); + filter.where.or = [ + {id: {inq: ids}}, + filterByCode + ]; + } + + filter.include = { + relation: 'user', + scope: { + fields: ['name', 'nickname'] + } + }; + + const workers = await models.Worker.find(filter); + + const result = workers.map(worker => { + return { + id: worker.id, + code: worker.code, + name: worker.user().name, + nickname: worker.user().nickname + }; + }); + result.sort((a, b) => { + return a.name.localeCompare(b.name); + }); + + return result; + }; +}; diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index fa17640a8..16e4055bc 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -16,6 +16,7 @@ module.exports = Self => { require('../methods/worker/new')(Self); require('../methods/worker/deallocatePDA')(Self); require('../methods/worker/allocatePDA')(Self); + require('../methods/worker/search')(Self); Self.validatesUniquenessOf('locker', { message: 'This locker has already been assigned' From 3b4626ee7436d0cef4df6fa241cef43d951345c7 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 31 May 2023 13:01:16 +0200 Subject: [PATCH 04/23] a --- front/core/components/worker-autocomplete/index.html | 1 - modules/ticket/front/tracking/edit/index.html | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/front/core/components/worker-autocomplete/index.html b/front/core/components/worker-autocomplete/index.html index 65418aee0..c48a6f8d3 100755 --- a/front/core/components/worker-autocomplete/index.html +++ b/front/core/components/worker-autocomplete/index.html @@ -1,7 +1,6 @@ + vn-one + ng-model="$ctrl.workerFk" + where="{role: 'employee'}"> + + From 874255f2e59ebce40b7c8e1fbff10d07ffdc0399 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 8 Jun 2023 11:07:57 +0200 Subject: [PATCH 05/23] refs #5244 feat: extiende correctamente --- .../components/worker-autocomplete/index.html | 31 ++++---------- .../components/worker-autocomplete/index.js | 34 +++++++-------- modules/worker/back/methods/worker/search.js | 41 +------------------ 3 files changed, 28 insertions(+), 78 deletions(-) diff --git a/front/core/components/worker-autocomplete/index.html b/front/core/components/worker-autocomplete/index.html index c48a6f8d3..95631e8aa 100755 --- a/front/core/components/worker-autocomplete/index.html +++ b/front/core/components/worker-autocomplete/index.html @@ -1,23 +1,8 @@ - - -
- {{name}} -
-
- {{nickname}}, {{code}} -
-
- - + +
+ {{name}} +
+
+ {{nickname}}, {{code}} +
+
diff --git a/front/core/components/worker-autocomplete/index.js b/front/core/components/worker-autocomplete/index.js index 7983f53a5..59a46cc46 100755 --- a/front/core/components/worker-autocomplete/index.js +++ b/front/core/components/worker-autocomplete/index.js @@ -1,26 +1,28 @@ import ngModule from '../../module'; import Autocomplete from '../autocomplete'; -/** - * Input with option selector. - * - * @property {String} showFiled The data field name that should be shown - * @property {String} valueField The data field name that should be used as value - * @property {Array} data Static data for the autocomplete - * @property {Object} intialData An initial data to avoid the server request used to get the selection - * @property {Boolean} multiple Whether to allow multiple selection - * @property {Object} selection Current object selected - * - * @event change Thrown when value is changed - */ export default class WorkerAutocomplete extends Autocomplete { - constructor($element, $, $compile, $transclude) { - super($element, $, $compile, $transclude); + constructor(...args) { + super(...args); + Object.assign(this, { + label: 'Worker', + url: 'Workers/search', + fields: ['id', 'name', 'nickname'], + searchFunction: function($search) { + return {and: [ + {active: {neq: false}}, + {or: [ + {name: $search}, + {nickname: {like: '%' + $search + '%'}}, + {code: {like: $search + '%'}} + ]} + ]}; + } + }); } } -WorkerAutocomplete.$inject = ['$element', '$scope', '$compile', '$transclude']; ngModule.vnComponent('vnWorkerAutocomplete', { - template: require('./index.html'), + slotTemplate: require('./index.html'), controller: WorkerAutocomplete }); diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 1d1742595..39bcef4c1 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -18,44 +18,7 @@ module.exports = Self => { }); Self.search = async filter => { - const models = Self.app.models; - - delete filter.order; - delete filter.fields; - const users = await models.VnUser.find(filter); - - if (filter.where) { - const indexToDelete = 2; - const filterByCode = filter.where.or.splice(indexToDelete, 1)[0]; - - const ids = users.map(user => parseInt(user.id)); - filter.where.or = [ - {id: {inq: ids}}, - filterByCode - ]; - } - - filter.include = { - relation: 'user', - scope: { - fields: ['name', 'nickname'] - } - }; - - const workers = await models.Worker.find(filter); - - const result = workers.map(worker => { - return { - id: worker.id, - code: worker.code, - name: worker.user().name, - nickname: worker.user().nickname - }; - }); - result.sort((a, b) => { - return a.name.localeCompare(b.name); - }); - - return result; + const $ = Self.app.models; + return await $.VnUser.find(filter); }; }; From 7dd5a5ac8e0d60dc0c581baf3a3fd6a472949f1b Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 8 Jun 2023 13:12:30 +0200 Subject: [PATCH 06/23] refs #5244 feat: hereda correctamente --- db/changes/232601/00-aclWorker.sql | 3 +++ front/core/components/autocomplete/index.js | 7 +++---- front/core/components/field/index.js | 6 +++--- .../components/worker-autocomplete/index.js | 2 +- front/core/lib/component.js | 7 +++---- front/core/lib/event-emitter.js | 1 - modules/worker/back/methods/worker/search.js | 18 +++++++++++++++++- 7 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 db/changes/232601/00-aclWorker.sql diff --git a/db/changes/232601/00-aclWorker.sql b/db/changes/232601/00-aclWorker.sql new file mode 100644 index 000000000..7e5081530 --- /dev/null +++ b/db/changes/232601/00-aclWorker.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (id, model, property, accessType, permission, principalType, principalId) + VALUES + ('Worker', 'search', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/front/core/components/autocomplete/index.js b/front/core/components/autocomplete/index.js index 2539c4ef4..b8a0617b3 100755 --- a/front/core/components/autocomplete/index.js +++ b/front/core/components/autocomplete/index.js @@ -17,10 +17,9 @@ import './style.scss'; * @event change Thrown when value is changed */ export default class Autocomplete extends Field { - constructor($element, $, $compile, $transclude) { - super($element, $, $compile); + constructor($element, $, $transclude) { + super($element, $, $transclude); this.$transclude = $transclude; - this.$compile = $compile; this._selection = null; this.input = this.element.querySelector('input'); } @@ -282,7 +281,7 @@ export default class Autocomplete extends Field { this.refreshSelection(); } } -Autocomplete.$inject = ['$element', '$scope', '$compile', '$transclude']; +Autocomplete.$inject = ['$element', '$scope', '$transclude']; ngModule.vnComponent('vnAutocomplete', { template: require('./index.html'), diff --git a/front/core/components/field/index.js b/front/core/components/field/index.js index 7ce840555..ff92b6b87 100644 --- a/front/core/components/field/index.js +++ b/front/core/components/field/index.js @@ -3,8 +3,8 @@ import FormInput from '../form-input'; import './style.scss'; export default class Field extends FormInput { - constructor($element, $scope) { - super($element, $scope); + constructor($element, $scope, $transclude) { + super($element, $scope, $transclude); this.prefix = null; this.suffix = null; @@ -197,7 +197,7 @@ export default class Field extends FormInput { }); } } -Field.$inject = ['$element', '$scope']; +Field.$inject = ['$element', '$scope', '$transclude']; ngModule.vnComponent('vnField', { template: require('./index.html'), diff --git a/front/core/components/worker-autocomplete/index.js b/front/core/components/worker-autocomplete/index.js index 59a46cc46..efaa6a4a9 100755 --- a/front/core/components/worker-autocomplete/index.js +++ b/front/core/components/worker-autocomplete/index.js @@ -8,7 +8,7 @@ export default class WorkerAutocomplete extends Autocomplete { label: 'Worker', url: 'Workers/search', fields: ['id', 'name', 'nickname'], - searchFunction: function($search) { + searchFunction: function({$search}) { return {and: [ {active: {neq: false}}, {or: [ diff --git a/front/core/lib/component.js b/front/core/lib/component.js index 5695d9449..6bb83e55a 100644 --- a/front/core/lib/component.js +++ b/front/core/lib/component.js @@ -12,10 +12,9 @@ export default class Component extends EventEmitter { * @param {HTMLElement} $element The main component element * @param {$rootScope.Scope} $scope The element scope * @param {Function} $transclude The transclusion function - * @param {Function} $location The location function */ - constructor($element, $scope, $transclude, $location) { - super($element, $scope, $transclude, $location); + constructor($element, $scope, $transclude) { + super(); this.$ = $scope; if (!$element) return; @@ -165,7 +164,7 @@ export default class Component extends EventEmitter { $transclude.$$boundTransclude.$$slots[slot]; } } -Component.$inject = ['$element', '$scope', '$location', '$state']; +Component.$inject = ['$element', '$scope', '$transclude']; /* * Automatically adds the most used services to the prototype, so they are diff --git a/front/core/lib/event-emitter.js b/front/core/lib/event-emitter.js index 83e361253..0e0ce1872 100644 --- a/front/core/lib/event-emitter.js +++ b/front/core/lib/event-emitter.js @@ -83,4 +83,3 @@ export default class EventEmitter { } } } -EventEmitter.$inject = ['$element', '$scope']; diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 39bcef4c1..1e8343fac 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -19,6 +19,22 @@ module.exports = Self => { Self.search = async filter => { const $ = Self.app.models; - return await $.VnUser.find(filter); + + let {where} = filter; + const users = where && await $.VnUser.find({ + fields: ['id'], + where + }); + + const workers = await Self.find({ + fields: ['id'], + where: { + businessFk: {neq: null}, + id: users ? {inq: users.map(u => u.id)} : undefined + } + }); + + where = {id: {inq: workers.map(w => w.id)}}; + return await $.VnUser.find(Object.assign({}, filter, {where})); }; }; From f47a049d7ab55ea7d2baa6574bbbddc5f134fe84 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 8 Jun 2023 13:39:21 +0200 Subject: [PATCH 07/23] =?UTF-8?q?refs=20#5244=20fix:=20cambiada=20descripc?= =?UTF-8?q?i=C3=B3n=20erronea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/worker/back/methods/worker/activeWithInheritedRole.js | 4 ++-- modules/worker/back/methods/worker/activeWithRole.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker/activeWithInheritedRole.js b/modules/worker/back/methods/worker/activeWithInheritedRole.js index 9536b0f29..19038405b 100644 --- a/modules/worker/back/methods/worker/activeWithInheritedRole.js +++ b/modules/worker/back/methods/worker/activeWithInheritedRole.js @@ -1,7 +1,7 @@ module.exports = Self => { Self.remoteMethod('activeWithInheritedRole', { - description: 'Returns active workers with a role', + description: 'Returns active workers with an inherited role', accessType: 'READ', accepts: [{ arg: 'filter', @@ -24,7 +24,7 @@ module.exports = Self => { `SELECT DISTINCT w.id, w.firstName, w.lastName, u.name, u.nickname FROM worker w JOIN account.user u ON u.id = w.userFk - JOIN account.roleRole i ON i.role = u.role + JOIN account.roleRole i ON i.role = u.role JOIN account.role r ON r.id = i.inheritsFrom`; return Self.activeWorkers(query, filter); diff --git a/modules/worker/back/methods/worker/activeWithRole.js b/modules/worker/back/methods/worker/activeWithRole.js index 392416458..c7f96e151 100644 --- a/modules/worker/back/methods/worker/activeWithRole.js +++ b/modules/worker/back/methods/worker/activeWithRole.js @@ -1,7 +1,7 @@ module.exports = Self => { Self.remoteMethod('activeWithRole', { - description: 'Returns active workers with an inherited role', + description: 'Returns active workers with a role', accessType: 'READ', accepts: [{ arg: 'filter', From 5195c0100b0536c8b5b550eadf58af40718d3bba Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 8 Jun 2023 14:49:28 +0200 Subject: [PATCH 08/23] refs #5244 fix: sql --- db/changes/232601/00-aclWorker.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/232601/00-aclWorker.sql b/db/changes/232601/00-aclWorker.sql index 7e5081530..e79d8f738 100644 --- a/db/changes/232601/00-aclWorker.sql +++ b/db/changes/232601/00-aclWorker.sql @@ -1,3 +1,3 @@ -INSERT INTO `salix`.`ACL` (id, model, property, accessType, permission, principalType, principalId) +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) VALUES ('Worker', 'search', 'READ', 'ALLOW', 'ROLE', 'employee'); From a699e2d8748ce295193620f324500481c4668a40 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 21 Jun 2023 14:07:36 +0200 Subject: [PATCH 09/23] =?UTF-8?q?refs=20#5244=20feat:=20a=C3=B1adido=20'de?= =?UTF-8?q?patments'=20como=20binding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/worker-autocomplete/index.js | 26 ++++++--- modules/ticket/front/tracking/edit/index.html | 2 +- modules/worker/back/methods/worker/search.js | 57 +++++++++++++------ 3 files changed, 59 insertions(+), 26 deletions(-) diff --git a/front/core/components/worker-autocomplete/index.js b/front/core/components/worker-autocomplete/index.js index efaa6a4a9..436959c5d 100755 --- a/front/core/components/worker-autocomplete/index.js +++ b/front/core/components/worker-autocomplete/index.js @@ -4,25 +4,35 @@ import Autocomplete from '../autocomplete'; export default class WorkerAutocomplete extends Autocomplete { constructor(...args) { super(...args); + } + + $onInit() { + let url = 'Workers/search'; + if (this.departments) { + const parameter = encodeURIComponent(JSON.stringify(this.departments)); + url = `Workers/search?departmentCodes=${parameter}`; + } Object.assign(this, { label: 'Worker', - url: 'Workers/search', - fields: ['id', 'name', 'nickname'], + url: url, searchFunction: function({$search}) { return {and: [ - {active: {neq: false}}, + {'u.active': {neq: false}}, {or: [ - {name: $search}, - {nickname: {like: '%' + $search + '%'}}, - {code: {like: $search + '%'}} + {'u.name': $search}, + {'u.nickname': {like: '%' + $search + '%'}}, + {'w.code': {like: $search + '%'}} ]} ]}; - } + }, }); } } ngModule.vnComponent('vnWorkerAutocomplete', { slotTemplate: require('./index.html'), - controller: WorkerAutocomplete + controller: WorkerAutocomplete, + bindings: { + departments: ' + departments="['VN']"> { - Self.remoteMethod('search', { + Self.remoteMethodCtx('search', { description: 'Returns an array of search from an specified worker', accepts: [{ arg: 'filter', - type: 'Object', + type: 'object', description: 'Filter defining where and paginated data', required: true + }, + { + arg: 'departmentCodes', + type: ['string'], + description: 'Department codes to search workers', }], returns: { type: ['object'], @@ -17,24 +25,39 @@ module.exports = Self => { } }); - Self.search = async filter => { - const $ = Self.app.models; + Self.search = async(ctx, filter, departmentCodes) => { + const models = Self.app.models; + const conn = Self.dataSource.connector; - let {where} = filter; - const users = where && await $.VnUser.find({ - fields: ['id'], - where - }); + let allDepartments = []; + if (departmentCodes) { + const departments = await models.Department.find({ + fields: ['id'], + where: {code: {inq: departmentCodes}} + }); + const departmentIds = departments.map(department => department.id); - const workers = await Self.find({ - fields: ['id'], - where: { - businessFk: {neq: null}, - id: users ? {inq: users.map(u => u.id)} : undefined + let departmentLeaves = []; + for (let id of departmentIds) { + const leaves = await models.Department.getLeaves(ctx, id, null); + console.log(leaves); + for (let leave of leaves) departmentLeaves.push(leave.id); } - }); - where = {id: {inq: workers.map(w => w.id)}}; - return await $.VnUser.find(Object.assign({}, filter, {where})); + allDepartments = departmentIds.concat(departmentLeaves); + console.log(allDepartments); + const where = {'d.id': {inq: allDepartments}}; + filter = mergeFilters(filter, {where}); + } + + const stmt = new ParameterizedSQL( + `SELECT DISTINCT w.code, u.name, u.nickname + FROM worker w + JOIN account.user u ON u.id = w.id + JOIN business b ON b.workerFk = w.id + JOIN department d ON d.id = b.departmentFk`); + + stmt.merge(conn.makeSuffix(filter)); + return conn.executeStmt(stmt); }; }; From e9ef81f8d7b7640f802d0fc8b4ec4a1ac5ee29ed Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 21 Jun 2023 15:00:46 +0200 Subject: [PATCH 10/23] refs #5244 feat: coge todos los hijos recursivamente --- db/changes/232601/00-department.sql | 3 ++ modules/worker/back/methods/worker/search.js | 30 +++++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 db/changes/232601/00-department.sql diff --git a/db/changes/232601/00-department.sql b/db/changes/232601/00-department.sql new file mode 100644 index 000000000..777d26b9f --- /dev/null +++ b/db/changes/232601/00-department.sql @@ -0,0 +1,3 @@ +UPDATE `vn`.`department` + SET code='VN' +WHERE name='VERDNATURA'; diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 388b94e6b..c02053b0c 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -29,24 +29,14 @@ module.exports = Self => { const models = Self.app.models; const conn = Self.dataSource.connector; - let allDepartments = []; if (departmentCodes) { const departments = await models.Department.find({ - fields: ['id'], + fields: ['id', 'sons'], where: {code: {inq: departmentCodes}} }); - const departmentIds = departments.map(department => department.id); - let departmentLeaves = []; - for (let id of departmentIds) { - const leaves = await models.Department.getLeaves(ctx, id, null); - console.log(leaves); - for (let leave of leaves) departmentLeaves.push(leave.id); - } - - allDepartments = departmentIds.concat(departmentLeaves); - console.log(allDepartments); - const where = {'d.id': {inq: allDepartments}}; + const allLeaves = await getAllLeaves(ctx, departments); + const where = {'d.id': {inq: allLeaves}}; filter = mergeFilters(filter, {where}); } @@ -60,4 +50,18 @@ module.exports = Self => { stmt.merge(conn.makeSuffix(filter)); return conn.executeStmt(stmt); }; + + async function getAllLeaves(ctx, departments) { + const models = Self.app.models; + const leaves = []; + for (const department of departments) { + if (department.sons > 0) { + const subLeaves = await models.Department.getLeaves(ctx, department.id, null); + const grandLeaves = await getAllLeaves(ctx, subLeaves); + leaves.push(...grandLeaves); + } + leaves.push(department.id); + } + return leaves; + } }; From 3cedef6f1616dfb9bae0263f5654f142e3ddfb99 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 29 Jun 2023 15:22:53 +0200 Subject: [PATCH 11/23] refs #5244 fix: add id --- modules/worker/back/methods/worker/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index c02053b0c..14916cbb6 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -41,7 +41,7 @@ module.exports = Self => { } const stmt = new ParameterizedSQL( - `SELECT DISTINCT w.code, u.name, u.nickname + `SELECT DISTINCT w.id, w.code, u.name, u.nickname FROM worker w JOIN account.user u ON u.id = w.id JOIN business b ON b.workerFk = w.id From f3e771747ae2d231d46bf643fa63d90c8f05bf37 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 29 Jun 2023 15:56:07 +0200 Subject: [PATCH 12/23] refs #5244 fix: getItemTypeWorker permite filtrar por id --- .../back/methods/worker/getItemTypeWorker.js | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 modules/worker/back/methods/worker/getItemTypeWorker.js diff --git a/modules/worker/back/methods/worker/getItemTypeWorker.js b/modules/worker/back/methods/worker/getItemTypeWorker.js new file mode 100644 index 000000000..b1f49ae99 --- /dev/null +++ b/modules/worker/back/methods/worker/getItemTypeWorker.js @@ -0,0 +1,65 @@ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const buildFilter = require('vn-loopback/util/filter').buildFilter; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; + +module.exports = Self => { + Self.remoteMethod('getItemTypeWorker', { + description: 'Returns the workers that appear in itemType', + accessType: 'READ', + accepts: [{ + arg: 'filter', + type: 'Object', + description: 'Filter defining where and paginated data', + required: true + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/getItemTypeWorker`, + verb: 'GET' + } + }); + + Self.getItemTypeWorker = async(filter, options) => { + const myOptions = {}; + const conn = Self.dataSource.connector; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const query = + `SELECT DISTINCT u.id, w.firstName, w.lastName, u.nickname, u.name + FROM itemType it + JOIN worker w ON w.id = it.workerFk + JOIN account.user u ON u.id = w.id`; + + let stmt = new ParameterizedSQL(query); + + let clientFilter = Object.assign({}, filter); + clientFilter.where = buildFilter(filter.where, (param, value) => { + switch (param) { + case 'role': + return {'r.name': value}; + case 'firstName': + return {or: [ + {'w.firstName': {like: `%${value}%`}}, + {'w.lastName': {like: `%${value}%`}}, + {'u.name': {like: `%${value}%`}}, + {'u.nickname': {like: `%${value}%`}} + ]}; + case 'id': + return {'w.id': value}; + } + }); + + let myFilter = { + where: {'u.active': true} + }; + + myFilter = mergeFilters(myFilter, clientFilter); + stmt.merge(conn.makeSuffix(myFilter)); + return conn.executeStmt(stmt); + }; +}; From 7b4e8570aaf20597864cb2c4048fb965231d6ace Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 30 Jun 2023 12:03:26 +0200 Subject: [PATCH 13/23] refs #5244 refactor: se sustituyen los activeWithRole con where="{role: {inq: ['logistic', 'buyer']}}" por getItemTypeWorker --- .../front/consumption-search-panel/index.html | 5 ++- .../front/latest-buys-search-panel/index.html | 3 +- .../front/fixed-price-search-panel/index.html | 3 +- modules/item/front/index/index.js | 3 +- .../front/request-search-panel/index.html | 17 +++++----- .../front/consumption-search-panel/index.html | 5 ++- .../ticket-request/getItemTypeWorker.js | 33 +++++++++++-------- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/modules/client/front/consumption-search-panel/index.html b/modules/client/front/consumption-search-panel/index.html index 4d23eb53a..c113ee601 100644 --- a/modules/client/front/consumption-search-panel/index.html +++ b/modules/client/front/consumption-search-panel/index.html @@ -17,12 +17,11 @@ - {{nickname}} diff --git a/modules/entry/front/latest-buys-search-panel/index.html b/modules/entry/front/latest-buys-search-panel/index.html index 075d6a8f7..c73bf7365 100644 --- a/modules/entry/front/latest-buys-search-panel/index.html +++ b/modules/entry/front/latest-buys-search-panel/index.html @@ -54,11 +54,10 @@ vn-id="salesPerson" disabled="false" ng-model="$ctrl.filter.salesPersonFk" - url="Workers/activeWithRole" + url="TicketRequests/getItemTypeWorker" show-field="nickname" search-function="{firstName: $search}" value-field="id" - where="{role: {inq: ['logistic', 'buyer']}}" label="Buyer" on-change="$ctrl.addFilters()"> diff --git a/modules/item/front/fixed-price-search-panel/index.html b/modules/item/front/fixed-price-search-panel/index.html index ebe210277..347e65571 100644 --- a/modules/item/front/fixed-price-search-panel/index.html +++ b/modules/item/front/fixed-price-search-panel/index.html @@ -54,11 +54,10 @@ vn-id="buyer" disabled="false" ng-model="$ctrl.filter.buyerFk" - url="Workers/activeWithRole" + url="TicketRequests/getItemTypeWorker" show-field="nickname" search-function="{firstName: $search}" value-field="id" - where="{role: {inq: ['logistic', 'buyer']}}" label="Buyer" on-change="$ctrl.addFilters()">
diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js index 10bd4bbb7..2bcc2302a 100644 --- a/modules/item/front/index/index.js +++ b/modules/item/front/index/index.js @@ -44,8 +44,7 @@ class Controller extends Section { { field: 'buyerFk', autocomplete: { - url: 'Workers/activeWithRole', - where: `{role: {inq: ['logistic', 'buyer']}}`, + url: 'TicketRequests/getItemTypeWorker', searchFunction: '{firstName: $search}', showField: 'nickname', valueField: 'id', diff --git a/modules/item/front/request-search-panel/index.html b/modules/item/front/request-search-panel/index.html index a76684776..806ab79b1 100644 --- a/modules/item/front/request-search-panel/index.html +++ b/modules/item/front/request-search-panel/index.html @@ -1,7 +1,7 @@
@@ -22,12 +22,11 @@ - {{nickname}} @@ -57,7 +56,7 @@ {{firstName}} {{lastName}} - +
- - {{nickname}} diff --git a/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js b/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js index 0655c7bba..f160cfaac 100644 --- a/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js +++ b/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js @@ -1,7 +1,9 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const buildFilter = require('vn-loopback/util/filter').buildFilter; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { - Self.remoteMethodCtx('getItemTypeWorker', { + Self.remoteMethod('getItemTypeWorker', { description: 'Returns the workers that appear in itemType', accessType: 'READ', accepts: [{ @@ -20,10 +22,9 @@ module.exports = Self => { } }); - Self.getItemTypeWorker = async(ctx, filter, options) => { + Self.getItemTypeWorker = async(filter, options) => { const myOptions = {}; const conn = Self.dataSource.connector; - let tx; if (typeof options == 'object') Object.assign(myOptions, options); @@ -33,25 +34,29 @@ module.exports = Self => { FROM itemType it JOIN worker w ON w.id = it.workerFk JOIN account.user u ON u.id = w.id`; + const stmt = new ParameterizedSQL(query); - let stmt = new ParameterizedSQL(query); - - if (filter.where) { - const value = filter.where.firstName; - const myFilter = { - where: {or: [ + filter.where = buildFilter(filter.where, (param, value) => { + switch (param) { + case 'firstName': + return {or: [ {'w.firstName': {like: `%${value}%`}}, {'w.lastName': {like: `%${value}%`}}, {'u.name': {like: `%${value}%`}}, {'u.nickname': {like: `%${value}%`}} - ]} - }; + ]}; + case 'id': + return {'w.id': value}; + } + }); - stmt.merge(conn.makeSuffix(myFilter)); - } + let myFilter = { + where: {'u.active': true} + }; - if (tx) await tx.commit(); + myFilter = mergeFilters(myFilter, filter); + stmt.merge(conn.makeSuffix(myFilter)); return conn.executeStmt(stmt); }; }; From 954c2f5435518e7b8493d04de2eb312c1ee3f1ed Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 12 Jul 2023 13:12:51 +0200 Subject: [PATCH 14/23] refs #5244 feat: carga valor inicial --- .../core/components/worker-autocomplete/index.js | 10 ++++++---- modules/claim/front/basic-data/index.html | 3 +++ modules/worker/back/methods/worker/search.js | 15 +++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/front/core/components/worker-autocomplete/index.js b/front/core/components/worker-autocomplete/index.js index 436959c5d..24cc02797 100755 --- a/front/core/components/worker-autocomplete/index.js +++ b/front/core/components/worker-autocomplete/index.js @@ -7,6 +7,8 @@ export default class WorkerAutocomplete extends Autocomplete { } $onInit() { + super.$onInit(); + let url = 'Workers/search'; if (this.departments) { const parameter = encodeURIComponent(JSON.stringify(this.departments)); @@ -17,11 +19,11 @@ export default class WorkerAutocomplete extends Autocomplete { url: url, searchFunction: function({$search}) { return {and: [ - {'u.active': {neq: false}}, + {'active': {neq: false}}, {or: [ - {'u.name': $search}, - {'u.nickname': {like: '%' + $search + '%'}}, - {'w.code': {like: $search + '%'}} + {'name': $search}, + {'nickname': {like: '%' + $search + '%'}}, + {'code': {like: $search + '%'}} ]} ]}; }, diff --git a/modules/claim/front/basic-data/index.html b/modules/claim/front/basic-data/index.html index 16e134c60..70be85a8f 100644 --- a/modules/claim/front/basic-data/index.html +++ b/modules/claim/front/basic-data/index.html @@ -34,6 +34,9 @@ where="{role: 'salesPerson'}" label="Attended by"> + + { filter = mergeFilters(filter, {where}); } - const stmt = new ParameterizedSQL( - `SELECT DISTINCT w.id, w.code, u.name, u.nickname - FROM worker w - JOIN account.user u ON u.id = w.id - JOIN business b ON b.workerFk = w.id - JOIN department d ON d.id = b.departmentFk`); + const stmt = new ParameterizedSQL(` + SELECT * + FROM( + SELECT DISTINCT w.id, w.code, u.name, u.nickname, u.active + FROM worker w + JOIN account.user u ON u.id = w.id + JOIN business b ON b.workerFk = w.id + JOIN department d ON d.id = b.departmentFk + ) w`); stmt.merge(conn.makeSuffix(filter)); return conn.executeStmt(stmt); From c876719a5c9fb66ed88735596388833389338d15 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 13 Jul 2023 12:59:02 +0200 Subject: [PATCH 15/23] refs #5244 fix: corregidos errores --- front/core/components/autocomplete/index.js | 9 +++- .../worker-autocomplete/index.spec.js | 54 ------------------- modules/worker/back/methods/worker/search.js | 5 +- 3 files changed, 10 insertions(+), 58 deletions(-) delete mode 100644 front/core/components/worker-autocomplete/index.spec.js diff --git a/front/core/components/autocomplete/index.js b/front/core/components/autocomplete/index.js index b8a0617b3..c78c29398 100755 --- a/front/core/components/autocomplete/index.js +++ b/front/core/components/autocomplete/index.js @@ -152,7 +152,14 @@ export default class Autocomplete extends Field { filter.include = this.include; let json = encodeURIComponent(JSON.stringify(filter)); - this.$http.get(`${this.url}?filter=${json}`).then( + + let url; + if (this.url.includes('?')) + url = `${this.url}&filter=${json}`; + else + url = `${this.url}?filter=${json}`; + + this.$http.get(url).then( json => this.onSelectionRequest(json.data), () => this.onSelectionRequest() ); diff --git a/front/core/components/worker-autocomplete/index.spec.js b/front/core/components/worker-autocomplete/index.spec.js deleted file mode 100644 index 847761179..000000000 --- a/front/core/components/worker-autocomplete/index.spec.js +++ /dev/null @@ -1,54 +0,0 @@ -describe('Component vnAutocomplete', () => { - let $element; - let controller; - let data = {id: 1, name: 'Bruce Wayne'}; - - beforeEach(ngModule('vnCore')); - - beforeEach(inject(($compile, $rootScope) => { - $element = $compile(``)($rootScope); - controller = $element.controller('vnAutocomplete'); - })); - - afterEach(() => { - $element.remove(); - }); - - describe('url() setter', () => { - it(`should set the url property`, () => { - controller.url = '/TestModels'; - - expect(controller.url).toEqual('/TestModels'); - }); - }); - - describe('field() setter/getter', () => { - it(`should set the field property`, () => { - controller.field = 'id'; - - expect(controller.field).toEqual('id'); - }); - }); - - describe('selection property', () => { - beforeEach(() => { - controller.field = data.id; - }); - - it(`should set selection finding an existing item in the initialData property`, () => { - controller.initialData = data; - - expect(controller.selection).toEqual(data); - }); - - it(`should set selection finding an existing item in the data property`, () => { - controller.data = [data]; - - expect(controller.selection).toEqual(data); - }); - - it(`should set selection to null when can't find an existing item in the data property`, () => { - expect(controller.selection).toEqual(null); - }); - }); -}); diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 8be9ecc5e..50fe71235 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -36,18 +36,17 @@ module.exports = Self => { }); const allLeaves = await getAllLeaves(ctx, departments); - const where = {'d.id': {inq: allLeaves}}; + const where = {'departmentFk': {inq: allLeaves}}; filter = mergeFilters(filter, {where}); } const stmt = new ParameterizedSQL(` SELECT * FROM( - SELECT DISTINCT w.id, w.code, u.name, u.nickname, u.active + SELECT DISTINCT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk FROM worker w JOIN account.user u ON u.id = w.id JOIN business b ON b.workerFk = w.id - JOIN department d ON d.id = b.departmentFk ) w`); stmt.merge(conn.makeSuffix(filter)); From 75a66571baa3be6244e36b9e7877eaebf8930b76 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 13 Jul 2023 12:59:39 +0200 Subject: [PATCH 16/23] refs #5244 refactor: modificados todos los url='activeWith...' --- modules/claim/front/basic-data/index.html | 15 +++++-------- modules/claim/front/development/index.html | 13 ++++-------- modules/claim/front/search-panel/index.html | 20 ++++++------------ modules/client/front/basic-data/index.html | 21 ++++++++----------- modules/client/front/create/index.html | 21 ++++++++----------- modules/client/front/search-panel/index.html | 11 +++------- .../front/request-search-panel/index.html | 13 ++++-------- .../front/index/search-panel/index.html | 14 +++++-------- modules/order/front/search-panel/index.html | 11 ++++------ modules/route/front/basic-data/index.html | 13 ++---------- modules/route/front/create/index.html | 12 ++++------- modules/route/front/search-panel/index.html | 15 +++++-------- modules/supplier/front/basic-data/index.html | 18 +++++++--------- modules/ticket/front/search-panel/index.html | 14 +++++-------- modules/ticket/front/tracking/edit/index.html | 9 +------- modules/worker/front/basic-data/index.html | 7 ++----- modules/worker/front/create/index.html | 7 ++----- .../front/department/basic-data/index.html | 14 ++++++------- 18 files changed, 83 insertions(+), 165 deletions(-) diff --git a/modules/claim/front/basic-data/index.html b/modules/claim/front/basic-data/index.html index 70be85a8f..10aa7623a 100644 --- a/modules/claim/front/basic-data/index.html +++ b/modules/claim/front/basic-data/index.html @@ -25,17 +25,12 @@ - - + disabled="false" + show-field="nickname" + ng-model="$ctrl.claim.workerFk" + departments="['VT']" + label="Attended by"> - + @@ -66,16 +66,11 @@ show-field="description" rule> - - + --> - \ No newline at end of file + diff --git a/modules/claim/front/search-panel/index.html b/modules/claim/front/search-panel/index.html index 151a06c8e..fbc527d60 100644 --- a/modules/claim/front/search-panel/index.html +++ b/modules/claim/front/search-panel/index.html @@ -22,26 +22,18 @@ - - {{firstName}} {{name}} - - + - {{firstName}} {{name}} - + - @@ -59,18 +59,15 @@ - - - + - - {{firstName}} {{lastName}} - + departments="['VT']" + show-field="nickname"> + - - {{code}} - {{town.name}} ({{town.province.name}}, + {{code}} - {{town.name}} ({{town.province.name}}, {{town.province.country.country}}) @@ -82,7 +79,7 @@ - {{name}}, {{province.name}} + {{name}}, {{province.name}} ({{province.country.country}}) @@ -150,4 +147,4 @@ - \ No newline at end of file + diff --git a/modules/client/front/search-panel/index.html b/modules/client/front/search-panel/index.html index a02f93882..2105d3a65 100644 --- a/modules/client/front/search-panel/index.html +++ b/modules/client/front/search-panel/index.html @@ -14,17 +14,12 @@ vn-one label="Name" ng-model="filter.name"> - - {{firstName}} {{name}} - + - - {{firstName}} {{lastName}} - + departments="['VT']" + label="Salesperson"> + -
@@ -43,16 +43,12 @@ label="Nickname" ng-model="filter.nickname"> - - {{firstName}} {{name}} - + - - + -
\ No newline at end of file +
diff --git a/modules/route/front/basic-data/index.html b/modules/route/front/basic-data/index.html index c63fee53b..a51a3dbdb 100644 --- a/modules/route/front/basic-data/index.html +++ b/modules/route/front/basic-data/index.html @@ -8,20 +8,11 @@
- - -
{{::nickname}}
-
{{::name}}
-
-
+ - - + show-field="nickname"> + diff --git a/modules/route/front/search-panel/index.html b/modules/route/front/search-panel/index.html index a78d88d1c..f3d392580 100644 --- a/modules/route/front/search-panel/index.html +++ b/modules/route/front/search-panel/index.html @@ -1,7 +1,7 @@
@@ -15,16 +15,11 @@ - - + show-field="nickname"> + - - + @@ -45,7 +41,7 @@ @@ -63,4 +59,4 @@ ng-click="watcher.loadOriginalData()"> - \ No newline at end of file + diff --git a/modules/ticket/front/search-panel/index.html b/modules/ticket/front/search-panel/index.html index 52bede97f..d80f21531 100644 --- a/modules/ticket/front/search-panel/index.html +++ b/modules/ticket/front/search-panel/index.html @@ -1,7 +1,7 @@
@@ -62,16 +62,12 @@ label="Nickname" ng-model="filter.nickname"> - - {{firstName}} {{name}} - + + ng-model="$ctrl.workerFk"> - - diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index d89d88f2e..2d85d018d 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -37,14 +37,11 @@ - - + - - + - - + - + @@ -78,12 +76,12 @@ label="Fill in days without physical check-ins" ng-model="$ctrl.department.hasToRefill"> - - + + - + From a6b8f4ddf88a5960e9dda46a89b06129942bcba0 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Jul 2023 09:46:25 +0200 Subject: [PATCH 17/23] refs #5244 fix: tfront --- front/core/lib/component.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/front/core/lib/component.js b/front/core/lib/component.js index 6bb83e55a..5695d9449 100644 --- a/front/core/lib/component.js +++ b/front/core/lib/component.js @@ -12,9 +12,10 @@ export default class Component extends EventEmitter { * @param {HTMLElement} $element The main component element * @param {$rootScope.Scope} $scope The element scope * @param {Function} $transclude The transclusion function + * @param {Function} $location The location function */ - constructor($element, $scope, $transclude) { - super(); + constructor($element, $scope, $transclude, $location) { + super($element, $scope, $transclude, $location); this.$ = $scope; if (!$element) return; @@ -164,7 +165,7 @@ export default class Component extends EventEmitter { $transclude.$$boundTransclude.$$slots[slot]; } } -Component.$inject = ['$element', '$scope', '$transclude']; +Component.$inject = ['$element', '$scope', '$location', '$state']; /* * Automatically adds the most used services to the prototype, so they are From d6a27741b53c30de3999faa81212867c674ba427 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Jul 2023 09:50:56 +0200 Subject: [PATCH 18/23] a --- .../back/methods/worker/getItemTypeWorker.js | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 modules/worker/back/methods/worker/getItemTypeWorker.js diff --git a/modules/worker/back/methods/worker/getItemTypeWorker.js b/modules/worker/back/methods/worker/getItemTypeWorker.js deleted file mode 100644 index b1f49ae99..000000000 --- a/modules/worker/back/methods/worker/getItemTypeWorker.js +++ /dev/null @@ -1,65 +0,0 @@ -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; -const buildFilter = require('vn-loopback/util/filter').buildFilter; -const mergeFilters = require('vn-loopback/util/filter').mergeFilters; - -module.exports = Self => { - Self.remoteMethod('getItemTypeWorker', { - description: 'Returns the workers that appear in itemType', - accessType: 'READ', - accepts: [{ - arg: 'filter', - type: 'Object', - description: 'Filter defining where and paginated data', - required: true - }], - returns: { - type: ['object'], - root: true - }, - http: { - path: `/getItemTypeWorker`, - verb: 'GET' - } - }); - - Self.getItemTypeWorker = async(filter, options) => { - const myOptions = {}; - const conn = Self.dataSource.connector; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - const query = - `SELECT DISTINCT u.id, w.firstName, w.lastName, u.nickname, u.name - FROM itemType it - JOIN worker w ON w.id = it.workerFk - JOIN account.user u ON u.id = w.id`; - - let stmt = new ParameterizedSQL(query); - - let clientFilter = Object.assign({}, filter); - clientFilter.where = buildFilter(filter.where, (param, value) => { - switch (param) { - case 'role': - return {'r.name': value}; - case 'firstName': - return {or: [ - {'w.firstName': {like: `%${value}%`}}, - {'w.lastName': {like: `%${value}%`}}, - {'u.name': {like: `%${value}%`}}, - {'u.nickname': {like: `%${value}%`}} - ]}; - case 'id': - return {'w.id': value}; - } - }); - - let myFilter = { - where: {'u.active': true} - }; - - myFilter = mergeFilters(myFilter, clientFilter); - stmt.merge(conn.makeSuffix(myFilter)); - return conn.executeStmt(stmt); - }; -}; From 7312ed9cc4dbea12b624be248b786e29e2aa2052 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Jul 2023 09:56:07 +0200 Subject: [PATCH 19/23] refs #5244 fix back test --- .../methods/ticket-request/specs/getItemTypeWorkers.spec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/ticket-request/specs/getItemTypeWorkers.spec.js b/modules/ticket/back/methods/ticket-request/specs/getItemTypeWorkers.spec.js index ae5c508b6..c57451c26 100644 --- a/modules/ticket/back/methods/ticket-request/specs/getItemTypeWorkers.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/getItemTypeWorkers.spec.js @@ -1,12 +1,10 @@ const models = require('vn-loopback/server/server').models; describe('ticket-request getItemTypeWorker()', () => { - const ctx = {req: {accessToken: {userId: 18}}}; - it('should return the buyer as result', async() => { const filter = {where: {firstName: 'buyer'}}; - const result = await models.TicketRequest.getItemTypeWorker(ctx, filter); + const result = await models.TicketRequest.getItemTypeWorker(filter); expect(result.length).toEqual(1); }); @@ -14,7 +12,7 @@ describe('ticket-request getItemTypeWorker()', () => { it('should return the workers at itemType as result', async() => { const filter = {}; - const result = await models.TicketRequest.getItemTypeWorker(ctx, filter); + const result = await models.TicketRequest.getItemTypeWorker(filter); expect(result.length).toBeGreaterThan(1); }); From 2f27f32c45c64034f538b0feb1dad99f301cb388 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Jul 2023 11:26:48 +0200 Subject: [PATCH 20/23] refs #5244 fix: e2e --- e2e/helpers/extensions.js | 2 ++ e2e/helpers/selectors.js | 14 +++++++------- e2e/paths/05-ticket/05_tracking_state.spec.js | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index fe3ef08bd..b6ea32a6c 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -632,6 +632,7 @@ let actions = { await this.write(selector, value.toString()); break; case 'vn-autocomplete': + case 'vn-worker-autocomplete': if (value) await this.autocompleteSearch(selector, value.toString()); else @@ -667,6 +668,7 @@ let actions = { switch (tagName) { case 'vn-textfield': case 'vn-autocomplete': + case 'vn-worker-autocomplete': case 'vn-input-time': case 'vn-datalist': el = await input.$('input'); diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 977c8a837..3302280e3 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -187,7 +187,7 @@ export default { country: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.countryFk"]', userName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.userName"]', email: 'vn-client-create vn-textfield[ng-model="$ctrl.client.email"]', - salesPerson: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.salesPersonFk"]', + salesPerson: 'vn-client-create vn-worker-autocomplete[ng-model="$ctrl.client.salesPersonFk"]', saveNewProvicenButton: '#saveProvince', saveNewCityButton: '#saveCity', saveNewPoscode: '#savePostcode', @@ -199,7 +199,7 @@ export default { email: 'vn-client-basic-data vn-textfield[ng-model="$ctrl.client.email"]', phone: 'vn-client-basic-data vn-textfield[ng-model="$ctrl.client.phone"]', mobile: 'vn-client-basic-data vn-textfield[ng-model="$ctrl.client.mobile"]', - salesPerson: 'vn-client-basic-data vn-autocomplete[ng-model="$ctrl.client.salesPersonFk"]', + salesPerson: 'vn-client-basic-data vn-worker-autocomplete[ng-model="$ctrl.client.salesPersonFk"]', channel: 'vn-client-basic-data vn-autocomplete[ng-model="$ctrl.client.contactChannelFk"]', transferor: 'vn-client-basic-data vn-autocomplete[ng-model="$ctrl.client.transferorFk"]', businessType: 'vn-client-basic-data vn-autocomplete[ng-model="$ctrl.client.businessTypeFk"]', @@ -735,7 +735,7 @@ export default { }, createStateView: { state: 'vn-autocomplete[ng-model="$ctrl.stateFk"]', - worker: 'vn-autocomplete[ng-model="$ctrl.workerFk"]', + worker: 'vn-worker-autocomplete[ng-model="$ctrl.workerFk"]', saveStateButton: `button[type=submit]` }, claimsIndex: { @@ -781,12 +781,12 @@ export default { firstClaimReason: 'vn-claim-development vn-horizontal:nth-child(1) vn-autocomplete[ng-model="claimDevelopment.claimReasonFk"]', firstClaimResult: 'vn-claim-development vn-horizontal:nth-child(1) vn-autocomplete[ng-model="claimDevelopment.claimResultFk"]', firstClaimResponsible: 'vn-claim-development vn-horizontal:nth-child(1) vn-autocomplete[ng-model="claimDevelopment.claimResponsibleFk"]', - firstClaimWorker: 'vn-claim-development vn-horizontal:nth-child(1) vn-autocomplete[ng-model="claimDevelopment.workerFk"]', + firstClaimWorker: 'vn-claim-development vn-horizontal:nth-child(1) vn-worker-autocomplete[ng-model="claimDevelopment.workerFk"]', firstClaimRedelivery: 'vn-claim-development vn-horizontal:nth-child(1) vn-autocomplete[ng-model="claimDevelopment.claimRedeliveryFk"]', secondClaimReason: 'vn-claim-development vn-horizontal:nth-child(2) vn-autocomplete[ng-model="claimDevelopment.claimReasonFk"]', secondClaimResult: 'vn-claim-development vn-horizontal:nth-child(2) vn-autocomplete[ng-model="claimDevelopment.claimResultFk"]', secondClaimResponsible: 'vn-claim-development vn-horizontal:nth-child(2) vn-autocomplete[ng-model="claimDevelopment.claimResponsibleFk"]', - secondClaimWorker: 'vn-claim-development vn-horizontal:nth-child(2) vn-autocomplete[ng-model="claimDevelopment.workerFk"]', + secondClaimWorker: 'vn-claim-development vn-horizontal:nth-child(2) vn-worker-autocomplete[ng-model="claimDevelopment.workerFk"]', secondClaimRedelivery: 'vn-claim-development vn-horizontal:nth-child(2) vn-autocomplete[ng-model="claimDevelopment.claimRedeliveryFk"]', saveDevelopmentButton: 'button[type=submit]' }, @@ -854,7 +854,7 @@ export default { }, createRouteView: { - worker: 'vn-route-create vn-autocomplete[ng-model="$ctrl.route.workerFk"]', + worker: 'vn-route-create vn-worker-autocomplete[ng-model="$ctrl.route.workerFk"]', createdDatePicker: 'vn-route-create vn-date-picker[ng-model="$ctrl.route.created"]', vehicleAuto: 'vn-route-create vn-autocomplete[ng-model="$ctrl.route.vehicleFk"]', agency: 'vn-route-create vn-autocomplete[ng-model="$ctrl.route.agencyModeFk"]', @@ -976,7 +976,7 @@ export default { street: 'vn-worker-create vn-textfield[ng-model="$ctrl.worker.street"]', user: 'vn-worker-create vn-textfield[ng-model="$ctrl.worker.name"]', email: 'vn-worker-create vn-textfield[ng-model="$ctrl.worker.email"]', - boss: 'vn-worker-create vn-autocomplete[ng-model="$ctrl.worker.bossFk"]', + boss: 'vn-worker-create vn-worker-autocomplete[ng-model="$ctrl.worker.bossFk"]', role: 'vn-worker-create vn-autocomplete[ng-model="$ctrl.worker.roleFk"]', iban: 'vn-worker-create vn-textfield[ng-model="$ctrl.worker.iban"]', createButton: 'vn-worker-create vn-submit[label="Create"]', diff --git a/e2e/paths/05-ticket/05_tracking_state.spec.js b/e2e/paths/05-ticket/05_tracking_state.spec.js index 949c9a8e6..9ac373287 100644 --- a/e2e/paths/05-ticket/05_tracking_state.spec.js +++ b/e2e/paths/05-ticket/05_tracking_state.spec.js @@ -59,7 +59,7 @@ describe('Ticket Create new tracking state path', () => { const result = await page .waitToGetProperty(selectors.createStateView.worker, 'value'); - expect(result).toEqual('salesPersonNick'); + expect(result).toEqual('salesPerson'); }); it(`should succesfully create a valid state`, async() => { From 4657bf4e433c9292d2604321d2f0dab865073cce Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 22 Aug 2023 14:58:26 +0200 Subject: [PATCH 21/23] refs #6143 refactor: ibanValidation with countryCode param --- loopback/util/validateIban.js | 3 ++- modules/client/back/models/client.js | 8 +++----- modules/supplier/back/models/supplier-account.js | 9 +++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/loopback/util/validateIban.js b/loopback/util/validateIban.js index 3ca09ef95..ed3e00426 100644 --- a/loopback/util/validateIban.js +++ b/loopback/util/validateIban.js @@ -1,6 +1,7 @@ -module.exports = function(iban) { +module.exports = function(iban, countryCode) { if (iban == null) return true; if (typeof iban != 'string') return false; + if (countryCode?.toLowerCase() != 'es') return true; iban = iban.toUpperCase(); iban = trim(iban); diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 129924b78..bdf2f91b5 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -90,16 +90,14 @@ module.exports = Self => { }); async function ibanNeedsValidation(err, done) { + const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk); const filter = { fields: ['code'], - where: {id: this.countryFk} + where: {id: bankEntity.countryFk} }; const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code.toLowerCase() : null; - if (code != 'es') - return done(); - if (!validateIban(this.iban)) + if (!validateIban(this.iban, country?.code)) err(); done(); } diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js index 51da113ec..7a9e14421 100644 --- a/modules/supplier/back/models/supplier-account.js +++ b/modules/supplier/back/models/supplier-account.js @@ -7,18 +7,15 @@ module.exports = Self => { }); async function ibanValidation(err, done) { - const supplier = await Self.app.models.Supplier.findById(this.supplierFk); + const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk); const filter = { fields: ['code'], - where: {id: supplier.countryFk} + where: {id: bankEntity.countryFk} }; const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code.toLowerCase() : null; - if (code != 'es') - return done(); - if (!validateIban(this.iban)) + if (!validateIban(this.iban, country?.code)) err(); done(); } From dad792cb76269af581c0664b518a4af2bf9a08c4 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 24 Aug 2023 07:40:37 +0200 Subject: [PATCH 22/23] refs #5244 move changes sql --- db/changes/{232601 => 233601}/00-aclWorker.sql | 0 db/changes/{232601 => 233601}/00-department.sql | 0 front/core/components/worker-autocomplete/index.js | 2 +- front/core/lib/event-emitter.js | 1 + modules/worker/back/methods/worker/search.js | 4 ++-- 5 files changed, 4 insertions(+), 3 deletions(-) rename db/changes/{232601 => 233601}/00-aclWorker.sql (100%) rename db/changes/{232601 => 233601}/00-department.sql (100%) diff --git a/db/changes/232601/00-aclWorker.sql b/db/changes/233601/00-aclWorker.sql similarity index 100% rename from db/changes/232601/00-aclWorker.sql rename to db/changes/233601/00-aclWorker.sql diff --git a/db/changes/232601/00-department.sql b/db/changes/233601/00-department.sql similarity index 100% rename from db/changes/232601/00-department.sql rename to db/changes/233601/00-department.sql diff --git a/front/core/components/worker-autocomplete/index.js b/front/core/components/worker-autocomplete/index.js index 24cc02797..70ca69e6e 100755 --- a/front/core/components/worker-autocomplete/index.js +++ b/front/core/components/worker-autocomplete/index.js @@ -16,7 +16,7 @@ export default class WorkerAutocomplete extends Autocomplete { } Object.assign(this, { label: 'Worker', - url: url, + url, searchFunction: function({$search}) { return {and: [ {'active': {neq: false}}, diff --git a/front/core/lib/event-emitter.js b/front/core/lib/event-emitter.js index 0e0ce1872..83e361253 100644 --- a/front/core/lib/event-emitter.js +++ b/front/core/lib/event-emitter.js @@ -83,3 +83,4 @@ export default class EventEmitter { } } } +EventEmitter.$inject = ['$element', '$scope']; diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 50fe71235..cd0a466ea 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -3,11 +3,11 @@ const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { Self.remoteMethodCtx('search', { - description: 'Returns an array of search from an specified worker', + description: 'Returns an array of search results for a specified worker', accepts: [{ arg: 'filter', type: 'object', - description: 'Filter defining where and paginated data', + description: 'Filter to define conditions and paginate the data.', required: true }, { From f54a23922904e7afba8b5b69aff839769de337ff Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 25 Aug 2023 09:46:53 +0200 Subject: [PATCH 23/23] fixes #6143 fixes: this.bankEntityFk no existe --- loopback/util/specs/validateIban.spec.js | 44 ++++++++++++++----- modules/client/back/models/client.js | 3 ++ .../supplier/back/models/supplier-account.js | 3 ++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/loopback/util/specs/validateIban.spec.js b/loopback/util/specs/validateIban.spec.js index a5d08d4c4..dd096c1b5 100644 --- a/loopback/util/specs/validateIban.spec.js +++ b/loopback/util/specs/validateIban.spec.js @@ -1,21 +1,45 @@ const validateIban = require('../validateIban'); describe('IBAN validation', () => { - it('should return false for non-IBAN input', () => { - let isValid = validateIban('Pepinillos'); + it('should return false for invalid Spanish IBAN format', () => { + let isValid = validateIban('ES00 9999 0000 9999 0000 9999', 'ES'); expect(isValid).toBeFalsy(); }); - it('should return false for invalid spanish IBAN input', () => { - let isValid = validateIban('ES00 9999 0000 9999 0000 9999'); - - expect(isValid).toBeFalsy(); - }); - - it('should return true for valid spanish IBAN', () => { - let isValid = validateIban('ES91 2100 0418 4502 0005 1332'); + it('should return true for valid Spanish IBAN', () => { + let isValid = validateIban('ES91 2100 0418 4502 0005 1332', 'ES'); expect(isValid).toBeTruthy(); }); + + it('should return false for invalid Spanish IBAN with incorrect length', () => { + let isValid = validateIban('ES91210004184502000513', 'ES'); + + expect(isValid).toBeFalsy(); + }); + + it('should return false for invalid Spanish IBAN with incorrect module97 result', () => { + let isValid = validateIban('ES9121000418450200051331', 'ES'); + + expect(isValid).toBeFalsy(); + }); + + it('should return true for a non-Spanish countryCode', () => { + let isValid = validateIban('DE89370400440532013000', 'AT'); + + expect(isValid).toBeTruthy(); + }); + + it('should return true for null IBAN', () => { + let isValid = validateIban(null, 'ES'); + + expect(isValid).toBeTruthy(); + }); + + it('should return false for non-string IBAN', () => { + let isValid = validateIban(12345, 'ES'); + + expect(isValid).toBeFalsy(); + }); }); diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index bdf2f91b5..8e720484f 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -90,6 +90,9 @@ module.exports = Self => { }); async function ibanNeedsValidation(err, done) { + if (!this.bankEntityFk) + return done(); + const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk); const filter = { fields: ['code'], diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js index 7a9e14421..691e72580 100644 --- a/modules/supplier/back/models/supplier-account.js +++ b/modules/supplier/back/models/supplier-account.js @@ -7,6 +7,9 @@ module.exports = Self => { }); async function ibanValidation(err, done) { + if (!this.bankEntityFk) + return done(); + const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk); const filter = { fields: ['code'],