From 6017894ba9b36f1334706bc5e8307f545fc8b9dd Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Thu, 7 Jan 2021 15:14:38 +0100 Subject: [PATCH 01/18] first step bankEntity --- db/changes/10270-wiseMan/00-ACL.sql | 1 + .../back/models/supplier-account.json | 5 ++ modules/supplier/front/account/index.html | 75 +++++++++++++++++++ modules/supplier/front/account/index.js | 49 ++++++++++++ modules/supplier/front/account/index.spec.js | 34 +++++++++ modules/supplier/front/account/locale/es.yml | 2 + modules/supplier/front/bankentity/index.html | 40 ++++++++++ modules/supplier/front/bankentity/index.js | 42 +++++++++++ .../supplier/front/bankentity/index.spec.js | 34 +++++++++ .../supplier/front/bankentity/locale/es.yml | 11 +++ modules/supplier/front/bankentity/style.scss | 9 +++ modules/supplier/front/index.js | 1 + modules/supplier/front/routes.json | 10 +++ 13 files changed, 313 insertions(+) create mode 100644 db/changes/10270-wiseMan/00-ACL.sql create mode 100644 modules/supplier/front/account/index.html create mode 100644 modules/supplier/front/account/index.js create mode 100644 modules/supplier/front/account/index.spec.js create mode 100644 modules/supplier/front/account/locale/es.yml create mode 100644 modules/supplier/front/bankentity/index.html create mode 100644 modules/supplier/front/bankentity/index.js create mode 100644 modules/supplier/front/bankentity/index.spec.js create mode 100644 modules/supplier/front/bankentity/locale/es.yml create mode 100644 modules/supplier/front/bankentity/style.scss diff --git a/db/changes/10270-wiseMan/00-ACL.sql b/db/changes/10270-wiseMan/00-ACL.sql new file mode 100644 index 0000000000..e6374d5a2b --- /dev/null +++ b/db/changes/10270-wiseMan/00-ACL.sql @@ -0,0 +1 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('SupplierAccount', '*', 'WRITE', 'ALLOW', 'ROLE', 'administrative'); \ No newline at end of file diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index 237934f8c1..364bdaae51 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -45,6 +45,11 @@ "type": "belongsTo", "model": "Supplier", "foreignKey": "supplierFk" + }, + "bankEntity": { + "type": "belongsTo", + "model": "BankEntity", + "foreignKey": "bankEntityFk" } } } \ No newline at end of file diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html new file mode 100644 index 0000000000..864b362286 --- /dev/null +++ b/modules/supplier/front/account/index.html @@ -0,0 +1,75 @@ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/modules/supplier/front/account/index.js b/modules/supplier/front/account/index.js new file mode 100644 index 0000000000..069601a207 --- /dev/null +++ b/modules/supplier/front/account/index.js @@ -0,0 +1,49 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +class Controller extends Section { + constructor($element, $) { + super($element, $); + this.include = { + relation: 'bankEntity', + scope: { + fields: ['countryFk', 'id', 'name', 'bic'] + } + }; + } + + add() { + this.$.model.insert({ + supplierFk: this.$params.id + }); + } + + onSubmit() { + this.$.watcher.check(); + this.$.model.save().then(() => { + this.$.watcher.notifySaved(); + this.$.watcher.updateOriginalData(); + this.card.reload(); + }); + } + + showBankEntity(event) { + if (event.defaultPrevented) return; + event.preventDefault(); + this.$.bankEntity.show(); + } + + onBankEntityAccept() { + const query = `SupplierAccounts/${this.$params.id}/createBankEntity`; + return this.$http.patch(query, this.newBankEntity) + .then(res => this.supplierAccount.bankEntityFk = res.data.id); + } +} + +ngModule.vnComponent('vnSupplierAccount', { + template: require('./index.html'), + controller: Controller, + require: { + card: '^vnSupplierCard' + } +}); diff --git a/modules/supplier/front/account/index.spec.js b/modules/supplier/front/account/index.spec.js new file mode 100644 index 0000000000..34a9ce143d --- /dev/null +++ b/modules/supplier/front/account/index.spec.js @@ -0,0 +1,34 @@ +import './index.js'; +import crudModel from 'core/mocks/crud-model'; + +describe('Item', () => { + describe('Component vnItemTags', () => { + let $scope; + let controller; + + beforeEach(ngModule('item')); + + beforeEach(inject(($componentController, $rootScope) => { + $scope = $rootScope.$new(); + $scope.model = crudModel; + $scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}]; + const $element = angular.element(''); + controller = $componentController('vnItemTags', {$element, $scope}); + })); + + describe('getHighestPriority', () => { + it('should return the highest priority value + 1 from the array', () => { + let result = controller.getHighestPriority(); + + expect(result).toEqual(3); + }); + + it('should return 1 when there is no priority defined', () => { + $scope.model.data = []; + let result = controller.getHighestPriority(); + + expect(result).toEqual(1); + }); + }); + }); +}); diff --git a/modules/supplier/front/account/locale/es.yml b/modules/supplier/front/account/locale/es.yml new file mode 100644 index 0000000000..7443ad4e35 --- /dev/null +++ b/modules/supplier/front/account/locale/es.yml @@ -0,0 +1,2 @@ +Bank entity: Entidad bancaria +swift: Swift BIC \ No newline at end of file diff --git a/modules/supplier/front/bankentity/index.html b/modules/supplier/front/bankentity/index.html new file mode 100644 index 0000000000..ed1691f27f --- /dev/null +++ b/modules/supplier/front/bankentity/index.html @@ -0,0 +1,40 @@ + + +

Please, ensure you put the correct data!

+ + + + + + + + + + +
+ + + + +
diff --git a/modules/supplier/front/bankentity/index.js b/modules/supplier/front/bankentity/index.js new file mode 100644 index 0000000000..20be668dad --- /dev/null +++ b/modules/supplier/front/bankentity/index.js @@ -0,0 +1,42 @@ +import ngModule from '../module'; +import Component from 'core/lib/component'; +import './style.scss'; + +class Controller extends Component { + open() { + this.$.bankentityDialog.show(); + } + + onOpen() { + this.location = {}; + this.$.bankentity.focus(); + } + + onCountryResponse(response) { + this.location.countryFk = response.id; + } + + onAccept() { + try { + if (!this.location.countryFk) + throw new Error(`The country can't be empty`); + + this.$http.patch(`bankentities`, this.location).then(() => { + this.vnApp.showMessage(this.$t('The bankentity has been created. You can save the data now')); + this.emit('response', {$response: this.location}); + }); + } catch (e) { + this.vnApp.showError(this.$t(e.message)); + return false; + } + return true; + } +} + +ngModule.vnComponent('vnNewBankentity', { + template: require('./index.html'), + controller: Controller, + bindings: { + data: '<', + } +}); diff --git a/modules/supplier/front/bankentity/index.spec.js b/modules/supplier/front/bankentity/index.spec.js new file mode 100644 index 0000000000..bb5591f357 --- /dev/null +++ b/modules/supplier/front/bankentity/index.spec.js @@ -0,0 +1,34 @@ +import './index'; + +describe('Supplier', () => { + describe('Component vnNewBankentity', () => { + let controller; + let $httpBackend; + let $scope; + + beforeEach(ngModule('supplier')); + + beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => { + $httpBackend = _$httpBackend_; + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnNewBankentity', {$element, $scope}); + controller.client = {id: 101}; + })); + + describe('onAccept()', () => { + it('should perform a POST query and show a success snackbar', () => { + let params = {countryFk: 1}; + controller.location = {countryFk: 1}; + + jest.spyOn(controller.vnApp, 'showMessage'); + $httpBackend.expect('PATCH', `bankentity`, params).respond(200, params); + + controller.onAccept(); + $httpBackend.flush(); + + expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The bankentity has been created. You can save the data now'); + }); + }); + }); +}); diff --git a/modules/supplier/front/bankentity/locale/es.yml b/modules/supplier/front/bankentity/locale/es.yml new file mode 100644 index 0000000000..782690e885 --- /dev/null +++ b/modules/supplier/front/bankentity/locale/es.yml @@ -0,0 +1,11 @@ +New postcode: Nuevo código postal +New city: Nueva ciudad +New province: Nueva provincia +Please, ensure you put the correct data!: ¡Por favor, asegúrate de poner los datos correctos! +The postcode can't be empty: El código postal no puede quedar vacío +The town can't be empty: La población no puede quedar vacía +The province can't be empty: La provincia no puede quedar vacía +The country can't be empty: El país no puede quedar vacío +The postcode has been created. You can save the data now: Se ha creado el código postal. Ahora puedes guardar los datos +The city has been created: Se ha creado la ciudad +The province has been created: Se ha creado la provincia \ No newline at end of file diff --git a/modules/supplier/front/bankentity/style.scss b/modules/supplier/front/bankentity/style.scss new file mode 100644 index 0000000000..adad7ab019 --- /dev/null +++ b/modules/supplier/front/bankentity/style.scss @@ -0,0 +1,9 @@ +@import "variables"; + +vn-new-bankentity { + vn-dialog { + p { + color: $color-alert + } + } +} \ No newline at end of file diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js index 9a9334c416..80c49a8b45 100644 --- a/modules/supplier/front/index.js +++ b/modules/supplier/front/index.js @@ -8,6 +8,7 @@ import './search-panel'; import './summary'; import './basic-data'; import './fiscal-data'; +import './account'; import './contact'; import './log'; import './consumption'; diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index 54d203c8cd..f76af9d979 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -9,6 +9,7 @@ {"state": "supplier.index", "icon": "icon-supplier"} ], "card": [ + {"state": "supplier.card.account", "icon": "face"}, {"state": "supplier.card.basicData", "icon": "settings"}, {"state": "supplier.card.fiscalData", "icon": "account_balance"}, {"state": "supplier.card.billingData", "icon": "icon-payment"}, @@ -96,6 +97,15 @@ "supplier": "$ctrl.supplier" }, "acl": ["administrative"] + },{ + "url": "/account", + "state": "supplier.card.account", + "component": "vn-supplier-account", + "description": "Account", + "params": { + "supplier": "$ctrl.supplier" + }, + "acl": ["administrative"] } ] } \ No newline at end of file From 31f18db72d6a25e26065515baf88d1099483497b Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Thu, 7 Jan 2021 15:14:50 +0100 Subject: [PATCH 02/18] first step bankEntity --- modules/supplier/front/account/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/supplier/front/account/index.js b/modules/supplier/front/account/index.js index 069601a207..e72e6d0db7 100644 --- a/modules/supplier/front/account/index.js +++ b/modules/supplier/front/account/index.js @@ -38,6 +38,13 @@ class Controller extends Section { return this.$http.patch(query, this.newBankEntity) .then(res => this.supplierAccount.bankEntityFk = res.data.id); } + + onResponse(response) { + this.supplier.postcode = response.code; + this.supplier.city = response.city; + this.supplier.provinceFk = response.provinceFk; + this.supplier.countryFk = response.countryFk; + } } ngModule.vnComponent('vnSupplierAccount', { From 5e201419f86e158672e1cc3b861c75b7f739b268 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Fri, 8 Jan 2021 10:46:50 +0100 Subject: [PATCH 03/18] Second step, add component bankEntity --- modules/supplier/front/account/index.html | 2 +- modules/supplier/front/account/index.js | 7 ------- modules/supplier/front/bankentity/index.html | 6 +++--- modules/supplier/front/bankentity/index.js | 5 ++--- modules/supplier/front/bankentity/index.spec.js | 2 +- modules/supplier/front/index.js | 1 + 6 files changed, 8 insertions(+), 15 deletions(-) diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html index 864b362286..6d391e06ae 100644 --- a/modules/supplier/front/account/index.html +++ b/modules/supplier/front/account/index.html @@ -2,7 +2,7 @@ vn-id="model" url="SupplierAccounts" fields="['id', 'supplierFk', 'iban', 'bankEntityFk']" - link="{bankEntityFk: $ctrl.$params.id}" + link="{supplierFk: $ctrl.$params.id}" include="$ctrl.include" data="$ctrl.supplierAccounts" auto-load="true"> diff --git a/modules/supplier/front/account/index.js b/modules/supplier/front/account/index.js index e72e6d0db7..069601a207 100644 --- a/modules/supplier/front/account/index.js +++ b/modules/supplier/front/account/index.js @@ -38,13 +38,6 @@ class Controller extends Section { return this.$http.patch(query, this.newBankEntity) .then(res => this.supplierAccount.bankEntityFk = res.data.id); } - - onResponse(response) { - this.supplier.postcode = response.code; - this.supplier.city = response.city; - this.supplier.provinceFk = response.provinceFk; - this.supplier.countryFk = response.countryFk; - } } ngModule.vnComponent('vnSupplierAccount', { diff --git a/modules/supplier/front/bankentity/index.html b/modules/supplier/front/bankentity/index.html index ed1691f27f..55b40f4816 100644 --- a/modules/supplier/front/bankentity/index.html +++ b/modules/supplier/front/bankentity/index.html @@ -1,5 +1,5 @@ @@ -9,7 +9,7 @@ @@ -35,6 +35,6 @@ - + diff --git a/modules/supplier/front/bankentity/index.js b/modules/supplier/front/bankentity/index.js index 20be668dad..babf64c115 100644 --- a/modules/supplier/front/bankentity/index.js +++ b/modules/supplier/front/bankentity/index.js @@ -4,12 +4,11 @@ import './style.scss'; class Controller extends Component { open() { - this.$.bankentityDialog.show(); + this.$.bankEntityDialog.show(); } onOpen() { this.location = {}; - this.$.bankentity.focus(); } onCountryResponse(response) { @@ -22,7 +21,7 @@ class Controller extends Component { throw new Error(`The country can't be empty`); this.$http.patch(`bankentities`, this.location).then(() => { - this.vnApp.showMessage(this.$t('The bankentity has been created. You can save the data now')); + this.vnApp.showMessage(this.$t('The bank entity has been created. You can save the data now')); this.emit('response', {$response: this.location}); }); } catch (e) { diff --git a/modules/supplier/front/bankentity/index.spec.js b/modules/supplier/front/bankentity/index.spec.js index bb5591f357..b999ab21f2 100644 --- a/modules/supplier/front/bankentity/index.spec.js +++ b/modules/supplier/front/bankentity/index.spec.js @@ -27,7 +27,7 @@ describe('Supplier', () => { controller.onAccept(); $httpBackend.flush(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The bankentity has been created. You can save the data now'); + expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The bank entity has been created. You can save the data now'); }); }); }); diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js index 80c49a8b45..f24fb997ef 100644 --- a/modules/supplier/front/index.js +++ b/modules/supplier/front/index.js @@ -8,6 +8,7 @@ import './search-panel'; import './summary'; import './basic-data'; import './fiscal-data'; +import './bankentity'; import './account'; import './contact'; import './log'; From 403964934df7a9200577e4434a091919e478a572 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Fri, 8 Jan 2021 16:01:13 +0100 Subject: [PATCH 04/18] Change order of iban and entity name --- modules/supplier/front/account/index.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html index 6d391e06ae..64eed2bbfe 100644 --- a/modules/supplier/front/account/index.html +++ b/modules/supplier/front/account/index.html @@ -21,6 +21,12 @@
+ + - - Date: Fri, 8 Jan 2021 16:45:20 +0100 Subject: [PATCH 05/18] Fix problems with ACL and the autocomplete of bank entity --- db/changes/10270-wiseMan/00-ACL.sql | 2 +- modules/supplier/front/account/index.html | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/db/changes/10270-wiseMan/00-ACL.sql b/db/changes/10270-wiseMan/00-ACL.sql index e6374d5a2b..3d3f0d013f 100644 --- a/db/changes/10270-wiseMan/00-ACL.sql +++ b/db/changes/10270-wiseMan/00-ACL.sql @@ -1 +1 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('SupplierAccount', '*', 'WRITE', 'ALLOW', 'ROLE', 'administrative'); \ No newline at end of file +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('SupplierAccount', '*', '*', 'ALLOW', 'ROLE', 'administrative'); \ No newline at end of file diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html index 64eed2bbfe..ce908b0040 100644 --- a/modules/supplier/front/account/index.html +++ b/modules/supplier/front/account/index.html @@ -12,12 +12,6 @@ data="$ctrl.supplierAccounts" form="form"> - - @@ -31,7 +25,7 @@ label="Bank entity" initial-data="$ctrl.getName(bankEntity)" ng-model="supplierAccount.bankEntityFk" - data="bankEntities" + url="BankEntities" on-change="$ctrl.getName(bankEntity)" show-field="name" rule> From c5ace0a9398e481eab4244ac6bcf6eebba695bf3 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Fri, 15 Jan 2021 11:24:32 +0100 Subject: [PATCH 06/18] create the tests fields for create Account section --- loopback/locale/es.json | 4 +- modules/client/back/models/bank-entity.js | 7 +- modules/supplier/front/account/index.html | 4 +- modules/supplier/front/account/index.spec.js | 80 +++++++++++++------ modules/supplier/front/bankentity/index.html | 2 +- modules/supplier/front/bankentity/index.js | 10 +-- .../supplier/front/bankentity/index.spec.js | 65 +++++++++------ modules/supplier/front/bankentity/style.scss | 2 +- 8 files changed, 114 insertions(+), 60 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index b54c0cc675..d493f99e31 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -166,5 +166,7 @@ "The selected ticket is not suitable for this route": "El ticket seleccionado no es apto para esta ruta", "Sorts whole route": "Reordena ruta entera", "New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día {{shipped}}, con una cantidad de {{quantity}} y un precio de {{price}} €", - "New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día {{shipped}}, con una cantidad de {{quantity}}" + "New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día {{shipped}}, con una cantidad de {{quantity}}", + "Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío", + "This BIC already exist.": "Este BIC ya existe." } \ No newline at end of file diff --git a/modules/client/back/models/bank-entity.js b/modules/client/back/models/bank-entity.js index 4cfa7fc918..565c27752c 100644 --- a/modules/client/back/models/bank-entity.js +++ b/modules/client/back/models/bank-entity.js @@ -1,8 +1,11 @@ module.exports = Self => { Self.validatesPresenceOf('name', { - message: `Name cannot be blank` + message: 'Name cannot be blank' }); Self.validatesPresenceOf('bic', { - message: `Swift / BIC can't be empty` + message: 'Swift / BIC cannot be empty' + }); + Self.validatesUniquenessOf('bic', { + message: 'This BIC already exist.' }); }; diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html index ce908b0040..5a9addeea4 100644 --- a/modules/supplier/front/account/index.html +++ b/modules/supplier/front/account/index.html @@ -63,7 +63,7 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/supplier/front/account/index.spec.js b/modules/supplier/front/account/index.spec.js index 34a9ce143d..448db07779 100644 --- a/modules/supplier/front/account/index.spec.js +++ b/modules/supplier/front/account/index.spec.js @@ -1,34 +1,68 @@ import './index.js'; -import crudModel from 'core/mocks/crud-model'; -describe('Item', () => { - describe('Component vnItemTags', () => { - let $scope; - let controller; +describe('Supplier Component vnSupplierAccount', () => { + let $scope; + let $element; + let controller; + let $httpBackend; + beforeEach(ngModule('supplier')); - beforeEach(ngModule('item')); + beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + $scope = $rootScope.$new(); + $scope.bankEntity = { + show: () => {} + }; + $element = angular.element(''); + controller = $componentController('vnSupplierAccount', {$element, $scope}); + controller.supplierAccount = { + supplierFk: 442, + name: 'Verdnatura' + }; + })); - beforeEach(inject(($componentController, $rootScope) => { - $scope = $rootScope.$new(); - $scope.model = crudModel; - $scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}]; - const $element = angular.element(''); - controller = $componentController('vnItemTags', {$element, $scope}); - })); + describe('showBankEntity()', () => { + it('should do nothing if it default is prevented', () => { + const event = { + defaultPrevented: true, + preventDefault: () => {} + }; + jest.spyOn(event, 'preventDefault'); + jest.spyOn(controller.$.bankEntity, 'show'); - describe('getHighestPriority', () => { - it('should return the highest priority value + 1 from the array', () => { - let result = controller.getHighestPriority(); + controller.showBankEntity(event); - expect(result).toEqual(3); - }); + expect(event.preventDefault).not.toHaveBeenCalledWith(); + expect(controller.$.bankEntity.show).not.toHaveBeenCalledWith(); + }); - it('should return 1 when there is no priority defined', () => { - $scope.model.data = []; - let result = controller.getHighestPriority(); + it('should call preventDefault() and show() when the default is not prevented', () => { + const event = { + defaultPrevented: false, + preventDefault: () => {} + }; + jest.spyOn(event, 'preventDefault'); + jest.spyOn(controller.$.bankEntity, 'show'); - expect(result).toEqual(1); - }); + controller.showBankEntity(event); + + expect(event.preventDefault).toHaveBeenCalledWith(); + expect(controller.$.bankEntity.show).toHaveBeenCalledWith(); + }); + + it('should request to create a new bank entity', () => { + controller.bankEntity = { + name: 'My new bank entity', + bic: 'ES1234', + countryFk: 1, + id: 2200 + }; + $httpBackend.expectPATCH(`SupplierAccounts/${controller.$.bankEntity.id}/createBankEntity`).respond({id: 2200}); + controller.onBankEntityAccept(); + $httpBackend.flush(); + + expect(controller.supplierAccount.bankEntityFk).toEqual(controller.bankEntity.id); }); }); }); + diff --git a/modules/supplier/front/bankentity/index.html b/modules/supplier/front/bankentity/index.html index 55b40f4816..74a302d069 100644 --- a/modules/supplier/front/bankentity/index.html +++ b/modules/supplier/front/bankentity/index.html @@ -1,6 +1,6 @@ diff --git a/modules/supplier/front/bankentity/index.js b/modules/supplier/front/bankentity/index.js index babf64c115..322afc78f6 100644 --- a/modules/supplier/front/bankentity/index.js +++ b/modules/supplier/front/bankentity/index.js @@ -3,11 +3,7 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { - open() { - this.$.bankEntityDialog.show(); - } - - onOpen() { + resetLocation() { this.location = {}; } @@ -20,7 +16,7 @@ class Controller extends Component { if (!this.location.countryFk) throw new Error(`The country can't be empty`); - this.$http.patch(`bankentities`, this.location).then(() => { + this.$http.post(`Bankentities`, this.location).then(() => { this.vnApp.showMessage(this.$t('The bank entity has been created. You can save the data now')); this.emit('response', {$response: this.location}); }); @@ -32,7 +28,7 @@ class Controller extends Component { } } -ngModule.vnComponent('vnNewBankentity', { +ngModule.vnComponent('vnNewBankEntity', { template: require('./index.html'), controller: Controller, bindings: { diff --git a/modules/supplier/front/bankentity/index.spec.js b/modules/supplier/front/bankentity/index.spec.js index b999ab21f2..84273ded80 100644 --- a/modules/supplier/front/bankentity/index.spec.js +++ b/modules/supplier/front/bankentity/index.spec.js @@ -1,34 +1,53 @@ import './index'; -describe('Supplier', () => { - describe('Component vnNewBankentity', () => { - let controller; - let $httpBackend; - let $scope; +describe('Supplier Component vnNewBankEntity', () => { + let controller; + let $httpBackend; + let $scope; + let $element; + let vnApp; - beforeEach(ngModule('supplier')); + beforeEach(ngModule('supplier')); - beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => { - $httpBackend = _$httpBackend_; - $scope = $rootScope.$new(); - const $element = angular.element(''); - controller = $componentController('vnNewBankentity', {$element, $scope}); - controller.client = {id: 101}; - })); + beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => { + $httpBackend = _$httpBackend_; + vnApp = _vnApp_; + jest.spyOn(vnApp, 'showError'); + $scope = $rootScope.$new(); + $element = angular.element(''); + controller = $componentController('vnNewBankEntity', {$element, $scope}); + })); - describe('onAccept()', () => { - it('should perform a POST query and show a success snackbar', () => { - let params = {countryFk: 1}; - controller.location = {countryFk: 1}; + describe('resetLocation()', () => { + it('should reset the location in the controller', () => { + expect(controller.location).toBeUndefined(); - jest.spyOn(controller.vnApp, 'showMessage'); - $httpBackend.expect('PATCH', `bankentity`, params).respond(200, params); + controller.resetLocation(); - controller.onAccept(); - $httpBackend.flush(); + expect(controller.location).toEqual({}); + }); + }); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The bank entity has been created. You can save the data now'); - }); + describe('onAccept()', () => { + it('should throw an error if there is no country id in the location', () => { + jest.spyOn(controller.vnApp, 'showMessage'); + + controller.location = {}; + + controller.onAccept(); + + expect(controller.vnApp.showError).toHaveBeenCalledWith(`The country can't be empty`); + }); + + it('should do add the new bank entity', () => { + controller.location = { + countryFk: 1 + }; + + $httpBackend.expectPOST('Bankentities', controller.location).respond(200, controller.location); + + controller.onAccept(); + $httpBackend.flush(); }); }); }); diff --git a/modules/supplier/front/bankentity/style.scss b/modules/supplier/front/bankentity/style.scss index adad7ab019..1171366da2 100644 --- a/modules/supplier/front/bankentity/style.scss +++ b/modules/supplier/front/bankentity/style.scss @@ -1,6 +1,6 @@ @import "variables"; -vn-new-bankentity { +vn-new-bank-entity { vn-dialog { p { color: $color-alert From 51627af39511c13d2be6a419424cb626f16fa5a5 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Fri, 15 Jan 2021 13:13:51 +0100 Subject: [PATCH 07/18] Fixed open popup --- modules/supplier/front/bankentity/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/supplier/front/bankentity/index.js b/modules/supplier/front/bankentity/index.js index 322afc78f6..975b186efb 100644 --- a/modules/supplier/front/bankentity/index.js +++ b/modules/supplier/front/bankentity/index.js @@ -3,6 +3,9 @@ import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { + open() { + this.$.bankEntityDialog.show(); + } resetLocation() { this.location = {}; } From fe6124b691faf828b14ffa9537448c3934f30643 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Fri, 15 Jan 2021 13:57:36 +0100 Subject: [PATCH 08/18] Put log in the section --- modules/supplier/back/models/supplier-account.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index 364bdaae51..1d989cbfbb 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -1,6 +1,10 @@ { "name": "SupplierAccount", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"SupplierLog", + "relation": "supplier" + }, "options": { "mysql": { "table": "supplierAccount" From 1adaeca61524a436cbd046af2c996010aed1576d Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Mon, 8 Feb 2021 08:41:26 +0100 Subject: [PATCH 09/18] Added controller with sql --- .../methods/travel/getTravelDaysDuration.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 modules/travel/back/methods/travel/getTravelDaysDuration.js diff --git a/modules/travel/back/methods/travel/getTravelDaysDuration.js b/modules/travel/back/methods/travel/getTravelDaysDuration.js new file mode 100644 index 0000000000..12a190e19b --- /dev/null +++ b/modules/travel/back/methods/travel/getTravelDaysDuration.js @@ -0,0 +1,44 @@ + +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +module.exports = Self => { + Self.remoteMethod('getTravelDaysDuration', { + description: 'Return the total days of travel', + accessType: 'READ', + accepts: { + arg: 'id', + type: 'number', + required: true, + description: 'The travel id', + http: {source: 'path'} + }, + returns: { + type: 'number', + root: true + }, + http: { + path: `/:id/getTravelDaysDuration`, + verb: 'GET' + } + }); + + Self.getTravelDaysDuration = async id => { + let stmt; + + stmt = new ParameterizedSQL(` + SELECT + ROUND( + AVG( + DATEDIFF(landed , shipped) + ) + ) + FROM travel + WHERE agencyFk = ? + GROUP BY agencyFK`, [ + id + ]); + + let result = await Self.rawStmt(stmt); + + return result; + }; +}; From 1c6bddbfb67cae03424734e5af74183500c15dbe Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Wed, 10 Feb 2021 08:47:58 +0100 Subject: [PATCH 10/18] Added functionality to autocomplete the inputs --- .../back/methods/travel/getTravelData.js | 36 +++++++++++++++ .../methods/travel/getTravelDaysDuration.js | 44 ------------------- modules/travel/back/models/travel.js | 1 + modules/travel/front/create/index.html | 2 + modules/travel/front/create/index.js | 24 ++++++++++ modules/travel/front/create/index.spec.js | 39 +++++++++++++++- 6 files changed, 101 insertions(+), 45 deletions(-) create mode 100644 modules/travel/back/methods/travel/getTravelData.js delete mode 100644 modules/travel/back/methods/travel/getTravelDaysDuration.js diff --git a/modules/travel/back/methods/travel/getTravelData.js b/modules/travel/back/methods/travel/getTravelData.js new file mode 100644 index 0000000000..7e70c454bc --- /dev/null +++ b/modules/travel/back/methods/travel/getTravelData.js @@ -0,0 +1,36 @@ +module.exports = Self => { + Self.remoteMethod('getTravelData', { + description: 'Returns the days of travel duration', + accessType: 'READ', + accepts: [{ + arg: 'agencyModeFk', + type: 'number', + required: true + }], + returns: { + type: 'number', + root: true + }, + http: { + path: `/getTravelData`, + verb: 'GET' + } + }); + + Self.getTravelData = async agencyModeFk => { + const query = ` + SELECT t.warehouseInFk as warehouseIn, + t.warehouseOutFk as warehouseOut, + dayDuration + FROM travel t + JOIN ( + SELECT ROUND(AVG(DATEDIFF(landed, shipped))) as dayDuration + FROM travel + WHERE agencyFk = 4) AS t2 + WHERE t.agencyFk = 4 + ORDER BY t.id DESC LIMIT 1;`; + + const [result] = await Self.rawSql(query, [agencyModeFk, agencyModeFk]); + return result; + }; +}; diff --git a/modules/travel/back/methods/travel/getTravelDaysDuration.js b/modules/travel/back/methods/travel/getTravelDaysDuration.js deleted file mode 100644 index 12a190e19b..0000000000 --- a/modules/travel/back/methods/travel/getTravelDaysDuration.js +++ /dev/null @@ -1,44 +0,0 @@ - -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; -module.exports = Self => { - Self.remoteMethod('getTravelDaysDuration', { - description: 'Return the total days of travel', - accessType: 'READ', - accepts: { - arg: 'id', - type: 'number', - required: true, - description: 'The travel id', - http: {source: 'path'} - }, - returns: { - type: 'number', - root: true - }, - http: { - path: `/:id/getTravelDaysDuration`, - verb: 'GET' - } - }); - - Self.getTravelDaysDuration = async id => { - let stmt; - - stmt = new ParameterizedSQL(` - SELECT - ROUND( - AVG( - DATEDIFF(landed , shipped) - ) - ) - FROM travel - WHERE agencyFk = ? - GROUP BY agencyFK`, [ - id - ]); - - let result = await Self.rawStmt(stmt); - - return result; - }; -}; diff --git a/modules/travel/back/models/travel.js b/modules/travel/back/models/travel.js index 46d33b305d..e2bb94c87c 100644 --- a/modules/travel/back/models/travel.js +++ b/modules/travel/back/models/travel.js @@ -8,6 +8,7 @@ module.exports = Self => { require('../methods/travel/deleteThermograph')(Self); require('../methods/travel/updateThermograph')(Self); require('../methods/travel/extraCommunityFilter')(Self); + require('../methods/travel/getTravelData')(Self); require('../methods/travel/cloneWithEntries')(Self); Self.rewriteDbError(function(err) { diff --git a/modules/travel/front/create/index.html b/modules/travel/front/create/index.html index 0931c322ee..6db662a546 100644 --- a/modules/travel/front/create/index.html +++ b/modules/travel/front/create/index.html @@ -20,7 +20,9 @@ { + const landed = new Date(value); + const warehouseIn = res.data.warehouseIn; + const warehouseOut = res.data.warehouseOut; + + const futureDate = landed.getDate() + res.data.dayDuration; + landed.setDate(futureDate); + + this.travel.landed = landed; + this.travel.warehouseInFk = warehouseIn; + this.travel.warehouseOutFk = warehouseOut; + }); + } + onSubmit() { return this.$.watcher.submit().then( res => this.$state.go('travel.card.basicData', {id: res.data.id}) diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index 99f52b322c..a00a3fb79a 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -5,10 +5,12 @@ describe('Travel Component vnTravelCreate', () => { let $scope; let $state; let controller; + let $httpBackend; beforeEach(ngModule('travel')); - beforeEach(inject(($componentController, $rootScope, _$state_) => { + beforeEach(inject(($componentController, $rootScope, _$state_, _$httpBackend_) => { + $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); $state = _$state_; $scope.watcher = watcher; @@ -38,4 +40,39 @@ describe('Travel Component vnTravelCreate', () => { expect(controller.travel).toEqual(json); }); }); + + fdescribe('onShippedChange()', () => { + it(`should do nothing if there's no agencyMode or the travel has filled properties.`, () => { + controller.agencyModeFk = {}; + controller.landed = {landed: 'January 30,2021, 00:00:00'}; + controller.warehouseInFk = {warehouseInFk: 4}; + controller.warehouseOutFk = {warehouseOutFk: 4}; + + const landed = {landed: 'January 30,2021, 00:00:00'}; + const warehouseIn = {warehouseInFk: 4}; + const warehouseOut = {warehouseOutFk: 4}; + const agencyModeFk = {}; + + expect(controller.agencyModeFk).toEqual(agencyModeFk); + expect(controller.landed).toEqual(landed); + expect(controller.warehouseInFk).toEqual(warehouseIn); + expect(controller.warehouseOutFk).toEqual(warehouseOut); + }); + + it(`should do fill the fields when it's selected a date and agency.`, () => { + controller.travel = { + agencyModeFk: 4, + landed: 'January 30,2021, 00:00:00', + warehouseInFk: 4, + warehouseOutFk: 4 + }; + const params = {agencyModeFk: 4}; + + $httpBackend.expectGET(`travels/getTravelData`, params).respond({agencyModeFk: 4}); + controller.onShippedChange(); + // $httpBackend.flush(); + + expect(controller.travel.agencyModeFk).toEqual(params.agencyModeFk); + }); + }); }); From 2cf37a9e968d848f792f86eab1e209049c2b17d9 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Wed, 10 Feb 2021 09:10:15 +0100 Subject: [PATCH 11/18] Added permissions to role administrative --- db/changes/10280-valentineDay/00-EntryAddPermissions.sql | 1 + modules/entry/front/routes.json | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 db/changes/10280-valentineDay/00-EntryAddPermissions.sql diff --git a/db/changes/10280-valentineDay/00-EntryAddPermissions.sql b/db/changes/10280-valentineDay/00-EntryAddPermissions.sql new file mode 100644 index 0000000000..d3b02fc2d0 --- /dev/null +++ b/db/changes/10280-valentineDay/00-EntryAddPermissions.sql @@ -0,0 +1 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Entry', '*', '*', 'ALLOW', 'ROLE', 'administrative'); diff --git a/modules/entry/front/routes.json b/modules/entry/front/routes.json index db12e95fd9..1911f721cf 100644 --- a/modules/entry/front/routes.json +++ b/modules/entry/front/routes.json @@ -31,19 +31,19 @@ "state": "entry.index", "component": "vn-entry-index", "description": "Entries", - "acl": ["buyer"] + "acl": ["buyer", "administrative"] }, { "url": "/latest-buys?q", "state": "entry.latestBuys", "component": "vn-entry-latest-buys", "description": "Latest buys", - "acl": ["buyer"] + "acl": ["buyer", "administrative"] }, { "url": "/create?supplierFk&travelFk&companyFk", "state": "entry.create", "component": "vn-entry-create", "description": "New entry", - "acl": ["buyer"] + "acl": ["buyer", "administrative"] }, { "url": "/:id", "state": "entry.card", From 31e5d3fd1e69c7ecf164caa2bb14989ca0674ee3 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Thu, 11 Feb 2021 08:32:16 +0100 Subject: [PATCH 12/18] Created test and optimized sql query --- .../back/methods/travel/getTravelData.js | 16 +++---- modules/travel/front/create/index.js | 17 +++---- modules/travel/front/create/index.spec.js | 47 +++++++++---------- 3 files changed, 36 insertions(+), 44 deletions(-) diff --git a/modules/travel/back/methods/travel/getTravelData.js b/modules/travel/back/methods/travel/getTravelData.js index 7e70c454bc..d688fc0406 100644 --- a/modules/travel/back/methods/travel/getTravelData.js +++ b/modules/travel/back/methods/travel/getTravelData.js @@ -19,16 +19,12 @@ module.exports = Self => { Self.getTravelData = async agencyModeFk => { const query = ` - SELECT t.warehouseInFk as warehouseIn, - t.warehouseOutFk as warehouseOut, - dayDuration - FROM travel t - JOIN ( - SELECT ROUND(AVG(DATEDIFF(landed, shipped))) as dayDuration - FROM travel - WHERE agencyFk = 4) AS t2 - WHERE t.agencyFk = 4 - ORDER BY t.id DESC LIMIT 1;`; + SELECT t.id, t.warehouseInFk, t.warehouseOutFk, + (SELECT ROUND(AVG(DATEDIFF(t.landed, t.shipped ))) + FROM travel t + WHERE t.agencyFk = ? LIMIT 50) AS dayDuration + FROM travel t + WHERE t.agencyFk = ? ORDER BY t.id DESC LIMIT 1;`; const [result] = await Self.rawSql(query, [agencyModeFk, agencyModeFk]); return result; diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js index 70b493ce59..0139be5073 100644 --- a/modules/travel/front/create/index.js +++ b/modules/travel/front/create/index.js @@ -8,9 +8,13 @@ class Controller extends Section { } onShippedChange(value) { - const hasFilledProperties = this.travel.landed || this.travel.warehouseInFk || this.travel.warehouseOutFk; - - if (!this.travel.agencyModeFk || hasFilledProperties) + let hasFilledProperties; + let hasAgencyMode; + if (this.travel) { + hasAgencyMode = Boolean(this.travel.agencyModeFk); + hasFilledProperties = this.travel.landed || this.travel.warehouseInFk || this.travel.warehouseOutFk; + } + if (!hasAgencyMode || hasFilledProperties) return; const query = `travels/getTravelData`; @@ -19,15 +23,12 @@ class Controller extends Section { }; this.$http.get(query, {params}).then(res => { const landed = new Date(value); - const warehouseIn = res.data.warehouseIn; - const warehouseOut = res.data.warehouseOut; - const futureDate = landed.getDate() + res.data.dayDuration; landed.setDate(futureDate); this.travel.landed = landed; - this.travel.warehouseInFk = warehouseIn; - this.travel.warehouseOutFk = warehouseOut; + this.travel.warehouseInFk = res.data.warehouseInFk; + this.travel.warehouseOutFk = res.data.warehouseOutFk; }); } diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index a00a3fb79a..d85e937186 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -41,38 +41,33 @@ describe('Travel Component vnTravelCreate', () => { }); }); - fdescribe('onShippedChange()', () => { - it(`should do nothing if there's no agencyMode or the travel has filled properties.`, () => { - controller.agencyModeFk = {}; - controller.landed = {landed: 'January 30,2021, 00:00:00'}; - controller.warehouseInFk = {warehouseInFk: 4}; - controller.warehouseOutFk = {warehouseOutFk: 4}; + describe('onShippedChange()', () => { + it(`should do nothing if there's no agencyModeFk in the travel.`, () => { + controller.travel = {}; + controller.onShippedChange(); - const landed = {landed: 'January 30,2021, 00:00:00'}; - const warehouseIn = {warehouseInFk: 4}; - const warehouseOut = {warehouseOutFk: 4}; - const agencyModeFk = {}; - - expect(controller.agencyModeFk).toEqual(agencyModeFk); - expect(controller.landed).toEqual(landed); - expect(controller.warehouseInFk).toEqual(warehouseIn); - expect(controller.warehouseOutFk).toEqual(warehouseOut); + expect(controller.travel.landed).toBeUndefined(); + expect(controller.travel.warehouseInFk).toBeUndefined(); + expect(controller.travel.warehouseOutFk).toBeUndefined(); }); - it(`should do fill the fields when it's selected a date and agency.`, () => { - controller.travel = { - agencyModeFk: 4, - landed: 'January 30,2021, 00:00:00', - warehouseInFk: 4, - warehouseOutFk: 4 + it(`should fill the fields when it's selected a date and agency.`, () => { + controller.travel = {agencyModeFk: 1}; + const tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); + const expectedResponse = { + dayDuration: 2, + warehouseInFk: 1, + warehouseOutFk: 2 }; - const params = {agencyModeFk: 4}; - $httpBackend.expectGET(`travels/getTravelData`, params).respond({agencyModeFk: 4}); - controller.onShippedChange(); - // $httpBackend.flush(); + const query = `travels/getTravelData?agencyModeFk=${controller.travel.agencyModeFk}`; + $httpBackend.expectGET(query).respond(expectedResponse); + controller.onShippedChange(tomorrow); + $httpBackend.flush(); - expect(controller.travel.agencyModeFk).toEqual(params.agencyModeFk); + expect(controller.travel.warehouseInFk).toEqual(expectedResponse.warehouseInFk); + expect(controller.travel.warehouseOutFk).toEqual(expectedResponse.warehouseOutFk); }); }); }); From 433a0094c471307511b4797c798448e1a1f77edf Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Fri, 12 Feb 2021 09:11:43 +0100 Subject: [PATCH 13/18] Fixed errors detected --- db/changes/10270-wiseMan/00-ACL.sql | 1 - .../back/models/supplier-account.json | 59 ---------------- modules/supplier/front/account/index.html | 69 ------------------- modules/supplier/front/account/index.js | 49 ------------- modules/supplier/front/account/index.spec.js | 68 ------------------ modules/supplier/front/account/locale/es.yml | 2 - modules/supplier/front/bankentity/index.html | 40 ----------- modules/supplier/front/bankentity/index.js | 40 ----------- .../supplier/front/bankentity/index.spec.js | 53 -------------- .../supplier/front/bankentity/locale/es.yml | 11 --- modules/supplier/front/bankentity/style.scss | 9 --- modules/supplier/front/index.js | 2 - modules/supplier/front/routes.json | 10 --- 13 files changed, 413 deletions(-) delete mode 100644 db/changes/10270-wiseMan/00-ACL.sql delete mode 100644 modules/supplier/back/models/supplier-account.json delete mode 100644 modules/supplier/front/account/index.html delete mode 100644 modules/supplier/front/account/index.js delete mode 100644 modules/supplier/front/account/index.spec.js delete mode 100644 modules/supplier/front/account/locale/es.yml delete mode 100644 modules/supplier/front/bankentity/index.html delete mode 100644 modules/supplier/front/bankentity/index.js delete mode 100644 modules/supplier/front/bankentity/index.spec.js delete mode 100644 modules/supplier/front/bankentity/locale/es.yml delete mode 100644 modules/supplier/front/bankentity/style.scss diff --git a/db/changes/10270-wiseMan/00-ACL.sql b/db/changes/10270-wiseMan/00-ACL.sql deleted file mode 100644 index 3d3f0d013f..0000000000 --- a/db/changes/10270-wiseMan/00-ACL.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('SupplierAccount', '*', '*', 'ALLOW', 'ROLE', 'administrative'); \ No newline at end of file diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json deleted file mode 100644 index 1d989cbfbb..0000000000 --- a/modules/supplier/back/models/supplier-account.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "name": "SupplierAccount", - "base": "Loggable", - "log": { - "model":"SupplierLog", - "relation": "supplier" - }, - "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" - }, - "bankEntity": { - "type": "belongsTo", - "model": "BankEntity", - "foreignKey": "bankEntityFk" - } - } -} \ No newline at end of file diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html deleted file mode 100644 index 5a9addeea4..0000000000 --- a/modules/supplier/front/account/index.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - \ No newline at end of file diff --git a/modules/supplier/front/account/index.js b/modules/supplier/front/account/index.js deleted file mode 100644 index 069601a207..0000000000 --- a/modules/supplier/front/account/index.js +++ /dev/null @@ -1,49 +0,0 @@ -import ngModule from '../module'; -import Section from 'salix/components/section'; - -class Controller extends Section { - constructor($element, $) { - super($element, $); - this.include = { - relation: 'bankEntity', - scope: { - fields: ['countryFk', 'id', 'name', 'bic'] - } - }; - } - - add() { - this.$.model.insert({ - supplierFk: this.$params.id - }); - } - - onSubmit() { - this.$.watcher.check(); - this.$.model.save().then(() => { - this.$.watcher.notifySaved(); - this.$.watcher.updateOriginalData(); - this.card.reload(); - }); - } - - showBankEntity(event) { - if (event.defaultPrevented) return; - event.preventDefault(); - this.$.bankEntity.show(); - } - - onBankEntityAccept() { - const query = `SupplierAccounts/${this.$params.id}/createBankEntity`; - return this.$http.patch(query, this.newBankEntity) - .then(res => this.supplierAccount.bankEntityFk = res.data.id); - } -} - -ngModule.vnComponent('vnSupplierAccount', { - template: require('./index.html'), - controller: Controller, - require: { - card: '^vnSupplierCard' - } -}); diff --git a/modules/supplier/front/account/index.spec.js b/modules/supplier/front/account/index.spec.js deleted file mode 100644 index 448db07779..0000000000 --- a/modules/supplier/front/account/index.spec.js +++ /dev/null @@ -1,68 +0,0 @@ -import './index.js'; - -describe('Supplier Component vnSupplierAccount', () => { - let $scope; - let $element; - let controller; - let $httpBackend; - beforeEach(ngModule('supplier')); - - beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { - $httpBackend = _$httpBackend_; - $scope = $rootScope.$new(); - $scope.bankEntity = { - show: () => {} - }; - $element = angular.element(''); - controller = $componentController('vnSupplierAccount', {$element, $scope}); - controller.supplierAccount = { - supplierFk: 442, - name: 'Verdnatura' - }; - })); - - describe('showBankEntity()', () => { - it('should do nothing if it default is prevented', () => { - const event = { - defaultPrevented: true, - preventDefault: () => {} - }; - jest.spyOn(event, 'preventDefault'); - jest.spyOn(controller.$.bankEntity, 'show'); - - controller.showBankEntity(event); - - expect(event.preventDefault).not.toHaveBeenCalledWith(); - expect(controller.$.bankEntity.show).not.toHaveBeenCalledWith(); - }); - - it('should call preventDefault() and show() when the default is not prevented', () => { - const event = { - defaultPrevented: false, - preventDefault: () => {} - }; - jest.spyOn(event, 'preventDefault'); - jest.spyOn(controller.$.bankEntity, 'show'); - - controller.showBankEntity(event); - - expect(event.preventDefault).toHaveBeenCalledWith(); - expect(controller.$.bankEntity.show).toHaveBeenCalledWith(); - }); - - it('should request to create a new bank entity', () => { - controller.bankEntity = { - name: 'My new bank entity', - bic: 'ES1234', - countryFk: 1, - id: 2200 - }; - $httpBackend.expectPATCH(`SupplierAccounts/${controller.$.bankEntity.id}/createBankEntity`).respond({id: 2200}); - controller.onBankEntityAccept(); - $httpBackend.flush(); - - expect(controller.supplierAccount.bankEntityFk).toEqual(controller.bankEntity.id); - }); - }); -}); - diff --git a/modules/supplier/front/account/locale/es.yml b/modules/supplier/front/account/locale/es.yml deleted file mode 100644 index 7443ad4e35..0000000000 --- a/modules/supplier/front/account/locale/es.yml +++ /dev/null @@ -1,2 +0,0 @@ -Bank entity: Entidad bancaria -swift: Swift BIC \ No newline at end of file diff --git a/modules/supplier/front/bankentity/index.html b/modules/supplier/front/bankentity/index.html deleted file mode 100644 index 74a302d069..0000000000 --- a/modules/supplier/front/bankentity/index.html +++ /dev/null @@ -1,40 +0,0 @@ - - -

Please, ensure you put the correct data!

- - - - - - - - - - -
- - - - -
diff --git a/modules/supplier/front/bankentity/index.js b/modules/supplier/front/bankentity/index.js deleted file mode 100644 index 975b186efb..0000000000 --- a/modules/supplier/front/bankentity/index.js +++ /dev/null @@ -1,40 +0,0 @@ -import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; - -class Controller extends Component { - open() { - this.$.bankEntityDialog.show(); - } - resetLocation() { - this.location = {}; - } - - onCountryResponse(response) { - this.location.countryFk = response.id; - } - - onAccept() { - try { - if (!this.location.countryFk) - throw new Error(`The country can't be empty`); - - this.$http.post(`Bankentities`, this.location).then(() => { - this.vnApp.showMessage(this.$t('The bank entity has been created. You can save the data now')); - this.emit('response', {$response: this.location}); - }); - } catch (e) { - this.vnApp.showError(this.$t(e.message)); - return false; - } - return true; - } -} - -ngModule.vnComponent('vnNewBankEntity', { - template: require('./index.html'), - controller: Controller, - bindings: { - data: '<', - } -}); diff --git a/modules/supplier/front/bankentity/index.spec.js b/modules/supplier/front/bankentity/index.spec.js deleted file mode 100644 index 84273ded80..0000000000 --- a/modules/supplier/front/bankentity/index.spec.js +++ /dev/null @@ -1,53 +0,0 @@ -import './index'; - -describe('Supplier Component vnNewBankEntity', () => { - let controller; - let $httpBackend; - let $scope; - let $element; - let vnApp; - - beforeEach(ngModule('supplier')); - - beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => { - $httpBackend = _$httpBackend_; - vnApp = _vnApp_; - jest.spyOn(vnApp, 'showError'); - $scope = $rootScope.$new(); - $element = angular.element(''); - controller = $componentController('vnNewBankEntity', {$element, $scope}); - })); - - describe('resetLocation()', () => { - it('should reset the location in the controller', () => { - expect(controller.location).toBeUndefined(); - - controller.resetLocation(); - - expect(controller.location).toEqual({}); - }); - }); - - describe('onAccept()', () => { - it('should throw an error if there is no country id in the location', () => { - jest.spyOn(controller.vnApp, 'showMessage'); - - controller.location = {}; - - controller.onAccept(); - - expect(controller.vnApp.showError).toHaveBeenCalledWith(`The country can't be empty`); - }); - - it('should do add the new bank entity', () => { - controller.location = { - countryFk: 1 - }; - - $httpBackend.expectPOST('Bankentities', controller.location).respond(200, controller.location); - - controller.onAccept(); - $httpBackend.flush(); - }); - }); -}); diff --git a/modules/supplier/front/bankentity/locale/es.yml b/modules/supplier/front/bankentity/locale/es.yml deleted file mode 100644 index 782690e885..0000000000 --- a/modules/supplier/front/bankentity/locale/es.yml +++ /dev/null @@ -1,11 +0,0 @@ -New postcode: Nuevo código postal -New city: Nueva ciudad -New province: Nueva provincia -Please, ensure you put the correct data!: ¡Por favor, asegúrate de poner los datos correctos! -The postcode can't be empty: El código postal no puede quedar vacío -The town can't be empty: La población no puede quedar vacía -The province can't be empty: La provincia no puede quedar vacía -The country can't be empty: El país no puede quedar vacío -The postcode has been created. You can save the data now: Se ha creado el código postal. Ahora puedes guardar los datos -The city has been created: Se ha creado la ciudad -The province has been created: Se ha creado la provincia \ No newline at end of file diff --git a/modules/supplier/front/bankentity/style.scss b/modules/supplier/front/bankentity/style.scss deleted file mode 100644 index 1171366da2..0000000000 --- a/modules/supplier/front/bankentity/style.scss +++ /dev/null @@ -1,9 +0,0 @@ -@import "variables"; - -vn-new-bank-entity { - vn-dialog { - p { - color: $color-alert - } - } -} \ No newline at end of file diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js index f24fb997ef..9a9334c416 100644 --- a/modules/supplier/front/index.js +++ b/modules/supplier/front/index.js @@ -8,8 +8,6 @@ import './search-panel'; import './summary'; import './basic-data'; import './fiscal-data'; -import './bankentity'; -import './account'; import './contact'; import './log'; import './consumption'; diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index cf2ec32647..73ff28246a 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -9,7 +9,6 @@ {"state": "supplier.index", "icon": "icon-supplier"} ], "card": [ - {"state": "supplier.card.account", "icon": "face"}, {"state": "supplier.card.basicData", "icon": "settings"}, {"state": "supplier.card.fiscalData", "icon": "account_balance"}, {"state": "supplier.card.billingData", "icon": "icon-payment"}, @@ -100,15 +99,6 @@ "supplier": "$ctrl.supplier" }, "acl": ["administrative"] - },{ - "url": "/account", - "state": "supplier.card.account", - "component": "vn-supplier-account", - "description": "Account", - "params": { - "supplier": "$ctrl.supplier" - }, - "acl": ["administrative"] } ] } \ No newline at end of file From 211ffb8f301f26fb231d89e0f673cbafa5ee2db7 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Fri, 12 Feb 2021 09:50:23 +0100 Subject: [PATCH 14/18] Delete supplierAccount from this branch --- modules/supplier/back/model-config.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/supplier/back/model-config.json b/modules/supplier/back/model-config.json index 62c580acac..34d152bc6b 100644 --- a/modules/supplier/back/model-config.json +++ b/modules/supplier/back/model-config.json @@ -10,8 +10,5 @@ }, "SupplierContact": { "dataSource": "vn" - }, - "SupplierAccount": { - "dataSource": "vn" } } From dad3e7c155a01b52780e3725b6cbe57b71fcf296 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Fri, 12 Feb 2021 11:27:24 +0100 Subject: [PATCH 15/18] Requested changes realized --- modules/supplier/back/model-config.json | 3 ++ .../back/models/supplier-account.json | 50 +++++++++++++++++++ .../{getTravelData.js => getAverageDays.js} | 12 ++--- modules/travel/back/models/travel.js | 2 +- modules/travel/front/create/index.html | 1 - modules/travel/front/create/index.js | 2 +- modules/travel/front/create/index.spec.js | 2 +- 7 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 modules/supplier/back/models/supplier-account.json rename modules/travel/back/methods/travel/{getTravelData.js => getAverageDays.js} (66%) diff --git a/modules/supplier/back/model-config.json b/modules/supplier/back/model-config.json index 34d152bc6b..62c580acac 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/supplier-account.json b/modules/supplier/back/models/supplier-account.json new file mode 100644 index 0000000000..237934f8c1 --- /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/travel/back/methods/travel/getTravelData.js b/modules/travel/back/methods/travel/getAverageDays.js similarity index 66% rename from modules/travel/back/methods/travel/getTravelData.js rename to modules/travel/back/methods/travel/getAverageDays.js index d688fc0406..bcc98dbe2f 100644 --- a/modules/travel/back/methods/travel/getTravelData.js +++ b/modules/travel/back/methods/travel/getAverageDays.js @@ -1,6 +1,6 @@ module.exports = Self => { - Self.remoteMethod('getTravelData', { - description: 'Returns the days of travel duration', + Self.remoteMethod('getAverageDays', { + description: 'Returns the average days duration and the two warehouses of the travel.', accessType: 'READ', accepts: [{ arg: 'agencyModeFk', @@ -12,12 +12,12 @@ module.exports = Self => { root: true }, http: { - path: `/getTravelData`, + path: `/getAverageDays`, verb: 'GET' } }); - Self.getTravelData = async agencyModeFk => { + Self.getAverageDays = async agencyModeFk => { const query = ` SELECT t.id, t.warehouseInFk, t.warehouseOutFk, (SELECT ROUND(AVG(DATEDIFF(t.landed, t.shipped ))) @@ -26,7 +26,7 @@ module.exports = Self => { FROM travel t WHERE t.agencyFk = ? ORDER BY t.id DESC LIMIT 1;`; - const [result] = await Self.rawSql(query, [agencyModeFk, agencyModeFk]); - return result; + const [avgDays] = await Self.rawSql(query, [agencyModeFk, agencyModeFk]); + return avgDays; }; }; diff --git a/modules/travel/back/models/travel.js b/modules/travel/back/models/travel.js index e2bb94c87c..046153ee22 100644 --- a/modules/travel/back/models/travel.js +++ b/modules/travel/back/models/travel.js @@ -8,7 +8,7 @@ module.exports = Self => { require('../methods/travel/deleteThermograph')(Self); require('../methods/travel/updateThermograph')(Self); require('../methods/travel/extraCommunityFilter')(Self); - require('../methods/travel/getTravelData')(Self); + require('../methods/travel/getAverageDays')(Self); require('../methods/travel/cloneWithEntries')(Self); Self.rewriteDbError(function(err) { diff --git a/modules/travel/front/create/index.html b/modules/travel/front/create/index.html index 6db662a546..6c19e0e124 100644 --- a/modules/travel/front/create/index.html +++ b/modules/travel/front/create/index.html @@ -22,7 +22,6 @@ { warehouseOutFk: 2 }; - const query = `travels/getTravelData?agencyModeFk=${controller.travel.agencyModeFk}`; + const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`; $httpBackend.expectGET(query).respond(expectedResponse); controller.onShippedChange(tomorrow); $httpBackend.flush(); From 8800f766843bd1c142e621b22525fdcae6f3bd63 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Fri, 12 Feb 2021 11:35:33 +0100 Subject: [PATCH 16/18] Translations recovered --- loopback/locale/es.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5b73a2d729..174a9e0938 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -171,5 +171,8 @@ "New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día {{shipped}}, con una cantidad de {{quantity}}", "Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío", "This BIC already exist.": "Este BIC ya existe.", - "That item doesn't exists": "Ese artículo no existe" + "That item doesn't exists": "Ese artículo no existe", + "There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})", + "Invalid account": "Cuenta inválida", + "Compensation account is empty": "La cuenta para compensar está vacia" } \ No newline at end of file From 86580727e573df2568e9f1bca77fcba502e9d960 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Fri, 12 Feb 2021 11:47:53 +0100 Subject: [PATCH 17/18] Requested changes resolved --- db/changes/10280-valentineDay/00-EntryAddPermissions.sql | 1 - db/changes/10281-valentineDay/00-ACL.sql | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) delete mode 100644 db/changes/10280-valentineDay/00-EntryAddPermissions.sql create mode 100644 db/changes/10281-valentineDay/00-ACL.sql diff --git a/db/changes/10280-valentineDay/00-EntryAddPermissions.sql b/db/changes/10280-valentineDay/00-EntryAddPermissions.sql deleted file mode 100644 index d3b02fc2d0..0000000000 --- a/db/changes/10280-valentineDay/00-EntryAddPermissions.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Entry', '*', '*', 'ALLOW', 'ROLE', 'administrative'); diff --git a/db/changes/10281-valentineDay/00-ACL.sql b/db/changes/10281-valentineDay/00-ACL.sql new file mode 100644 index 0000000000..41626d4d6f --- /dev/null +++ b/db/changes/10281-valentineDay/00-ACL.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('Entry', '*', '*', 'ALLOW', 'ROLE', 'administrative'); From b3b99e651b3c69bc57ccb4b301c7d2ea08f86fe2 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Fri, 12 Feb 2021 15:02:30 +0100 Subject: [PATCH 18/18] description clears before changes --- e2e/paths/02-client/14_balance.spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/e2e/paths/02-client/14_balance.spec.js b/e2e/paths/02-client/14_balance.spec.js index 4917937fa4..d408215ff3 100644 --- a/e2e/paths/02-client/14_balance.spec.js +++ b/e2e/paths/02-client/14_balance.spec.js @@ -47,6 +47,7 @@ describe('Client balance path', () => { await page.closePopup(); await page.waitToClick(selectors.clientBalance.newPaymentButton); await page.autocompleteSearch(selectors.clientBalance.newPaymentBank, 'Cash'); + await page.clearInput(selectors.clientBalance.newDescription); await page.write(selectors.clientBalance.newDescription, 'Description'); await page.waitToClick(selectors.clientBalance.saveButton); const message = await page.waitForSnackbar(); @@ -86,6 +87,7 @@ describe('Client balance path', () => { await page.waitToClick(selectors.clientBalance.newPaymentButton); await page.write(selectors.clientBalance.newPaymentAmount, amountPaid); + await page.clearInput(selectors.clientBalance.newDescription); await page.write(selectors.clientBalance.newDescription, 'Payment'); await page.write(selectors.clientBalance.deliveredAmount, cashHanded); const refund = await page.waitToGetProperty(selectors.clientBalance.refundAmount, 'value'); @@ -107,6 +109,7 @@ describe('Client balance path', () => { await page.waitToClick(selectors.clientBalance.newPaymentButton); await page.autocompleteSearch(selectors.clientBalance.newPaymentBank, 'Pay on receipt'); await page.overwrite(selectors.clientBalance.newPaymentAmount, '-150'); + await page.clearInput(selectors.clientBalance.newDescription); await page.write(selectors.clientBalance.newDescription, 'Description'); await page.waitToClick(selectors.clientBalance.saveButton); const message = await page.waitForSnackbar();