Tarea #808 order.basic-data cr juan

This commit is contained in:
Javi Gallego 2019-02-06 14:56:36 +01:00
parent ffea839250
commit 6e421d8442
10 changed files with 122 additions and 32 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "salix-front", "name": "salix-front",
"version": "1.0.0", "version": "1.0.0",
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "Salix frontend", "description": "Salix frontend",
"license": "GPL-3.0", "license": "GPL-3.0",
"repository": { "repository": {

View File

@ -31,5 +31,6 @@
"Worker cannot be blank": "Worker cannot be blank", "Worker cannot be blank": "Worker cannot be blank",
"You must delete the claim id %d first": "You must delete the claim id %d first", "You must delete the claim id %d first": "You must delete the claim id %d first",
"You don't have enough privileges": "You don't have enough privileges", "You don't have enough privileges": "You don't have enough privileges",
"Tag value cannot be blank": "Tag value cannot be blank" "Tag value cannot be blank": "Tag value cannot be blank",
"You don't have enough privileges to do that": "You don't have enough privileges to do that"
} }

View File

@ -66,5 +66,6 @@
"You can't create a ticket for a frozen client": "No puedes crear un ticket para un cliente congelado", "You can't create a ticket for a frozen client": "No puedes crear un ticket para un cliente congelado",
"You can't create a ticket for a inactive client": "No puedes crear un ticket para un cliente inactivo", "You can't create a ticket for a inactive client": "No puedes crear un ticket para un cliente inactivo",
"Tag value cannot be blank": "El valor del tag no puede quedar en blanco", "Tag value cannot be blank": "El valor del tag no puede quedar en blanco",
"ORDER_EMPTY": "Cesta vacía" "ORDER_EMPTY": "Cesta vacía",
"You don't have enough privileges to do that": "No tienes permisos para cambiar esto"
} }

View File

@ -168,6 +168,11 @@
"model": "CreditClassification", "model": "CreditClassification",
"foreignKey": "client" "foreignKey": "client"
}, },
"defaultAddress": {
"type": "belongsTo",
"model": "Address",
"foreignKey": "defaultAddressFk"
},
"contacts": { "contacts": {
"type": "hasMany", "type": "hasMany",
"model": "ClientContact", "model": "ClientContact",
@ -178,20 +183,20 @@
"model": "BankEntity", "model": "BankEntity",
"foreignKey": "bankEntityFk" "foreignKey": "bankEntityFk"
}, },
"defaulters": { "defaulters": {
"type": "hasMany", "type": "hasMany",
"model": "Defaulter", "model": "Defaulter",
"foreignKey": "clientFk" "foreignKey": "clientFk"
}, },
"clientRisks": { "clientRisks": {
"type": "hasMany", "type": "hasMany",
"model": "ClientRisk", "model": "ClientRisk",
"foreignKey": "clientFk" "foreignKey": "clientFk"
}, },
"claimsRatio": { "claimsRatio": {
"type": "hasMany", "type": "hasMany",
"model": "ClaimRatio", "model": "ClaimRatio",
"foreignKey": "clientFk" "foreignKey": "clientFk"
} }
} }
} }

View File

@ -37,8 +37,9 @@ module.exports = Self => {
let validUpdateParams = [ let validUpdateParams = [
'clientFk', 'clientFk',
'companyFk', 'address_id',
'landed', 'landed',
'agency_id',
'note', 'note',
]; ];

View File

@ -14,6 +14,7 @@
}, },
"landed": { "landed": {
"type": "date", "type": "date",
"required": true,
"mysql": { "mysql": {
"columnName": "date_send" "columnName": "date_send"
} }
@ -27,6 +28,7 @@
}, },
"companyFk": { "companyFk": {
"type": "Number", "type": "Number",
"required": true,
"mysql": { "mysql": {
"columnName": "company_id" "columnName": "company_id"
} }
@ -73,6 +75,7 @@
}, },
"address": { "address": {
"type": "belongsTo", "type": "belongsTo",
"required": true,
"model": "Address", "model": "Address",
"foreignKey": "address_id" "foreignKey": "address_id"
}, },

View File

@ -1,4 +1,11 @@
<mg-ajax path="/order/api/Orders/{{patch.params.id}}/updateBasicData" options="vnPatch"></mg-ajax> <mg-ajax path="/order/api/Orders/{{patch.params.id}}/updateBasicData" options="vnPatch"></mg-ajax>
<vn-crud-model
vn-id="address-model"
url="/api/Addresses"
data="address"
order="nickname"
autoload = "false">
</vn-crud-model>
<vn-watcher <vn-watcher
vn-id="watcher" vn-id="watcher"
data="$ctrl.order" data="$ctrl.order"
@ -12,27 +19,42 @@
vn-one vn-one
url="/api/Clients" url="/api/Clients"
label="Client" label="Client"
search-function="{or: [{id: $search}, {name: {regexp: $search}}]}" search-function="{or: [{id: $search}, {name: {like: '%'+$search+'%'}}]}"
show-field="name" show-field="name"
value-field="id" value-field="id"
field="$ctrl.order.clientFk" field="$ctrl.order.clientFk"
order="id"> selection="$ctrl.selection"
<tpl-item>{{id}}: {{name}}</tpl-item> fields="['defaultAddressFk']">
<tpl-item>{{::id}}: {{::name}}</tpl-item>
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete <vn-autocomplete
vn-one vn-one
url="/api/Companies" data="address"
label="Company" label="Address"
show-field="code" search-function="{or: [{id: $search}, {nickname: {like: '%'+$search+'%'}}]}"
show-field="nickname"
value-field="id" value-field="id"
field="$ctrl.order.companyFk"> field="$ctrl.order.address_id">
<tpl-item>{{::nickname}}</tpl-item>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-date-picker <vn-date-picker
vn-one vn-one
label="Landed" label="Landed"
model="$ctrl.order.landed" model="$ctrl.order.landed"
ini-options="{enableTime: false}"> ini-options="{enableTime: false}">
</vn-date-picker> </vn-date-picker>
<vn-autocomplete
vn-one
url="/api/AgencyModes"
label="Agency"
search-function="{or: [{id: $search}, {name: {like: '%'+$search+'%'}}]}"
show-field="name"
value-field="id"
field="$ctrl.order.agency_id">
<tpl-item>{{::id}}: {{::name}}</tpl-item>
</vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textarea <vn-textarea

View File

@ -1,7 +1,29 @@
import ngModule from '../module'; import ngModule from '../module';
import './style.scss'; import './style.scss';
class Controller {
constructor($scope) {
let isDirty = false;
$scope.$watch('$ctrl.selection', newValue=>{
if (newValue) {
$scope.addressModel.where = {clientFk: newValue.id};
$scope.addressModel.refresh();
if (isDirty)
this.order.address_id = newValue.defaultAddressFk;
isDirty = true;
} else {
$scope.addressModel.clear();
if (isDirty)
this.order.address_id = null;
}
});
}
}
Controller.$inject = ['$scope'];
ngModule.component('vnOrderBasicData', { ngModule.component('vnOrderBasicData', {
controller: Controller,
template: require('./index.html'), template: require('./index.html'),
bindings: { bindings: {
order: '<' order: '<'

View File

@ -0,0 +1,35 @@
import './index.js';
describe('Order', () => {
describe('Component vnOrderBasicData', () => {
let $httpBackend;
let controller;
let $scope;
beforeEach(ngModule('order'));
beforeEach(angular.mock.inject(($compile, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
$httpBackend.whenGET(/^\/api\/Addresses/)
.respond([{id: 2, nickname: 'address 2'}]);
$httpBackend.whenGET(/^\/api\/Clients/)
.respond([{id: 1, defaultAddressFk: 1}]);
$scope.order = {clientFk: 1, address_id: 1};
let $element = $compile('<vn-order-basic-data order="order"></vn-order-basic-data>')($scope);
$httpBackend.flush();
controller = $element.controller('vnOrderBasicData');
}));
describe('constructor()', () => {
it('should update the address after the client changes', async() => {
controller.selection = {id: 2, defaultAddressFk: 2};
$scope.$digest();
expect(controller.order.address_id).toEqual(2);
});
});
});
});

12
package-lock.json generated
View File

@ -3762,7 +3762,7 @@
"dot-prop": { "dot-prop": {
"version": "4.2.0", "version": "4.2.0",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz",
"integrity": "sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ==", "integrity": "sha1-HxngwuGqDjJ5fEl5nyg3rGr2nFc=",
"dev": true, "dev": true,
"requires": { "requires": {
"is-obj": "^1.0.0" "is-obj": "^1.0.0"
@ -3935,7 +3935,7 @@
}, },
"jsonfile": { "jsonfile": {
"version": "2.4.0", "version": "2.4.0",
"resolved": "http://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz",
"integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -7863,7 +7863,7 @@
"karma-chrome-launcher": { "karma-chrome-launcher": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-2.2.0.tgz", "resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-2.2.0.tgz",
"integrity": "sha512-uf/ZVpAabDBPvdPdveyk1EPgbnloPvFFGgmRhYLTDH7gEB4nZdSBk8yTU47w1g/drLSx5uMOkjKk7IWKfWg/+w==", "integrity": "sha1-zxudBxNswY/iOTJ9JGVMPbw2is8=",
"dev": true, "dev": true,
"requires": { "requires": {
"fs-access": "^1.0.0", "fs-access": "^1.0.0",
@ -13367,7 +13367,7 @@
"split2": { "split2": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-2.2.0.tgz", "resolved": "https://registry.npmjs.org/split2/-/split2-2.2.0.tgz",
"integrity": "sha512-RAb22TG39LhI31MbreBgIuKiIKhVsawfTgEGqKHTK87aG+ul/PB8Sqoi3I7kVdRWiCfrKxK3uo4/YUkpNvhPbw==", "integrity": "sha1-GGsldbz4PoW30YRldWI47k7kJJM=",
"dev": true, "dev": true,
"requires": { "requires": {
"through2": "^2.0.2" "through2": "^2.0.2"
@ -14368,7 +14368,7 @@
"touch": { "touch": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz", "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz",
"integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==", "integrity": "sha1-/jZfX3XsntTlaCXgu3bSSrdK+Ds=",
"dev": true, "dev": true,
"requires": { "requires": {
"nopt": "~1.0.10" "nopt": "~1.0.10"
@ -15966,7 +15966,7 @@
"write-file-atomic": { "write-file-atomic": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.3.0.tgz", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.3.0.tgz",
"integrity": "sha512-xuPeK4OdjWqtfi59ylvVL0Yn35SF3zgcAcv7rBPFHVaEapaDr4GdGgm3j7ckTwH9wHL7fGmgfAnb0+THrHb8tA==", "integrity": "sha1-H/YVdcLipOjlENb6TiQ8zhg5mas=",
"dev": true, "dev": true,
"requires": { "requires": {
"graceful-fs": "^4.1.11", "graceful-fs": "^4.1.11",