diff --git a/back/model-config.json b/back/model-config.json
index a0c3d8740..b24226507 100644
--- a/back/model-config.json
+++ b/back/model-config.json
@@ -11,6 +11,9 @@
"Company": {
"dataSource": "vn"
},
+ "Container": {
+ "dataSource": "storage"
+ },
"Delivery": {
"dataSource": "vn"
},
@@ -44,8 +47,11 @@
"DmsType": {
"dataSource": "vn"
},
- "Container": {
- "dataSource": "storage"
+ "Town": {
+ "dataSource": "vn"
+ },
+ "Postcode": {
+ "dataSource": "vn"
}
}
diff --git a/back/models/postcode.json b/back/models/postcode.json
new file mode 100644
index 000000000..e28a77dc4
--- /dev/null
+++ b/back/models/postcode.json
@@ -0,0 +1,50 @@
+{
+ "name": "Postcode",
+ "base": "VnModel",
+ "options": {
+ "mysql": {
+ "table": "postCode"
+ }
+ },
+ "properties": {
+ "code": {
+ "id": true,
+ "type": "String"
+ }
+ },
+ "relations": {
+ "town": {
+ "type": "belongsTo",
+ "model": "Town",
+ "foreignKey": "townFk"
+ },
+ "geo": {
+ "type": "belongsTo",
+ "model": "ZoneGeo",
+ "foreignKey": "geoFk"
+ }
+ },
+ "acls": [{
+ "accessType": "READ",
+ "principalType": "ROLE",
+ "principalId": "$everyone",
+ "permission": "ALLOW"
+ }],
+ "scopes": {
+ "location": {
+ "include": {
+ "relation": "town",
+ "scope": {
+ "include": {
+ "relation": "province",
+ "scope": {
+ "include": {
+ "relation": "country"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/back/models/town.json b/back/models/town.json
new file mode 100644
index 000000000..8ae252780
--- /dev/null
+++ b/back/models/town.json
@@ -0,0 +1,56 @@
+{
+ "name": "Town",
+ "base": "VnModel",
+ "options": {
+ "mysql": {
+ "table": "town"
+ }
+ },
+ "properties": {
+ "id": {
+ "id": true,
+ "type": "Number"
+ },
+ "name": {
+ "type": "String"
+ }
+ },
+ "relations": {
+ "province": {
+ "type": "belongsTo",
+ "model": "Province",
+ "foreignKey": "provinceFk"
+ },
+ "postcodes": {
+ "type": "hasMany",
+ "model": "Postcode",
+ "foreignKey": "townFk"
+ },
+ "geo": {
+ "type": "belongsTo",
+ "model": "ZoneGeo",
+ "foreignKey": "geoFk"
+ }
+ },
+ "acls": [{
+ "accessType": "READ",
+ "principalType": "ROLE",
+ "principalId": "$everyone",
+ "permission": "ALLOW"
+ }],
+ "scopes": {
+ "location": {
+ "include": [{
+ "relation": "province",
+ "scope": {
+ "include": {
+ "relation": "country"
+ }
+ }
+ },
+ {
+ "relation": "postcodes"
+ }]
+ }
+ }
+}
\ No newline at end of file
diff --git a/db/docker-boot.sh b/db/docker-boot.sh
index 0d9eb9f35..6e04d3377 100755
--- a/db/docker-boot.sh
+++ b/db/docker-boot.sh
@@ -5,7 +5,7 @@ export MYSQL_PWD=root
mysql_import() {
FILE=$1
echo "[INFO] -> Imported $FILE"
- mysql -u root --comments -f < "$FILE"
+ mysql -u root --default-character-set=utf8 --comments -f < "$FILE"
}
mysql_import dump/structure.sql
diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql
index c7bc0881e..eb44a0f75 100644
--- a/db/dump/fixtures.sql
+++ b/db/dump/fixtures.sql
@@ -147,6 +147,20 @@ INSERT INTO `vn`.`province`(`id`, `name`, `countryFk`, `warehouseFk`, `zoneFk`)
(4, 'Province four', 1, NULL, 2),
(5, 'Province five', 1, NULL, 1);
+INSERT INTO `vn`.`town`(`id`, `name`, `provinceFk`)
+ VALUES
+ (1, 'Valencia', 1),
+ (2, 'Silla', 1),
+ (3, 'Algemesi', 1),
+ (4, 'Alzira', 1);
+
+INSERT INTO `vn`.`postCode`(`code`, `townFk`)
+ VALUES
+ ('46000', 1),
+ ('46460', 2),
+ ('46680', 3),
+ ('46600', 4);
+
INSERT INTO `vn`.`clientType`(`id`, `code`, `type`)
VALUES
(1, 'normal', 'Normal'),
diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js
index 908c22d68..3c264006b 100644
--- a/e2e/helpers/selectors.js
+++ b/e2e/helpers/selectors.js
@@ -33,7 +33,10 @@ export default {
taxNumber: `${components.vnTextfield}[name="fi"]`,
socialName: `${components.vnTextfield}[name="socialName"]`,
street: `${components.vnTextfield}[name="street"]`,
- city: `${components.vnTextfield}[name="city"]`,
+ postcode: `vn-autocomplete[field="$ctrl.client.postcode"]`,
+ city: `vn-autocomplete[field="$ctrl.client.city"]`,
+ province: `vn-autocomplete[field="$ctrl.client.provinceFk"]`,
+ country: `vn-autocomplete[field="$ctrl.client.countryFk"]`,
userName: `${components.vnTextfield}[name="userName"]`,
email: `${components.vnTextfield}[name="email"]`,
salesPersonAutocomplete: `vn-autocomplete[field="$ctrl.client.salesPersonFk"]`,
@@ -62,8 +65,8 @@ export default {
equalizationTaxCheckbox: 'vn-check[label="Is equalizated"] md-checkbox',
acceptPropagationButton: 'vn-client-fiscal-data > vn-confirm button[response=ACCEPT]',
addressInput: `${components.vnTextfield}[name="street"]`,
- cityInput: `${components.vnTextfield}[name="city"]`,
- postcodeInput: `${components.vnTextfield}[name="postcode"]`,
+ postcodeAutocomplete: `vn-autocomplete[field="$ctrl.client.postcode"]`,
+ cityAutocomplete: `vn-autocomplete[field="$ctrl.client.city"]`,
provinceAutocomplete: 'vn-autocomplete[field="$ctrl.client.provinceFk"]',
countryAutocomplete: 'vn-autocomplete[field="$ctrl.client.countryFk"]',
activeCheckbox: 'vn-check[label="Active"] md-checkbox',
@@ -97,8 +100,8 @@ export default {
defaultCheckboxInput: 'vn-check[label="Default"] md-checkbox',
consigneeInput: `${components.vnTextfield}[name="nickname"]`,
streetAddressInput: `${components.vnTextfield}[name="street"]`,
- postcodeInput: `${components.vnTextfield}[name="postalCode"]`,
- cityInput: `${components.vnTextfield}[name="city"]`,
+ postcodeAutocomplete: `vn-autocomplete[field="$ctrl.address.postalCode"]`,
+ cityAutocomplete: `vn-autocomplete[field="$ctrl.address.city"]`,
provinceAutocomplete: 'vn-autocomplete[field="$ctrl.address.provinceFk"]',
agencyAutocomplete: 'vn-autocomplete[field="$ctrl.address.agencyModeFk"]',
phoneInput: `${components.vnTextfield}[name="phone"]`,
diff --git a/e2e/paths/02-client-module/01_create_client.spec.js b/e2e/paths/02-client-module/01_create_client.spec.js
index 2d7b58b20..b9ea5e112 100644
--- a/e2e/paths/02-client-module/01_create_client.spec.js
+++ b/e2e/paths/02-client-module/01_create_client.spec.js
@@ -53,7 +53,7 @@ describe('Client create path', () => {
.write(selectors.createClientView.name, 'Carol Danvers')
.write(selectors.createClientView.socialName, 'AVG tax')
.write(selectors.createClientView.street, 'Many places')
- .write(selectors.createClientView.city, 'Silla')
+ .autocompleteSearch(selectors.createClientView.postcode, '46000')
.clearInput(selectors.createClientView.email)
.write(selectors.createClientView.email, 'incorrect email format')
.waitToClick(selectors.createClientView.createButton)
@@ -62,6 +62,21 @@ describe('Client create path', () => {
expect(result).toEqual('Some fields are invalid');
});
+ it(`should check for autocompleted city, province and country`, async() => {
+ const clientCity = await nightmare
+ .waitToGetProperty(`${selectors.createClientView.city} input`, 'value');
+
+ const clientProvince = await nightmare
+ .waitToGetProperty(`${selectors.createClientView.province} input`, 'value');
+
+ const clientCountry = await nightmare
+ .waitToGetProperty(`${selectors.createClientView.country} input`, 'value');
+
+ expect(clientCity).toEqual('Valencia');
+ expect(clientProvince).toEqual('Province one');
+ expect(clientCountry).toEqual('España');
+ });
+
it(`should create a new user with all correct data`, async() => {
const result = await nightmare
.clearInput(selectors.createClientView.email)
diff --git a/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js b/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js
index d424f0591..cd005cae0 100644
--- a/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js
+++ b/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js
@@ -67,11 +67,7 @@ describe('Client Edit fiscalData path', () => {
.write(selectors.clientFiscalData.fiscalIdInput, 'INVALID!')
.clearInput(selectors.clientFiscalData.addressInput)
.write(selectors.clientFiscalData.addressInput, 'Somewhere edited')
- .clearInput(selectors.clientFiscalData.postcodeInput)
- .write(selectors.clientFiscalData.postcodeInput, '12345')
- .clearInput(selectors.clientFiscalData.cityInput)
- .write(selectors.clientFiscalData.cityInput, 'N/A')
- .autocompleteSearch(selectors.clientFiscalData.provinceAutocomplete, 'Province two')
+ .autocompleteSearch(selectors.clientFiscalData.postcodeAutocomplete, '46000')
.waitToClick(selectors.clientFiscalData.activeCheckbox)
.waitToClick(selectors.clientFiscalData.frozenCheckbox)
.waitToClick(selectors.clientFiscalData.hasToInvoiceCheckbox)
@@ -197,23 +193,31 @@ describe('Client Edit fiscalData path', () => {
it('should confirm the postcode have been edited', async() => {
const result = await nightmare
- .waitToGetProperty(selectors.clientFiscalData.postcodeInput, 'value');
+ .waitToGetProperty(`${selectors.clientFiscalData.postcodeAutocomplete} input`, 'value');
- expect(result).toEqual('12345');
+ expect(result).toContain('46000');
});
- it('should confirm the city have been edited', async() => {
+ it('should confirm the city have been autocompleted', async() => {
const result = await nightmare
- .waitToGetProperty(selectors.clientFiscalData.cityInput, 'value');
+ .waitToGetProperty(`${selectors.clientFiscalData.cityAutocomplete} input`, 'value');
- expect(result).toEqual('N/A');
+ expect(result).toEqual('Valencia');
});
- it(`should confirm the province have been selected`, async() => {
+
+ it(`should confirm the province have been autocompleted`, async() => {
const result = await nightmare
.waitToGetProperty(`${selectors.clientFiscalData.provinceAutocomplete} input`, 'value');
- expect(result).toEqual('Province two');
+ expect(result).toEqual('Province one');
+ });
+
+ it('should confirm the country have been autocompleted', async() => {
+ const result = await nightmare
+ .waitToGetProperty(`${selectors.clientFiscalData.countryAutocomplete} input`, 'value');
+
+ expect(result).toEqual('España');
});
it('should confirm active checkbox is unchecked', async() => {
diff --git a/e2e/paths/02-client-module/05_add_address.spec.js b/e2e/paths/02-client-module/05_add_address.spec.js
index e082b6d8c..5e21f87d8 100644
--- a/e2e/paths/02-client-module/05_add_address.spec.js
+++ b/e2e/paths/02-client-module/05_add_address.spec.js
@@ -24,8 +24,7 @@ describe('Client Add address path', () => {
const result = await nightmare
.waitToClick(selectors.clientAddresses.defaultCheckboxInput)
.clearInput(selectors.clientAddresses.streetAddressInput)
- .write(selectors.clientAddresses.postcodeInput, '10022')
- .autocompleteSearch(selectors.clientAddresses.provinceAutocomplete, 'Province four')
+ .autocompleteSearch(selectors.clientAddresses.postcodeAutocomplete, '46000')
.autocompleteSearch(selectors.clientAddresses.agencyAutocomplete, 'Entanglement')
.write(selectors.clientAddresses.phoneInput, '999887744')
.write(selectors.clientAddresses.mobileInput, '999887744')
@@ -35,11 +34,32 @@ describe('Client Add address path', () => {
expect(result).toEqual('Some fields are invalid');
});
+ it('should confirm the postcode have been edited', async() => {
+ const result = await nightmare
+ .waitToGetProperty(`${selectors.clientAddresses.postcodeAutocomplete} input`, 'value');
+
+ expect(result).toContain('46000');
+ });
+
+ it('should confirm the city have been autocompleted', async() => {
+ const result = await nightmare
+ .waitToGetProperty(`${selectors.clientAddresses.cityAutocomplete} input`, 'value');
+
+ expect(result).toEqual('Valencia');
+ });
+
+
+ it(`should confirm the province have been autocompleted`, async() => {
+ const result = await nightmare
+ .waitToGetProperty(`${selectors.clientAddresses.provinceAutocomplete} input`, 'value');
+
+ expect(result).toEqual('Province one');
+ });
+
it(`should create a new address with all it's data`, async() => {
const result = await nightmare
.write(selectors.clientAddresses.consigneeInput, 'Bruce Bunner')
.write(selectors.clientAddresses.streetAddressInput, '320 Park Avenue New York')
- .write(selectors.clientAddresses.cityInput, 'New York')
.waitToClick(selectors.clientAddresses.saveButton)
.waitForLastSnackbar();
diff --git a/front/core/components/autocomplete/autocomplete.html b/front/core/components/autocomplete/autocomplete.html
index 2cd9a244a..ecb21fe2f 100755
--- a/front/core/components/autocomplete/autocomplete.html
+++ b/front/core/components/autocomplete/autocomplete.html
@@ -19,6 +19,6 @@