From 7b57d79f50157c02f95db8adb067311cc4dacf15 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 21 Feb 2020 12:39:41 +0100 Subject: [PATCH 1/5] Create client geo auto fill --- back/models/province.json | 89 +++++++++++---------- front/core/components/datalist/index.js | 9 ++- modules/client/front/create/index.html | 67 ++++++---------- modules/client/front/create/index.js | 66 +++++++++++---- modules/client/front/fiscal-data/index.html | 55 ++++++------- modules/client/front/fiscal-data/index.js | 58 ++++++++++++++ 6 files changed, 213 insertions(+), 131 deletions(-) diff --git a/back/models/province.json b/back/models/province.json index 49a971b65..2e2ace5ed 100644 --- a/back/models/province.json +++ b/back/models/province.json @@ -1,46 +1,53 @@ { - "name": "Province", - "description": "Provinces of every country", - "base": "VnModel", - "options": { - "mysql": { - "table": "province" - } - }, - "properties": { - "id": { - "type": "Number", - "id": true, - "description": "Identifier" + "name": "Province", + "description": "Provinces of every country", + "base": "VnModel", + "options": { + "mysql": { + "table": "province" + } }, - "name": { - "type": "string", - "required": true - } - }, - "relations": { - "country": { - "type": "belongsTo", - "model": "Country", - "foreignKey": "countryFk" + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string", + "required": true + } }, - "warehouse": { - "type": "belongsTo", - "model": "Warehouse", - "foreignKey": "warehouseFk" + "relations": { + "country": { + "type": "belongsTo", + "model": "Country", + "foreignKey": "countryFk" + }, + "warehouse": { + "type": "belongsTo", + "model": "Warehouse", + "foreignKey": "warehouseFk" + }, + "zone": { + "type": "belongsTo", + "model": "Zone", + "foreignKey": "zoneFk" + } }, - "zone": { - "type": "belongsTo", - "model": "Zone", - "foreignKey": "zoneFk" - } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] + "scopes": { + "location": { + "include": { + "relation": "country" + } + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] } \ No newline at end of file diff --git a/front/core/components/datalist/index.js b/front/core/components/datalist/index.js index bf3cab9a1..adf33b50a 100644 --- a/front/core/components/datalist/index.js +++ b/front/core/components/datalist/index.js @@ -52,7 +52,14 @@ export default class Datalist extends Textfield { validSelection(selection) { return this.modelData && this.modelData.find(item => { - return item[this.valueField] == selection; + let dataValue = item[this.valueField]; + if (typeof(dataValue) === 'string') + dataValue = dataValue.toLowerCase(); + + if (typeof(selection) === 'string') + selection = selection.toLowerCase(); + + return dataValue == selection; }); } diff --git a/modules/client/front/create/index.html b/modules/client/front/create/index.html index ce4b7d4ed..23676a36f 100644 --- a/modules/client/front/create/index.html +++ b/modules/client/front/create/index.html @@ -49,76 +49,57 @@ - - + rule> + {{name}} ({{country.country}}) - - - - + + {{name}}, {{province.name}} + ({{province.country.country}}) + + + - - + this.$state.go('client.card.basicData', {id: json.data.id}) + ); + } + + get province() { + return this._province; + } + + // Province auto complete + set province(selection) { + this._province = selection; + + if (!selection) return; + + const country = selection.country; + + this.client.countryFk = country.id; + } + + get town() { + return this._town; + } + + // Town auto complete + set town(selection) { + this._town = selection; + + if (!selection) return; + + const province = selection.province; + const country = province.country; + const postcodes = selection.postcodes; + + this.client.provinceFk = province.id; + this.client.countryFk = country.id; + + if (postcodes.length === 1) + this.client.postcode = postcodes[0].code; + } + + get postcode() { + return this._postcode; + } + + // Postcode auto complete + set postcode(selection) { + this._postcode = selection; if (!selection) return; @@ -29,17 +76,8 @@ export default class Controller { this.client.provinceFk = province.id; this.client.countryFk = country.id; } - - onResponse(response) { - this.client.postcode = response.code; - } - - onSubmit() { - return this.$.watcher.submit().then( - json => this.$state.go('client.card.basicData', {id: json.data.id}) - ); - } } + Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp']; ngModule.component('vnClientCreate', { diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index 3bbc48630..98d0e9318 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -33,9 +33,7 @@ - - + {{name}} ({{country.country}}) - - - - - + show-field="code" + rule> + {{code}} - {{town.name}} ({{town.province.name}}, {{town.province.country.country}}) + Date: Mon, 24 Feb 2020 11:27:36 +0100 Subject: [PATCH 2/5] Added datalist auto completion --- front/core/components/datalist/index.js | 2 +- .../client/front/address/create/index.html | 76 +++++++++---------- modules/client/front/address/create/index.js | 60 ++++++++++----- modules/client/front/address/edit/index.html | 66 ++++++++-------- modules/client/front/address/edit/index.js | 48 +++++++++++- modules/client/front/create/index.html | 11 ++- modules/client/front/create/index.js | 8 +- modules/client/front/fiscal-data/index.html | 22 +++++- modules/client/front/fiscal-data/index.js | 19 +++-- modules/client/front/postcode/index.html | 2 +- modules/client/front/postcode/index.js | 31 ++++---- 11 files changed, 210 insertions(+), 135 deletions(-) diff --git a/front/core/components/datalist/index.js b/front/core/components/datalist/index.js index adf33b50a..d52e6ca23 100644 --- a/front/core/components/datalist/index.js +++ b/front/core/components/datalist/index.js @@ -27,7 +27,7 @@ export default class Datalist extends Textfield { value = value == '' || value == null ? null : value; oldValue = oldValue == '' || oldValue == null ? null : oldValue; - this.refreshSelection(); + if (oldValue === undefined) this.refreshSelection(); if (!value || value === oldValue && this.modelData != null) return; diff --git a/modules/client/front/address/create/index.html b/modules/client/front/address/create/index.html index 1c70a1cbd..383f37d0a 100644 --- a/modules/client/front/address/create/index.html +++ b/modules/client/front/address/create/index.html @@ -39,61 +39,53 @@ - + rule> + {{name}} ({{country.country}}) - - - - + - - + + {{code}} - {{town.name}} ({{town.province.name}}, + {{town.province.country.country}}) + + + + + + { if (this.address.isDefaultAddress) @@ -51,6 +31,46 @@ export default class Controller extends Component { return this.$http.post(`CustomsAgents`, this.newCustomsAgent) .then(res => this.address.customsAgentFk = res.data.id); } + + get town() { + return this._town; + } + + // Town auto complete + set town(selection) { + this._town = selection; + + if (!selection) return; + + const province = selection.province; + const postcodes = selection.postcodes; + + this.address.provinceId = province.id; + + if (postcodes.length === 1) + this.address.postalCode = postcodes[0].code; + } + + get postcode() { + return this._postcode; + } + + // Postcode auto complete + set postcode(selection) { + this._postcode = selection; + + if (!selection) return; + + const town = selection.town; + const province = town.province; + + this.address.city = town.name; + this.address.provinceId = province.id; + } + + onResponse(response) { + this.address.postalCode = response.code; + } } Controller.$inject = ['$element', '$scope']; diff --git a/modules/client/front/address/edit/index.html b/modules/client/front/address/edit/index.html index 035608120..a5a9d8e0a 100644 --- a/modules/client/front/address/edit/index.html +++ b/modules/client/front/address/edit/index.html @@ -65,49 +65,43 @@ value-field="id" label="Province"> - - - - + + {{name}}, {{province.name}} + ({{province.country.country}}) + + + - - - + + {{code}} - {{town.name}} ({{town.province.name}}, + {{town.province.country.country}}) + + + + + + this.$.model.save(true)) @@ -39,6 +35,50 @@ export default class Controller extends Component { return this.$http.post(`CustomsAgents`, this.newCustomsAgent) .then(res => this.address.customsAgentFk = res.data.id); } + + get town() { + return this._town; + } + + // Town auto complete + set town(selection) { + const oldValue = this._town; + this._town = selection; + + if (!selection || oldValue === null || oldValue === undefined) + return; + + const province = selection.province; + const postcodes = selection.postcodes; + + this.address.provinceFk = province.id; + + if (postcodes.length === 1) + this.address.postalCode = postcodes[0].code; + } + + get postcode() { + return this._postcode; + } + + // Postcode auto complete + set postcode(selection) { + const oldValue = this._postcode; + this._postcode = selection; + + if (!selection || oldValue === null || oldValue === undefined) + return; + + const town = selection.town; + const province = town.province; + + this.address.city = town.name; + this.address.provinceFk = province.id; + } + + onResponse(response) { + this.address.postalCode = response.code; + } } ngModule.component('vnClientAddressEdit', { diff --git a/modules/client/front/create/index.html b/modules/client/front/create/index.html index 23676a36f..faffc118f 100644 --- a/modules/client/front/create/index.html +++ b/modules/client/front/create/index.html @@ -96,9 +96,16 @@ show-field="code" rule> - {{code}}, {{town.name}} - {{town.province.name}} - ({{town.province.country.country}}) + {{code}} - {{town.name}} ({{town.province.name}}, + {{town.province.country.country}}) + + + + diff --git a/modules/client/front/create/index.js b/modules/client/front/create/index.js index 3201f7097..a663717d6 100644 --- a/modules/client/front/create/index.js +++ b/modules/client/front/create/index.js @@ -12,10 +12,6 @@ export default class Controller { }; } - onResponse(response) { - this.client.postcode = response.code; - } - onSubmit() { return this.$.watcher.submit().then( json => this.$state.go('client.card.basicData', {id: json.data.id}) @@ -76,6 +72,10 @@ export default class Controller { this.client.provinceFk = province.id; this.client.countryFk = country.id; } + + onResponse(response) { + this.client.postcode = response.code; + } } Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp']; diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index 98d0e9318..d29e31f64 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -64,7 +64,10 @@ where="{provinceFk: province.selection.id}" show-field="name" value-field="name"> - {{name}} ({{province.name}}, {{province.country.country}}) + + {{name}}, {{province.name}} + ({{province.country.country}}) + - {{code}} - {{town.name}} ({{town.province.name}}, {{town.province.country.country}}) + + {{code}} - {{town.name}} ({{town.province.name}}, + {{town.province.country.country}}) + + + + + @@ -148,3 +161,8 @@ message="Found a client with this data" on-accept="$ctrl.onAcceptDuplication()"> + + + \ No newline at end of file diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index 42aa8032a..e1669b1fa 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -86,7 +86,8 @@ export default class Controller extends Component { const oldValue = this._province; this._province = selection; - if (!selection || !oldValue) return; + if (!selection || oldValue === undefined) + return; const country = selection.country; @@ -102,7 +103,8 @@ export default class Controller extends Component { const oldValue = this._town; this._town = selection; - if (!selection || !oldValue) return; + if (!selection || oldValue === undefined) + return; const province = selection.province; const country = province.country; @@ -123,17 +125,24 @@ export default class Controller extends Component { set postcode(selection) { const oldValue = this._postcode; this._postcode = selection; - console.log(selection); - if (!selection || !oldValue) return; + console.log(oldValue); + if (!selection || oldValue === undefined) + return; + + console.log('setter'); const town = selection.town; const province = town.province; const country = province.country; - console.log(province.id); + this.client.city = town.name; this.client.provinceFk = province.id; this.client.countryFk = country.id; } + + onResponse(response) { + this.client.postcode = response.code; + } } ngModule.component('vnClientFiscalData', { diff --git a/modules/client/front/postcode/index.html b/modules/client/front/postcode/index.html index 55990281c..fd81534ed 100644 --- a/modules/client/front/postcode/index.html +++ b/modules/client/front/postcode/index.html @@ -1,7 +1,7 @@ + on-accept="$ctrl.onAccept()">
New postcode

Please, ensure you put the correct data!

diff --git a/modules/client/front/postcode/index.js b/modules/client/front/postcode/index.js index bbf0b1953..836ea9a81 100644 --- a/modules/client/front/postcode/index.js +++ b/modules/client/front/postcode/index.js @@ -35,25 +35,20 @@ class Controller extends Component { this.$.postcode.focus(); } - onResponse(response) { - if (response == 'accept') { - try { - if (!this.data.code) - throw new Error(`The postcode can't be empty`); - if (!this.data.townFk) - throw new Error(`The town can't be empty`); + onAccept() { + try { + if (!this.data.code) + throw new Error(`The postcode can't be empty`); + if (!this.data.townFk) + throw new Error(`The town can't be empty`); - this.$http.patch(`postcodes`, this.data).then(response => { - if (response.data) { - this.vnApp.showMessage(this.$translate.instant('The postcode has been saved')); - - this.emit('response', {response: response.data}); - } - }); - } catch (e) { - this.vnApp.showError(this.$translate.instant(e.message)); - return false; - } + this.$http.patch(`postcodes`, this.data).then(res => { + this.vnApp.showMessage(this.$translate.instant('The postcode has been saved')); + this.emit('response', {$response: res.data}); + }); + } catch (e) { + this.vnApp.showError(this.$translate.instant(e.message)); + return false; } return true; } From 04917f980facfdab194187db601f4b20f22de168 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 2 Mar 2020 09:30:54 +0100 Subject: [PATCH 3/5] Updated E2E --- db/dump/fixtures.sql | 6 +- e2e/helpers/selectors.js | 12 ++-- e2e/paths/02-client/01_create_client.spec.js | 2 +- .../02-client/03_edit_fiscal_data.spec.js | 3 +- e2e/paths/02-client/05_add_address.spec.js | 14 +++- .../client/front/address/create/index.html | 48 ++++++------- modules/client/front/address/edit/index.html | 47 ++++++------ modules/client/front/create/index.html | 69 +++++++++--------- modules/client/front/fiscal-data/index.html | 71 +++++++++---------- 9 files changed, 136 insertions(+), 136 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 2f3a9378d..a62edad46 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -197,14 +197,16 @@ INSERT INTO `vn`.`town`(`id`, `name`, `provinceFk`) (1, 'Valencia', 1), (2, 'Silla', 1), (3, 'Algemesi', 1), - (4, 'Alzira', 1); + (4, 'Alzira', 1), + (5, 'Quito', 5); INSERT INTO `vn`.`postCode`(`code`, `townFk`, `geoFk`) VALUES ('46000', 1, 6), ('46460', 2, 6), ('46680', 3, 6), - ('46600', 4, 7); + ('46600', 4, 7), + ('EC170150', 5, 8); INSERT INTO `vn`.`clientType`(`id`, `code`, `type`) VALUES diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 7e3e726e4..0f31b2e0c 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -43,8 +43,8 @@ export default { taxNumber: 'vn-client-create vn-textfield[ng-model="$ctrl.client.fi"]', socialName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.socialName"]', street: 'vn-client-create vn-textfield[ng-model="$ctrl.client.street"]', - postcode: 'vn-client-create vn-textfield[ng-model="$ctrl.client.postcode"]', - city: 'vn-client-create vn-textfield[ng-model="$ctrl.client.city"]', + postcode: 'vn-client-create vn-datalist[ng-model="$ctrl.client.postcode"]', + city: 'vn-client-create vn-datalist[ng-model="$ctrl.client.city"]', province: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.provinceFk"]', country: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.countryFk"]', userName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.userName"]', @@ -75,8 +75,8 @@ export default { equalizationTaxCheckbox: 'vn-client-fiscal-data vn-check[ng-model="$ctrl.client.isEqualizated"]', acceptPropagationButton: '.vn-confirm.shown button[response=accept]', address: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.street"]', - postcode: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.postcode"]', - city: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.city"]', + postcode: 'vn-client-fiscal-data vn-datalist[ng-model="$ctrl.client.postcode"]', + city: 'vn-client-fiscal-data vn-datalist[ng-model="$ctrl.client.city"]', province: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.provinceFk"]', country: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.countryFk"]', activeCheckbox: 'vn-client-fiscal-data vn-check[label="Active"]', @@ -113,8 +113,8 @@ export default { defaultCheckbox: 'vn-check[label="Default"]', consignee: 'vn-textfield[ng-model="$ctrl.address.nickname"]', streetAddress: 'vn-textfield[ng-model="$ctrl.address.street"]', - postcode: 'vn-textfield[ng-model="$ctrl.address.postalCode"]', - city: 'vn-textfield[ng-model="$ctrl.address.city"]', + postcode: 'vn-datalist[ng-model="$ctrl.address.postalCode"]', + city: 'vn-datalist[ng-model="$ctrl.address.city"]', province: 'vn-autocomplete[ng-model="$ctrl.address.provinceId"]', agency: 'vn-autocomplete[ng-model="$ctrl.address.agencyModeId"]', phone: 'vn-textfield[ng-model="$ctrl.address.phone"]', diff --git a/e2e/paths/02-client/01_create_client.spec.js b/e2e/paths/02-client/01_create_client.spec.js index 27ed5049a..65db9e7c6 100644 --- a/e2e/paths/02-client/01_create_client.spec.js +++ b/e2e/paths/02-client/01_create_client.spec.js @@ -87,7 +87,7 @@ describe('Client create path', async() => { .waitToGetProperty(selectors.createClientView.country, 'value'); expect(clientCity).toEqual('Valencia'); - expect(clientProvince).toEqual('Province one'); + expect(clientProvince).toContain('Province one'); expect(clientCountry).toEqual('EspaƱa'); }); diff --git a/e2e/paths/02-client/03_edit_fiscal_data.spec.js b/e2e/paths/02-client/03_edit_fiscal_data.spec.js index f7d6cbe92..4cd54b87d 100644 --- a/e2e/paths/02-client/03_edit_fiscal_data.spec.js +++ b/e2e/paths/02-client/03_edit_fiscal_data.spec.js @@ -198,11 +198,10 @@ describe('Client Edit fiscalData path', () => { expect(result).toEqual('Valencia'); }); - it(`should confirm the province have been autocompleted`, async() => { const result = await page.waitToGetProperty(selectors.clientFiscalData.province, 'value'); - expect(result).toEqual('Province one'); + expect(result).toContain('Province one'); }); it('should confirm the country have been autocompleted', async() => { diff --git a/e2e/paths/02-client/05_add_address.spec.js b/e2e/paths/02-client/05_add_address.spec.js index 737d6b05b..c9228e1cf 100644 --- a/e2e/paths/02-client/05_add_address.spec.js +++ b/e2e/paths/02-client/05_add_address.spec.js @@ -25,9 +25,7 @@ describe('Client Add address path', () => { it('should receive an error after clicking save button as consignee, street and town fields are empty', async() => { await page.waitToClick(selectors.clientAddresses.defaultCheckbox); - await page.autocompleteSearch(selectors.clientAddresses.province, 'Province five'); - await page.write(selectors.clientAddresses.city, 'Valencia'); - await page.write(selectors.clientAddresses.postcode, '46000'); + await page.write(selectors.clientAddresses.postcode, 'EC170150'); await page.autocompleteSearch(selectors.clientAddresses.agency, 'Entanglement'); await page.write(selectors.clientAddresses.phone, '999887744'); await page.write(selectors.clientAddresses.mobileInput, '999887744'); @@ -37,6 +35,16 @@ describe('Client Add address path', () => { expect(result).toEqual('Some fields are invalid'); }); + it('should confirm that the city and province are propertly filled', async() => { + const city = await page + .waitToGetProperty(selectors.clientAddresses.city, 'value'); + + const province = await page + .waitToGetProperty(selectors.clientAddresses.province, 'value'); + + expect(city).toEqual('Quito'); + expect(province).toContain('Province five'); + }); it(`should receive an error after clicking save button as consignee, incoterms and customsAgent are empty`, async() => { await page.write(selectors.clientAddresses.consignee, 'Bruce Bunner'); diff --git a/modules/client/front/address/create/index.html b/modules/client/front/address/create/index.html index 383f37d0a..ef4c869f1 100644 --- a/modules/client/front/address/create/index.html +++ b/modules/client/front/address/create/index.html @@ -39,37 +39,12 @@
- - {{name}} ({{country.country}}) - - - - {{name}}, {{province.name}} - ({{province.country.country}}) - - + + + {{name}}, {{province.name}} + ({{province.country.country}}) + + + + {{name}} ({{country.country}}) + - - - - - {{name}}, {{province.name}} - ({{province.country.country}}) - - + + + {{name}}, {{province.name}} + ({{province.country.country}}) + + + + {{name}} ({{country.country}}) + - - - - {{name}} ({{country.country}}) - - - - - - {{name}}, {{province.name}} - ({{province.country.country}}) - - + + + {{name}}, {{province.name}} + ({{province.country.country}}) + + + + + + {{name}} ({{country.country}}) + + + - - - - {{name}} ({{country.country}}) - - - - - - {{name}}, {{province.name}} - ({{province.country.country}}) - - + + + {{name}}, {{province.name}} + ({{province.country.country}}) + + + + + + {{name}} ({{country.country}}) + + + Date: Tue, 3 Mar 2020 15:03:54 +0100 Subject: [PATCH 4/5] Updated unit tests --- loopback/locale/en.json | 3 +- .../client/front/address/create/index.spec.js | 47 ++++++++++- modules/client/front/address/edit/index.js | 6 +- modules/client/front/create/index.spec.js | 60 +++++++++++++- modules/client/front/fiscal-data/index.js | 11 +-- .../client/front/fiscal-data/index.spec.js | 83 +++++++++++++++++++ modules/client/front/postcode/index.spec.js | 4 +- .../back/methods/travel/createThermograph.js | 2 +- .../back/methods/travel/updateThermograph.js | 2 +- 9 files changed, 194 insertions(+), 24 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 49cd0f171..b8c31020b 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -64,5 +64,6 @@ "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", - "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}" + "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}", + "Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment" } \ No newline at end of file diff --git a/modules/client/front/address/create/index.spec.js b/modules/client/front/address/create/index.spec.js index 289e0572d..fb6567dce 100644 --- a/modules/client/front/address/create/index.spec.js +++ b/modules/client/front/address/create/index.spec.js @@ -53,9 +53,48 @@ describe('Client', () => { }); }); - describe('postcodeSelection() setter', () => { - it(`should set the town, province and contry properties`, () => { - controller.postcodeSelection = { + describe('town() setter', () => { + it(`should set provinceId property`, () => { + controller.town = { + provinceFk: 1, + code: 46001, + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }, + postcodes: [] + }; + + expect(controller.address.provinceId).toEqual(1); + }); + + it(`should set provinceId property and fill the postalCode if there's just one`, () => { + controller.town = { + provinceFk: 1, + code: 46001, + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }, + postcodes: [{code: '46001'}] + }; + + expect(controller.address.provinceId).toEqual(1); + expect(controller.address.postalCode).toEqual('46001'); + }); + }); + + describe('postcode() setter', () => { + it(`should set the town and province properties`, () => { + controller.postcode = { townFk: 1, code: 46001, town: { @@ -73,7 +112,7 @@ describe('Client', () => { }; expect(controller.address.city).toEqual('New York'); - expect(controller.address.provinceFk).toEqual(1); + expect(controller.address.provinceId).toEqual(1); }); }); diff --git a/modules/client/front/address/edit/index.js b/modules/client/front/address/edit/index.js index 8e43c27b1..f310b7250 100644 --- a/modules/client/front/address/edit/index.js +++ b/modules/client/front/address/edit/index.js @@ -45,8 +45,7 @@ export default class Controller extends Component { const oldValue = this._town; this._town = selection; - if (!selection || oldValue === null || oldValue === undefined) - return; + if (!oldValue) return; const province = selection.province; const postcodes = selection.postcodes; @@ -66,8 +65,7 @@ export default class Controller extends Component { const oldValue = this._postcode; this._postcode = selection; - if (!selection || oldValue === null || oldValue === undefined) - return; + if (!oldValue) return; const town = selection.town; const province = town.province; diff --git a/modules/client/front/create/index.spec.js b/modules/client/front/create/index.spec.js index 656392e3d..c297b0545 100644 --- a/modules/client/front/create/index.spec.js +++ b/modules/client/front/create/index.spec.js @@ -40,9 +40,63 @@ describe('Client', () => { }); }); - describe('postcodeSelection() setter', () => { - it(`should set the town, province and contry properties`, () => { - controller.postcodeSelection = { + describe('province() setter', () => { + it(`should set countryFk property`, () => { + controller.province = { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }; + + expect(controller.client.countryFk).toEqual(2); + }); + }); + + describe('town() setter', () => { + it(`should set provinceFk property`, () => { + controller.town = { + provinceFk: 1, + code: 46001, + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }, + postcodes: [] + }; + + expect(controller.client.provinceFk).toEqual(1); + }); + + it(`should set provinceFk property and fill the postalCode if there's just one`, () => { + controller.town = { + provinceFk: 1, + code: 46001, + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }, + postcodes: [{code: '46001'}] + }; + + expect(controller.client.provinceFk).toEqual(1); + expect(controller.client.postcode).toEqual('46001'); + }); + }); + + describe('postcode() setter', () => { + it(`should set the town, provinceFk and contryFk properties`, () => { + controller.postcode = { townFk: 1, code: 46001, town: { diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index f118dbaae..4450f2e32 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -87,8 +87,7 @@ export default class Controller extends Component { const oldValue = this._province; this._province = selection; - if (!selection || oldValue === undefined) - return; + if (!oldValue) return; const country = selection.country; @@ -104,8 +103,7 @@ export default class Controller extends Component { const oldValue = this._town; this._town = selection; - if (!selection || oldValue === undefined) - return; + if (!oldValue) return; const province = selection.province; const country = province.country; @@ -126,11 +124,8 @@ export default class Controller extends Component { set postcode(selection) { const oldValue = this._postcode; this._postcode = selection; - console.log(oldValue); - if (!selection || oldValue === undefined) - return; - console.log('setter'); + if (!oldValue) return; const town = selection.town; const province = town.province; diff --git a/modules/client/front/fiscal-data/index.spec.js b/modules/client/front/fiscal-data/index.spec.js index 52c2ee29e..6e8d6a8f0 100644 --- a/modules/client/front/fiscal-data/index.spec.js +++ b/modules/client/front/fiscal-data/index.spec.js @@ -25,6 +25,10 @@ describe('Client', () => { isEqualizated: false, isTaxDataChecked: false }; + + controller.province = {}; + controller.town = {}; + controller.postcode = {}; })); describe('onSubmit()', () => { @@ -107,5 +111,84 @@ describe('Client', () => { $httpBackend.flush(); }); }); + + describe('province() setter', () => { + it(`should set countryFk property`, () => { + controller.province = { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }; + + expect(controller.client.countryFk).toEqual(2); + }); + }); + + describe('town() setter', () => { + it(`should set provinceFk property`, () => { + controller.town = { + provinceFk: 1, + code: 46001, + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }, + postcodes: [] + }; + + expect(controller.client.provinceFk).toEqual(1); + }); + + it(`should set provinceFk property and fill the postalCode if there's just one`, () => { + controller.town = { + provinceFk: 1, + code: 46001, + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + }, + postcodes: [{code: '46001'}] + }; + + expect(controller.client.provinceFk).toEqual(1); + expect(controller.client.postcode).toEqual('46001'); + }); + }); + + describe('postcode() setter', () => { + it(`should set the town, provinceFk and contryFk properties`, () => { + controller.postcode = { + townFk: 1, + code: 46001, + town: { + id: 1, + name: 'New York', + province: { + id: 1, + name: 'New york', + country: { + id: 2, + name: 'USA' + } + } + } + }; + + expect(controller.client.city).toEqual('New York'); + expect(controller.client.provinceFk).toEqual(1); + expect(controller.client.countryFk).toEqual(2); + }); + }); }); }); diff --git a/modules/client/front/postcode/index.spec.js b/modules/client/front/postcode/index.spec.js index 04f1a8924..a5e5db9d5 100644 --- a/modules/client/front/postcode/index.spec.js +++ b/modules/client/front/postcode/index.spec.js @@ -15,7 +15,7 @@ describe('Client', () => { controller.client = {id: 101}; })); - describe('onResponse()', () => { + describe('onAccept()', () => { it('should perform a POST query and show a success snackbar', () => { let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'}; controller.data = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'}; @@ -24,7 +24,7 @@ describe('Client', () => { $httpBackend.when('PATCH', `postcodes`, params).respond(200, params); $httpBackend.expect('PATCH', `postcodes`, params).respond(params); - controller.onResponse('accept'); + controller.onAccept(); $httpBackend.flush(); expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been saved'); diff --git a/modules/travel/back/methods/travel/createThermograph.js b/modules/travel/back/methods/travel/createThermograph.js index d5388295a..974b67923 100644 --- a/modules/travel/back/methods/travel/createThermograph.js +++ b/modules/travel/back/methods/travel/createThermograph.js @@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('createThermograph', { - description: 'Upload and attach a document', + description: 'Creates a new travel thermograph', accessType: 'WRITE', accepts: [{ arg: 'id', diff --git a/modules/travel/back/methods/travel/updateThermograph.js b/modules/travel/back/methods/travel/updateThermograph.js index efad606eb..d89725920 100644 --- a/modules/travel/back/methods/travel/updateThermograph.js +++ b/modules/travel/back/methods/travel/updateThermograph.js @@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('updateThermograph', { - description: 'updates a file properties or file', + description: 'Updates a travel thermograph', accessType: 'WRITE', accepts: [{ arg: 'id', From 5da1c4147635248ace0aeb9601222a5764f32ac3 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 4 Mar 2020 12:51:29 +0100 Subject: [PATCH 5/5] Added ACL --- modules/client/front/address/create/index.html | 4 +++- modules/client/front/address/edit/index.html | 6 ++++-- modules/client/front/create/index.html | 4 +++- modules/client/front/fiscal-data/index.html | 4 +++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/client/front/address/create/index.html b/modules/client/front/address/create/index.html index ef4c869f1..519638d48 100644 --- a/modules/client/front/address/create/index.html +++ b/modules/client/front/address/create/index.html @@ -57,7 +57,9 @@ + ng-click="postcode.open()" + vn-acl="deliveryBoss" + vn-acl-action="remove"> diff --git a/modules/client/front/address/edit/index.html b/modules/client/front/address/edit/index.html index 877599377..70b3523c5 100644 --- a/modules/client/front/address/edit/index.html +++ b/modules/client/front/address/edit/index.html @@ -71,10 +71,12 @@ {{town.province.country.country}}) - + ng-click="postcode.open()" + vn-acl="deliveryBoss" + vn-acl-action="remove"> diff --git a/modules/client/front/create/index.html b/modules/client/front/create/index.html index 8d44aaae0..b2ef42beb 100644 --- a/modules/client/front/create/index.html +++ b/modules/client/front/create/index.html @@ -67,7 +67,9 @@ + ng-click="postcode.open()" + vn-acl="deliveryBoss" + vn-acl-action="remove"> diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index 1cda1fc8a..0339090a2 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -51,7 +51,9 @@ + ng-click="postcode.open()" + vn-acl="deliveryBoss" + vn-acl-action="remove">