Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 1878-print_with_auth

This commit is contained in:
Joan Sanchez 2020-03-05 10:08:21 +01:00
commit bc422e7f38
25 changed files with 674 additions and 338 deletions

View File

@ -1,46 +1,53 @@
{ {
"name": "Province", "name": "Province",
"description": "Provinces of every country", "description": "Provinces of every country",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "province" "table": "province"
} }
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
}, },
"name": { "properties": {
"type": "string", "id": {
"required": true "type": "Number",
} "id": true,
}, "description": "Identifier"
"relations": { },
"country": { "name": {
"type": "belongsTo", "type": "string",
"model": "Country", "required": true
"foreignKey": "countryFk" }
}, },
"warehouse": { "relations": {
"type": "belongsTo", "country": {
"model": "Warehouse", "type": "belongsTo",
"foreignKey": "warehouseFk" "model": "Country",
"foreignKey": "countryFk"
},
"warehouse": {
"type": "belongsTo",
"model": "Warehouse",
"foreignKey": "warehouseFk"
},
"zone": {
"type": "belongsTo",
"model": "Zone",
"foreignKey": "zoneFk"
}
}, },
"zone": { "scopes": {
"type": "belongsTo", "location": {
"model": "Zone", "include": {
"foreignKey": "zoneFk" "relation": "country"
} }
}, }
"acls": [ },
{ "acls": [
"accessType": "READ", {
"principalType": "ROLE", "accessType": "READ",
"principalId": "$everyone", "principalType": "ROLE",
"permission": "ALLOW" "principalId": "$everyone",
} "permission": "ALLOW"
] }
]
} }

View File

@ -197,14 +197,16 @@ INSERT INTO `vn`.`town`(`id`, `name`, `provinceFk`)
(1, 'Valencia', 1), (1, 'Valencia', 1),
(2, 'Silla', 1), (2, 'Silla', 1),
(3, 'Algemesi', 1), (3, 'Algemesi', 1),
(4, 'Alzira', 1); (4, 'Alzira', 1),
(5, 'Quito', 5);
INSERT INTO `vn`.`postCode`(`code`, `townFk`, `geoFk`) INSERT INTO `vn`.`postCode`(`code`, `townFk`, `geoFk`)
VALUES VALUES
('46000', 1, 6), ('46000', 1, 6),
('46460', 2, 6), ('46460', 2, 6),
('46680', 3, 6), ('46680', 3, 6),
('46600', 4, 7); ('46600', 4, 7),
('EC170150', 5, 8);
INSERT INTO `vn`.`clientType`(`id`, `code`, `type`) INSERT INTO `vn`.`clientType`(`id`, `code`, `type`)
VALUES VALUES

View File

@ -44,8 +44,8 @@ export default {
taxNumber: 'vn-client-create vn-textfield[ng-model="$ctrl.client.fi"]', taxNumber: 'vn-client-create vn-textfield[ng-model="$ctrl.client.fi"]',
socialName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.socialName"]', socialName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.socialName"]',
street: 'vn-client-create vn-textfield[ng-model="$ctrl.client.street"]', street: 'vn-client-create vn-textfield[ng-model="$ctrl.client.street"]',
postcode: 'vn-client-create vn-textfield[ng-model="$ctrl.client.postcode"]', postcode: 'vn-client-create vn-datalist[ng-model="$ctrl.client.postcode"]',
city: 'vn-client-create vn-textfield[ng-model="$ctrl.client.city"]', city: 'vn-client-create vn-datalist[ng-model="$ctrl.client.city"]',
province: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.provinceFk"]', province: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.provinceFk"]',
country: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.countryFk"]', country: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.countryFk"]',
userName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.userName"]', userName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.userName"]',
@ -76,8 +76,8 @@ export default {
equalizationTaxCheckbox: 'vn-client-fiscal-data vn-check[ng-model="$ctrl.client.isEqualizated"]', equalizationTaxCheckbox: 'vn-client-fiscal-data vn-check[ng-model="$ctrl.client.isEqualizated"]',
acceptPropagationButton: '.vn-confirm.shown button[response=accept]', acceptPropagationButton: '.vn-confirm.shown button[response=accept]',
address: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.street"]', address: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.street"]',
postcode: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.postcode"]', postcode: 'vn-client-fiscal-data vn-datalist[ng-model="$ctrl.client.postcode"]',
city: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.city"]', city: 'vn-client-fiscal-data vn-datalist[ng-model="$ctrl.client.city"]',
province: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.provinceFk"]', province: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.provinceFk"]',
country: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.countryFk"]', country: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.countryFk"]',
activeCheckbox: 'vn-client-fiscal-data vn-check[label="Active"]', activeCheckbox: 'vn-client-fiscal-data vn-check[label="Active"]',
@ -114,8 +114,8 @@ export default {
defaultCheckbox: 'vn-check[label="Default"]', defaultCheckbox: 'vn-check[label="Default"]',
consignee: 'vn-textfield[ng-model="$ctrl.address.nickname"]', consignee: 'vn-textfield[ng-model="$ctrl.address.nickname"]',
streetAddress: 'vn-textfield[ng-model="$ctrl.address.street"]', streetAddress: 'vn-textfield[ng-model="$ctrl.address.street"]',
postcode: 'vn-textfield[ng-model="$ctrl.address.postalCode"]', postcode: 'vn-datalist[ng-model="$ctrl.address.postalCode"]',
city: 'vn-textfield[ng-model="$ctrl.address.city"]', city: 'vn-datalist[ng-model="$ctrl.address.city"]',
province: 'vn-autocomplete[ng-model="$ctrl.address.provinceId"]', province: 'vn-autocomplete[ng-model="$ctrl.address.provinceId"]',
agency: 'vn-autocomplete[ng-model="$ctrl.address.agencyModeId"]', agency: 'vn-autocomplete[ng-model="$ctrl.address.agencyModeId"]',
phone: 'vn-textfield[ng-model="$ctrl.address.phone"]', phone: 'vn-textfield[ng-model="$ctrl.address.phone"]',

View File

@ -87,7 +87,7 @@ describe('Client create path', async() => {
.waitToGetProperty(selectors.createClientView.country, 'value'); .waitToGetProperty(selectors.createClientView.country, 'value');
expect(clientCity).toEqual('Valencia'); expect(clientCity).toEqual('Valencia');
expect(clientProvince).toEqual('Province one'); expect(clientProvince).toContain('Province one');
expect(clientCountry).toEqual('España'); expect(clientCountry).toEqual('España');
}); });

View File

@ -198,11 +198,10 @@ describe('Client Edit fiscalData path', () => {
expect(result).toEqual('Valencia'); expect(result).toEqual('Valencia');
}); });
it(`should confirm the province have been autocompleted`, async() => { it(`should confirm the province have been autocompleted`, async() => {
const result = await page.waitToGetProperty(selectors.clientFiscalData.province, 'value'); 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() => { it('should confirm the country have been autocompleted', async() => {

View File

@ -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() => { 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.waitToClick(selectors.clientAddresses.defaultCheckbox);
await page.autocompleteSearch(selectors.clientAddresses.province, 'Province five'); await page.write(selectors.clientAddresses.postcode, 'EC170150');
await page.write(selectors.clientAddresses.city, 'Valencia');
await page.write(selectors.clientAddresses.postcode, '46000');
await page.autocompleteSearch(selectors.clientAddresses.agency, 'Entanglement'); await page.autocompleteSearch(selectors.clientAddresses.agency, 'Entanglement');
await page.write(selectors.clientAddresses.phone, '999887744'); await page.write(selectors.clientAddresses.phone, '999887744');
await page.write(selectors.clientAddresses.mobileInput, '999887744'); await page.write(selectors.clientAddresses.mobileInput, '999887744');
@ -37,6 +35,16 @@ describe('Client Add address path', () => {
expect(result).toEqual('Some fields are invalid'); 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() => { 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'); await page.write(selectors.clientAddresses.consignee, 'Bruce Bunner');

View File

@ -27,7 +27,7 @@ export default class Datalist extends Textfield {
value = value == '' || value == null ? null : value; value = value == '' || value == null ? null : value;
oldValue = oldValue == '' || oldValue == null ? null : oldValue; oldValue = oldValue == '' || oldValue == null ? null : oldValue;
this.refreshSelection(); if (oldValue === undefined) this.refreshSelection();
if (!value || value === oldValue && this.modelData != null) return; if (!value || value === oldValue && this.modelData != null) return;
@ -52,7 +52,14 @@ export default class Datalist extends Textfield {
validSelection(selection) { validSelection(selection) {
return this.modelData && this.modelData.find(item => { 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;
}); });
} }

View File

@ -64,5 +64,6 @@
"Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})", "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", "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", "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"
} }

View File

@ -39,61 +39,53 @@
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete <vn-datalist vn-one
vn-one
vn-id="province"
ng-model="$ctrl.address.provinceId"
url="Provinces"
show-field="name"
value-field="id"
label="Province">
</vn-autocomplete>
<vn-textfield
vn-one
label="City"
ng-model="$ctrl.address.city"
rule>
</vn-textfield>
<!-- <vn-autocomplete vn-id="town" vn-one
label="City"
url="Towns"
fields="['id', 'name']"
where="{provinceFk: province.selection.id}"
show-field="name"
value-field="name"
ng-model="$ctrl.address.city">
</vn-autocomplete>
<vn-autocomplete vn-one
url="Postcodes/location"
fields="['code', 'townFk']"
ng-model="$ctrl.address.postalCode"
selection="$ctrl.postcodeSelection"
search-function="{code: $search}"
where="{townFk: town.selection.id}"
order="code, townFk"
show-field="code"
value-field="code"
label="Postcode">
<tpl-item>
{{code}}, {{town.name}} - {{town.province.name}}
({{town.province.country.country}})
</tpl-item>
</vn-autocomplete> -->
<vn-textfield
vn-one
label="Postcode" label="Postcode"
ng-model="$ctrl.address.postalCode" ng-model="$ctrl.address.postalCode"
selection="$ctrl.postcode"
url="Postcodes/location"
fields="['code','townFk']"
order="code, townFk"
value-field="code"
show-field="code"
rule> rule>
</vn-textfield> <tpl-item>
<!-- {{code}} - {{town.name}} ({{town.province.name}},
<vn-icon-button {{town.province.country.country}})
vn-auto </tpl-item>
class="vn-my-md" <append>
icon="add_circle" <vn-icon-button
vn-tooltip="New postcode" icon="add_circle"
ng-click="postcode.open()"> vn-tooltip="New postcode"
</vn-icon-button> ng-click="postcode.open()"
--> vn-acl="deliveryBoss"
vn-acl-action="remove">
</vn-icon-button>
</append>
</vn-datalist>
<vn-datalist vn-id="town" vn-one
label="City"
ng-model="$ctrl.address.city"
selection="$ctrl.town"
url="Towns/location"
fields="['id', 'name', 'provinceFk']"
show-field="name"
value-field="name">
<tpl-item>
{{name}}, {{province.name}}
({{province.country.country}})
</tpl-item>
</vn-datalist>
<vn-autocomplete vn-id="province" vn-one
label="Province"
ng-model="$ctrl.address.provinceId"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
show-field="name"
value-field="id"
rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete <vn-autocomplete

View File

@ -11,26 +11,6 @@ export default class Controller extends Component {
}; };
} }
get postcodeSelection() {
return this._postcodeSelection;
}
set postcodeSelection(selection) {
this._postcodeSelection = selection;
if (!selection) 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;
}
onSubmit() { onSubmit() {
this.$.watcher.submit().then(res => { this.$.watcher.submit().then(res => {
if (this.address.isDefaultAddress) if (this.address.isDefaultAddress)
@ -51,6 +31,46 @@ export default class Controller extends Component {
return this.$http.post(`CustomsAgents`, this.newCustomsAgent) return this.$http.post(`CustomsAgents`, this.newCustomsAgent)
.then(res => this.address.customsAgentFk = res.data.id); .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']; Controller.$inject = ['$element', '$scope'];

View File

@ -53,9 +53,48 @@ describe('Client', () => {
}); });
}); });
describe('postcodeSelection() setter', () => { describe('town() setter', () => {
it(`should set the town, province and contry properties`, () => { it(`should set provinceId property`, () => {
controller.postcodeSelection = { 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, townFk: 1,
code: 46001, code: 46001,
town: { town: {
@ -73,7 +112,7 @@ describe('Client', () => {
}; };
expect(controller.address.city).toEqual('New York'); expect(controller.address.city).toEqual('New York');
expect(controller.address.provinceFk).toEqual(1); expect(controller.address.provinceId).toEqual(1);
}); });
}); });

View File

@ -56,58 +56,53 @@
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete <vn-datalist vn-one
vn-one
vn-id="province"
ng-model="$ctrl.address.provinceFk"
url="Provinces"
show-field="name"
value-field="id"
label="Province">
</vn-autocomplete>
<vn-textfield
vn-one
label="City"
ng-model="$ctrl.address.city"
rule>
</vn-textfield>
<!--
<vn-autocomplete vn-id="town" vn-one
label="City"
url="Towns"
fields="['id', 'name']"
where="{provinceFk: province.selection.id}"
show-field="name"
value-field="name"
ng-model="$ctrl.address.city">
</vn-autocomplete>
<vn-autocomplete vn-one
url="Postcodes/location"
fields="['code', 'townFk']"
ng-model="$ctrl.address.postalCode"
where="{townFk: town.selection.id}"
search-function="{code: $search}"
order="code, townFk"
show-field="code"
value-field="code"
label="Postcode">
</vn-autocomplete>
-->
<vn-textfield
vn-one
label="Postcode" label="Postcode"
ng-model="$ctrl.address.postalCode" ng-model="$ctrl.address.postalCode"
selection="$ctrl.postcode"
url="Postcodes/location"
fields="['code','townFk']"
order="code, townFk"
value-field="code"
show-field="code"
rule> rule>
</vn-textfield> <tpl-item>
{{code}} - {{town.name}} ({{town.province.name}},
<!-- <vn-icon-button {{town.province.country.country}})
vn-auto </tpl-item>
class="vn-my-md" <append>
icon="add_circle" <vn-icon-button
vn-tooltip="New postcode" icon="add_circle"
ng-click="postcode.open()"> vn-tooltip="New postcode"
</vn-icon-button> ng-click="postcode.open()"
--> vn-acl="deliveryBoss"
vn-acl-action="remove">
</vn-icon-button>
</append>
</vn-datalist>
<vn-datalist vn-id="town" vn-one
label="City"
ng-model="$ctrl.address.city"
selection="$ctrl.town"
url="Towns/location"
fields="['id', 'name', 'provinceFk']"
show-field="name"
value-field="name">
<tpl-item>
{{name}}, {{province.name}}
({{province.country.country}})
</tpl-item>
</vn-datalist>
<vn-autocomplete vn-id="province" vn-one
label="Province"
ng-model="$ctrl.address.provinceFk"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
show-field="name"
value-field="id"
rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete vn-one <vn-autocomplete vn-one

View File

@ -15,10 +15,6 @@ export default class Controller extends Component {
this.$state.go('client.card.address.index'); this.$state.go('client.card.address.index');
} }
onResponse(response) {
this.address.postalCode = response.code;
}
onSubmit() { onSubmit() {
this.$.watcher.submit() this.$.watcher.submit()
.then(() => this.$.model.save(true)) .then(() => this.$.model.save(true))
@ -39,6 +35,48 @@ export default class Controller extends Component {
return this.$http.post(`CustomsAgents`, this.newCustomsAgent) return this.$http.post(`CustomsAgents`, this.newCustomsAgent)
.then(res => this.address.customsAgentFk = res.data.id); .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 (!oldValue) 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 (!oldValue) 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', { ngModule.component('vnClientAddressEdit', {

View File

@ -49,76 +49,63 @@
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete <vn-datalist vn-one
vn-id="country" label="Postcode"
vn-one ng-model="$ctrl.client.postcode"
selection="$ctrl.postcode"
url="Postcodes/location"
fields="['code','townFk']"
order="code, townFk"
value-field="code"
show-field="code"
rule>
<tpl-item>
{{code}} - {{town.name}} ({{town.province.name}},
{{town.province.country.country}})
</tpl-item>
<append>
<vn-icon-button
icon="add_circle"
vn-tooltip="New postcode"
ng-click="postcode.open()"
vn-acl="deliveryBoss"
vn-acl-action="remove">
</vn-icon-button>
</append>
</vn-datalist>
<vn-datalist vn-id="town" vn-one
label="City"
ng-model="$ctrl.client.city"
selection="$ctrl.town"
url="Towns/location"
fields="['id', 'name', 'provinceFk']"
show-field="name"
value-field="name">
<tpl-item>
{{name}}, {{province.name}}
({{province.country.country}})
</tpl-item>
</vn-datalist>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-id="province" vn-one
label="Province"
ng-model="$ctrl.client.provinceFk"
selection="$ctrl.province"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
show-field="name"
value-field="id"
rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete>
<vn-autocomplete vn-id="country" vn-one
ng-model="$ctrl.client.countryFk" ng-model="$ctrl.client.countryFk"
url="Countries" url="Countries"
show-field="country" show-field="country"
value-field="id" value-field="id"
label="Country"> label="Country">
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete
vn-id="province"
vn-one
url="Provinces"
ng-model="$ctrl.client.provinceFk"
where="{countryFk: country.selection.id}"
show-field="name"
value-field="id"
label="Province">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
label="City"
ng-model="$ctrl.client.city"
rule>
</vn-textfield>
<!--
<vn-autocomplete vn-id="town" vn-one
label="City"
url="Towns"
fields="['id', 'name']"
where="{provinceFk: province.selection.id}"
show-field="name"
value-field="name"
ng-model="$ctrl.client.city">
</vn-autocomplete>
<vn-icon-button
vn-auto
class="vn-my-md"
icon="add_circle"
vn-tooltip="New postcode"
ng-click="postcode.open()">
</vn-icon-button>
-->
<vn-textfield
vn-one
label="Postcode"
ng-model="$ctrl.client.postcode"
rule>
</vn-textfield>
<!--
<vn-autocomplete
vn-one
url="Postcodes/location"
fields="['code', 'townFk']"
ng-model="$ctrl.client.postcode"
selection="$ctrl.postcodeSelection"
search-function="{code: $search}"
where="{townFk: town.selection.id}"
order="code, townFk"
show-field="code"
value-field="code"
label="Postcode">
<tpl-item>
{{code}}, {{town.name}} - {{town.province.name}}
({{town.province.country.country}})
</tpl-item>
</vn-autocomplete>
-->
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield <vn-textfield

View File

@ -12,12 +12,55 @@ export default class Controller {
}; };
} }
get postcodeSelection() { onSubmit() {
return this._postcodeSelection; return this.$.watcher.submit().then(
json => this.$state.go('client.card.basicData', {id: json.data.id})
);
} }
set postcodeSelection(selection) { get province() {
this._postcodeSelection = selection; 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; if (!selection) return;
@ -33,13 +76,8 @@ export default class Controller {
onResponse(response) { onResponse(response) {
this.client.postcode = response.code; 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']; Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp'];
ngModule.component('vnClientCreate', { ngModule.component('vnClientCreate', {

View File

@ -40,9 +40,63 @@ describe('Client', () => {
}); });
}); });
describe('postcodeSelection() setter', () => { describe('province() setter', () => {
it(`should set the town, province and contry properties`, () => { it(`should set countryFk property`, () => {
controller.postcodeSelection = { 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, townFk: 1,
code: 46001, code: 46001,
town: { town: {

View File

@ -33,9 +33,57 @@
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete <vn-datalist vn-one
vn-one label="Postcode"
vn-id="country" ng-model="$ctrl.client.postcode"
selection="$ctrl.postcode"
url="Postcodes/location"
fields="['code','townFk']"
order="code, townFk"
value-field="code"
show-field="code"
rule>
<tpl-item>
{{code}} - {{town.name}} ({{town.province.name}},
{{town.province.country.country}})
</tpl-item>
<append>
<vn-icon-button
icon="add_circle"
vn-tooltip="New postcode"
ng-click="postcode.open()"
vn-acl="deliveryBoss"
vn-acl-action="remove">
</vn-icon-button>
</append>
</vn-datalist>
<vn-datalist vn-id="town" vn-one
label="City"
ng-model="$ctrl.client.city"
selection="$ctrl.town"
url="Towns/location"
fields="['id', 'name', 'provinceFk']"
show-field="name"
value-field="name">
<tpl-item>
{{name}}, {{province.name}}
({{province.country.country}})
</tpl-item>
</vn-datalist>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-id="province" vn-one
label="Province"
ng-model="$ctrl.client.provinceFk"
selection="$ctrl.province"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
show-field="name"
value-field="id"
rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete>
<vn-autocomplete vn-id="country" vn-one
ng-model="$ctrl.client.countryFk" ng-model="$ctrl.client.countryFk"
url="Countries" url="Countries"
show-field="country" show-field="country"
@ -43,51 +91,6 @@
label="Country" label="Country"
rule> rule>
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete
vn-one
vn-id="province"
ng-model="$ctrl.client.provinceFk"
url="Provinces"
where="{countryFk: country.selection.id}"
show-field="name"
value-field="id"
label="Province"
rule>
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
label="City"
ng-model="$ctrl.client.city"
rule>
</vn-textfield>
<vn-textfield
vn-one
label="Postcode"
ng-model="$ctrl.client.postcode"
rule>
</vn-textfield>
<!-- <vn-autocomplete vn-id="town" vn-one
label="City"
url="Towns"
fields="['id', 'name']"
where="{provinceFk: province.selection.id}"
show-field="name"
value-field="name"
ng-model="$ctrl.client.city">
</vn-autocomplete>
<vn-autocomplete vn-id="postcode" vn-one
url="Postcodes/location"
fields="['code', 'townFk']"
ng-model="$ctrl.client.postcode"
search-function="{code: $search}"
where="{townFk: town.selection.id}"
order="code, townFk"
show-field="code"
value-field="code"
label="Postcode">
</vn-autocomplete> -->
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-check <vn-check
@ -157,3 +160,8 @@
message="Found a client with this data" message="Found a client with this data"
on-accept="$ctrl.onAcceptDuplication()"> on-accept="$ctrl.onAcceptDuplication()">
</vn-confirm> </vn-confirm>
<!-- New postcode dialog -->
<vn-client-postcode
vn-id="postcode"
on-response="$ctrl.onResponse($response)">
</vn-client-postcode>

View File

@ -7,8 +7,8 @@ export default class Controller extends Component {
delete this.client.despiteOfClient; delete this.client.despiteOfClient;
const hasContactData = this.client.email || this.client.phone || this.client.mobile; const hasContactData = this.client.email || this.client.phone || this.client.mobile;
const isDataChecked = !orgData.isTaxDataChecked && this.client.isTaxDataChecked; const hasChangedTaxData = !orgData.isTaxDataChecked && this.client.isTaxDataChecked;
if (isDataChecked && hasContactData) if (hasChangedTaxData && hasContactData)
this.checkExistingClient(); this.checkExistingClient();
else this.save(); else this.save();
} }
@ -90,6 +90,68 @@ export default class Controller extends Component {
this.$.$apply(); this.$.$apply();
} }
get province() {
return this._province;
}
// Province auto complete
set province(selection) {
const oldValue = this._province;
this._province = selection;
if (!selection || !oldValue) return;
const country = selection.country;
this.client.countryFk = country.id;
}
get town() {
return this._town;
}
// Town auto complete
set town(selection) {
const oldValue = this._town;
this._town = selection;
if (!selection || !oldValue) 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) {
const oldValue = this._postcode;
this._postcode = selection;
if (!selection || !oldValue) return;
const town = selection.town;
const province = town.province;
const country = province.country;
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', { ngModule.component('vnClientFiscalData', {

View File

@ -25,6 +25,10 @@ describe('Client', () => {
isEqualizated: false, isEqualizated: false,
isTaxDataChecked: false isTaxDataChecked: false
}; };
controller.province = {};
controller.town = {};
controller.postcode = {};
})); }));
describe('onSubmit()', () => { describe('onSubmit()', () => {
@ -129,5 +133,84 @@ describe('Client', () => {
$httpBackend.flush(); $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);
});
});
}); });
}); });

View File

@ -1,7 +1,7 @@
<vn-dialog class="edit" <vn-dialog class="edit"
vn-id="postcodeDialog" vn-id="postcodeDialog"
on-open="$ctrl.onOpen()" on-open="$ctrl.onOpen()"
on-response="$ctrl.onResponse($response)"> on-accept="$ctrl.onAccept()">
<tpl-body> <tpl-body>
<h5 class="vn-py-sm" translate>New postcode</h5> <h5 class="vn-py-sm" translate>New postcode</h5>
<p translate>Please, ensure you put the correct data!</p> <p translate>Please, ensure you put the correct data!</p>

View File

@ -35,25 +35,20 @@ class Controller extends Component {
this.$.postcode.focus(); this.$.postcode.focus();
} }
onResponse(response) { onAccept() {
if (response == 'accept') { try {
try { if (!this.data.code)
if (!this.data.code) throw new Error(`The postcode can't be empty`);
throw new Error(`The postcode can't be empty`); if (!this.data.townFk)
if (!this.data.townFk) throw new Error(`The town can't be empty`);
throw new Error(`The town can't be empty`);
this.$http.patch(`postcodes`, this.data).then(response => { this.$http.patch(`postcodes`, this.data).then(res => {
if (response.data) { this.vnApp.showMessage(this.$translate.instant('The postcode has been saved'));
this.vnApp.showMessage(this.$translate.instant('The postcode has been saved')); this.emit('response', {$response: res.data});
});
this.emit('response', {response: response.data}); } catch (e) {
} this.vnApp.showError(this.$translate.instant(e.message));
}); return false;
} catch (e) {
this.vnApp.showError(this.$translate.instant(e.message));
return false;
}
} }
return true; return true;
} }

View File

@ -15,7 +15,7 @@ describe('Client', () => {
controller.client = {id: 101}; controller.client = {id: 101};
})); }));
describe('onResponse()', () => { describe('onAccept()', () => {
it('should perform a POST query and show a success snackbar', () => { it('should perform a POST query and show a success snackbar', () => {
let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'}; let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
controller.data = {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.when('PATCH', `postcodes`, params).respond(200, params);
$httpBackend.expect('PATCH', `postcodes`, params).respond(params); $httpBackend.expect('PATCH', `postcodes`, params).respond(params);
controller.onResponse('accept'); controller.onAccept();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been saved'); expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been saved');

View File

@ -3,6 +3,7 @@ const app = require('vn-loopback/server/server');
describe('ticket makeInvoice()', () => { describe('ticket makeInvoice()', () => {
let invoice; let invoice;
let ticketId = 11; let ticketId = 11;
const okState = 3;
afterAll(async done => { afterAll(async done => {
let ticket = await app.models.Ticket.findById(11); let ticket = await app.models.Ticket.findById(11);
@ -11,7 +12,7 @@ describe('ticket makeInvoice()', () => {
let ticketTrackings = await app.models.TicketTracking.find({ let ticketTrackings = await app.models.TicketTracking.find({
where: { where: {
ticketFk: ticketId, ticketFk: ticketId,
stateFk: {neq: 3} stateFk: {neq: okState}
}, },
order: 'id DESC' order: 'id DESC'
}); });

View File

@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('createThermograph', { Self.remoteMethodCtx('createThermograph', {
description: 'Upload and attach a document', description: 'Creates a new travel thermograph',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
arg: 'id', arg: 'id',

View File

@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('updateThermograph', { Self.remoteMethodCtx('updateThermograph', {
description: 'updates a file properties or file', description: 'Updates a travel thermograph',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
arg: 'id', arg: 'id',