From 1adaeca61524a436cbd046af2c996010aed1576d Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Mon, 8 Feb 2021 08:41:26 +0100 Subject: [PATCH 01/11] 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 000000000..12a190e19 --- /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 02/11] 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 000000000..7e70c454b --- /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 12a190e19..000000000 --- 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 46d33b305..e2bb94c87 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 0931c322e..6db662a54 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 99f52b322..a00a3fb79 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 03/11] 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 000000000..d3b02fc2d --- /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 db12e95fd..1911f721c 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 04/11] 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 7e70c454b..d688fc040 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 70b493ce5..0139be507 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 a00a3fb79..d85e93718 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 05/11] 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 3d3f0d013..000000000 --- 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 1d989cbfb..000000000 --- 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 5a9addeea..000000000 --- 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 069601a20..000000000 --- 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 448db0777..000000000 --- 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 7443ad4e3..000000000 --- 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 74a302d06..000000000 --- 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 975b186ef..000000000 --- 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 84273ded8..000000000 --- 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 782690e88..000000000 --- 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 1171366da..000000000 --- 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 f24fb997e..9a9334c41 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 cf2ec3264..73ff28246 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 06/11] 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 62c580aca..34d152bc6 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 07/11] 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 34d152bc6..62c580aca 100644 --- a/modules/supplier/back/model-config.json +++ b/modules/supplier/back/model-config.json @@ -10,5 +10,8 @@ }, "SupplierContact": { "dataSource": "vn" + }, + "SupplierAccount": { + "dataSource": "vn" } } diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json new file mode 100644 index 000000000..237934f8c --- /dev/null +++ b/modules/supplier/back/models/supplier-account.json @@ -0,0 +1,50 @@ +{ + "name": "SupplierAccount", + "base": "VnModel", + "options": { + "mysql": { + "table": "supplierAccount" + } + }, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "supplierFk": { + "type": "Number" + }, + "iban": { + "type": "String" + }, + "office": { + "type": "String" + }, + "DC": { + "type": "String" + }, + "number": { + "type": "String" + }, + "description": { + "type": "String" + }, + "bicSufix": { + "type": "String" + }, + "bankEntityFk": { + "type": "Number" + }, + "bankFk": { + "type": "Number" + } + }, + "relations": { + "supplier": { + "type": "belongsTo", + "model": "Supplier", + "foreignKey": "supplierFk" + } + } +} \ No newline at end of file diff --git a/modules/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 d688fc040..bcc98dbe2 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 e2bb94c87..046153ee2 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 6db662a54..6c19e0e12 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 08/11] 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 5b73a2d72..174a9e093 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 09/11] 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 d3b02fc2d..000000000 --- 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 000000000..41626d4d6 --- /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 a3d7fc9313bb157df4db4f4cf32b7d452fb02d0a Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 12 Feb 2021 13:18:02 +0100 Subject: [PATCH 10/11] done --- back/methods/dms/uploadFile.js | 3 +- e2e/paths/02-client/14_balance.spec.js | 4 +- .../client/specs/createReceipt.spec.js | 109 ++++++++++-------- modules/client/back/models/receipt.js | 13 ++- 4 files changed, 71 insertions(+), 58 deletions(-) diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index c3065c3cc..d6540cbc5 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -110,11 +110,10 @@ module.exports = Self => { async function createDms(ctx, file, myOptions) { const models = Self.app.models; const myUserId = ctx.req.accessToken.userId; - const myWorker = await models.Worker.findOne({where: {userFk: myUserId}}, myOptions); const args = ctx.args; const newDms = await Self.create({ - workerFk: myWorker.id, + workerFk: myUserId, dmsTypeFk: args.dmsTypeId, companyFk: args.companyId, warehouseFk: args.warehouseId, diff --git a/e2e/paths/02-client/14_balance.spec.js b/e2e/paths/02-client/14_balance.spec.js index 4917937fa..22d3f15ac 100644 --- a/e2e/paths/02-client/14_balance.spec.js +++ b/e2e/paths/02-client/14_balance.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors'; import getBrowser from '../../helpers/puppeteer'; -describe('Client balance path', () => { +fdescribe('Client balance path', () => { let browser; let page; beforeAll(async() => { @@ -86,7 +86,7 @@ describe('Client balance path', () => { await page.waitToClick(selectors.clientBalance.newPaymentButton); await page.write(selectors.clientBalance.newPaymentAmount, amountPaid); - await page.write(selectors.clientBalance.newDescription, 'Payment'); + await page.write(selectors.clientBalance.deliveredAmount, cashHanded); const refund = await page.waitToGetProperty(selectors.clientBalance.refundAmount, 'value'); await page.waitToClick(selectors.clientBalance.saveButton); diff --git a/modules/client/back/methods/client/specs/createReceipt.spec.js b/modules/client/back/methods/client/specs/createReceipt.spec.js index 3bd560cdd..8d35064a2 100644 --- a/modules/client/back/methods/client/specs/createReceipt.spec.js +++ b/modules/client/back/methods/client/specs/createReceipt.spec.js @@ -1,4 +1,5 @@ const app = require('vn-loopback/server/server'); +const LoopBackContext = require('loopback-context'); describe('Client createReceipt', () => { const clientFk = 108; @@ -6,18 +7,34 @@ describe('Client createReceipt', () => { const companyFk = 442; const amountPaid = 12.50; const description = 'Receipt description'; + const activeCtx = { + accessToken: {userId: 5}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + const ctx = {req: activeCtx}; + activeCtx.http.req.__ = value => { + return value; + }; + + beforeEach(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); it('should create a new receipt', async() => { const bankFk = 1; - let ctx = { - args: { - clientFk: clientFk, - payed: payed, - companyFk: companyFk, - bankFk: bankFk, - amountPaid: amountPaid, - description: description - } + ctx.args = { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description }; const receipt = await app.models.Client.createReceipt(ctx); @@ -40,15 +57,14 @@ describe('Client createReceipt', () => { it('should throw Compensation account is empty', async() => { const bankFk = 3; - let ctx = { - args: { - clientFk: clientFk, - payed: payed, - companyFk: companyFk, - bankFk: bankFk, - amountPaid: amountPaid, - description: description - } + + ctx.args = { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description }; try { @@ -64,16 +80,14 @@ describe('Client createReceipt', () => { it('should throw Invalid account if compensationAccount does not belongs to a client nor a supplier', async() => { let error; const bankFk = 3; - const ctx = { - args: { - clientFk: clientFk, - payed: payed, - companyFk: companyFk, - bankFk: bankFk, - amountPaid: amountPaid, - description: description, - compensationAccount: 'non existing account' - } + ctx.args = { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description, + compensationAccount: 'non existing account' }; try { @@ -88,16 +102,15 @@ describe('Client createReceipt', () => { it('should create a new receipt with a compensation for a client', async() => { const bankFk = 3; - const ctx = { - args: { - clientFk: clientFk, - payed: payed, - companyFk: companyFk, - bankFk: bankFk, - amountPaid: amountPaid, - description: description, - compensationAccount: '4300000001' - } + + ctx.args = { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description, + compensationAccount: '4300000001' }; const receipt = await app.models.Client.createReceipt(ctx); const receiptCompensated = await app.models.Receipt.findOne({ @@ -127,16 +140,16 @@ describe('Client createReceipt', () => { }); it('should create a new receipt with a compensation for a supplier', async() => { - const ctx = { - args: { - clientFk: clientFk, - payed: payed, - companyFk: companyFk, - bankFk: 3, - amountPaid: amountPaid, - description: description, - compensationAccount: '4100000001' - } + const bankFk = 3; + + ctx.args = { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description, + compensationAccount: '4100000001' }; const receipt = await app.models.Client.createReceipt(ctx); diff --git a/modules/client/back/models/receipt.js b/modules/client/back/models/receipt.js index 88b7bfb5b..03a05490e 100644 --- a/modules/client/back/models/receipt.js +++ b/modules/client/back/models/receipt.js @@ -1,3 +1,5 @@ +const LoopBackContext = require('loopback-context'); + module.exports = function(Self) { require('../methods/receipt/filter')(Self); @@ -23,13 +25,12 @@ module.exports = function(Self) { Self.observe('before save', async function(ctx) { if (ctx.isNewInstance) { - let token = ctx.options.accessToken; - let userId = token && token.userId; - - ctx.instance.workerFk = userId; - + const loopBackContext = LoopBackContext.getCurrentContext(); + console.log(loopBackContext); + ctx.instance.workerFk = loopBackContext.active.accessToken.userId; + console.log(ctx.instance.workerFk); await Self.app.models.Till.create({ - workerFk: userId, + workerFk: ctx.instance.workerFk, bankFk: ctx.instance.bankFk, in: ctx.instance.amountPaid, concept: ctx.instance.description, From 7c0e690f8fb90a5ff28e416cca03dc3b7ee56c83 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 15 Feb 2021 14:34:13 +0100 Subject: [PATCH 11/11] sin console --- loopback/locale/en.json | 3 ++- modules/client/back/models/receipt.js | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 44f882638..c5062c3e9 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -91,5 +91,6 @@ "The observation type can't be repeated": "The observation type can't be repeated", "New ticket request has been created with price": "New ticket request has been created *'{{description}}'* for day *{{shipped}}*, with a quantity of *{{quantity}}* and a price of *{{price}} €*", "New ticket request has been created": "New ticket request has been created *'{{description}}'* for day *{{shipped}}*, with a quantity of *{{quantity}}*", - "There's a new urgent ticket": "There's a new urgent ticket: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})" + "There's a new urgent ticket": "There's a new urgent ticket: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})", + "Swift / BIC cannot be empty": "Swift / BIC cannot be empty" } \ No newline at end of file diff --git a/modules/client/back/models/receipt.js b/modules/client/back/models/receipt.js index 03a05490e..36a4a8952 100644 --- a/modules/client/back/models/receipt.js +++ b/modules/client/back/models/receipt.js @@ -26,9 +26,7 @@ module.exports = function(Self) { Self.observe('before save', async function(ctx) { if (ctx.isNewInstance) { const loopBackContext = LoopBackContext.getCurrentContext(); - console.log(loopBackContext); ctx.instance.workerFk = loopBackContext.active.accessToken.userId; - console.log(ctx.instance.workerFk); await Self.app.models.Till.create({ workerFk: ctx.instance.workerFk, bankFk: ctx.instance.bankFk,