fixed itemDiary warehouseFk select #671

This commit is contained in:
Joan Sanchez 2018-09-18 13:34:11 +02:00
parent 9aff95904d
commit 469e6f8076
3 changed files with 22 additions and 15 deletions

View File

@ -1,7 +1,7 @@
<vn-crud-model
vn-id="model"
url="item/api/Items/getDiary"
filter="::$ctrl.filter"
filter="$ctrl.filter"
data="sales">
</vn-crud-model>
<vn-vertical>

View File

@ -10,12 +10,11 @@ class Controller {
this.$window = $window;
this.$translate = $translate;
}
/*
$postLink() {
if (this.item)
this.filterBuilder();
get item() {
return this._item;
}
*/
set item(value) {
this._item = value;
@ -23,14 +22,12 @@ class Controller {
where: {itemFk: this.$stateParams.id}
};
this.$scope.$$postDigest(() => {
if (this.$stateParams.warehouseFk)
this.warehouseFk = this.$stateParams.warehouseFk;
else if (value)
this.warehouseFk = value.itemType.warehouseFk;
}
get item() {
return this._item;
});
}
set warehouseFk(value) {
@ -41,6 +38,7 @@ class Controller {
});
this.filter.where.warehouseFk = value;
this.$scope.model.refresh();
}
get warehouseFk() {

View File

@ -1,4 +1,5 @@
import './index.js';
import {crudModel} from '../../../helpers/crudModelHelper';
describe('Item', () => {
describe('Component vnItemDiary', () => {
@ -20,7 +21,7 @@ describe('Item', () => {
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
controller = $componentController('vnItemDiary', {$scope: $scope, $stateParams});
controller.$scope.model = {};
controller.$scope.model = crudModel;
}));
describe('isToday()', () => {
@ -75,16 +76,24 @@ describe('Item', () => {
describe('set item()', () => {
it(`should set warehouseFk property based on itemType warehouseFk`, () => {
spyOn(controller.$scope, '$$postDigest').and.callThrough();
controller.item = {id: 1, itemType: {warehouseFk: 1}};
expect(controller.$scope.$$postDigest).toHaveBeenCalledWith(jasmine.any(Function));
$scope.$digest();
expect(controller.warehouseFk).toEqual(1);
expect(controller.item.id).toEqual(1);
});
it(`should set warehouseFk property based on url query warehouseFk`, () => {
spyOn(controller.$scope, '$$postDigest').and.callThrough();
controller.$stateParams.warehouseFk = 4;
controller.item = {id: 1, itemType: {warehouseFk: 1}};
expect(controller.$scope.$$postDigest).toHaveBeenCalledWith(jasmine.any(Function));
$scope.$digest();
expect(controller.warehouseFk).toEqual(4);
expect(controller.item.id).toEqual(1);
});