diff --git a/client/core/src/components/th/index.spec.js b/client/core/src/components/th/index.spec.js
index fd863b46e..780ffe8d7 100644
--- a/client/core/src/components/th/index.spec.js
+++ b/client/core/src/components/th/index.spec.js
@@ -14,16 +14,24 @@ describe('Component vnTh', () => {
$componentController = _$componentController_;
$element = angular.element(`
${template}
`);
controller = $componentController('vnTh', {$element: $element});
- controller.table = {setOrder: () => {}};
- controller.column = {
- getAttribute: () => 'MyField',
- classList: {
- add: () => {},
- remove: () => {}
- }
+ controller.table = {
+ setOrder: () => {},
+ applyOrder: () => {}
};
+ controller.column.setAttribute('field', 'MyField');
}));
+ describe('onInit()', () => {
+ it(`should define controllers order as per defaultOrder then call setOrder()`, () => {
+ controller.defaultOrder = 'DESC';
+ spyOn(controller.table, 'setOrder');
+ controller.$onInit();
+
+ expect(controller.order).toEqual('DESC');
+ expect(controller.table.setOrder).toHaveBeenCalledWith('MyField', 'DESC');
+ });
+ });
+
describe('toggleOrder()', () => {
it(`should change the ordenation to DESC (descendant) if it was ASC (ascendant)`, () => {
controller.order = 'ASC';
@@ -47,14 +55,56 @@ describe('Component vnTh', () => {
});
});
- describe('onInit()', () => {
- it(`should define controllers order as per defaultOrder then call setOrder()`, () => {
- controller.defaultOrder = 'DESC';
- spyOn(controller.table, 'setOrder');
- controller.$onInit();
+ describe('onToggleOrder()', () => {
+ it(`should not call updateArrow() method if field property isn't defined`, () => {
+ controller.column.setAttribute('field', '');
+ spyOn(controller, 'updateArrow');
- expect(controller.order).toEqual('DESC');
- expect(controller.table.setOrder).toHaveBeenCalledWith('MyField', 'DESC');
+ controller.onToggleOrder();
+
+ expect(controller.updateArrow).not.toHaveBeenCalledWith();
+ });
+
+ it(`should call toggleOrder() method if field property and
+ table field property equals and then call updateArrow()`, () => {
+ controller.table.field = 'MyField';
+ spyOn(controller, 'toggleOrder');
+ spyOn(controller, 'updateArrow');
+
+ controller.onToggleOrder();
+
+ expect(controller.toggleOrder).toHaveBeenCalledWith();
+ expect(controller.updateArrow).toHaveBeenCalledWith();
+ });
+
+ it(`should call setOrder() method if field property and
+ table field property doesn't equals and then call updateArrow()`, () => {
+ controller.table.field = 'MyField2';
+ spyOn(controller.table, 'setOrder');
+ spyOn(controller, 'updateArrow');
+
+ controller.onToggleOrder();
+
+ expect(controller.table.setOrder).toHaveBeenCalledWith('MyField', 'ASC');
+ expect(controller.updateArrow).toHaveBeenCalledWith();
+ });
+ });
+
+ describe('updateArrow()', () => {
+ it(`should remove 'asc' class and add 'desc' class if order property is descendant`, () => {
+ controller.column.classList.add('asc');
+ controller.order = 'DESC';
+ controller.updateArrow();
+
+ expect(controller.column.classList[0]).toEqual('desc');
+ });
+
+ it(`should remove 'asc' class and add it again if order property is ascendant`, () => {
+ controller.column.classList.add('asc');
+ controller.order = 'ASC';
+ controller.updateArrow();
+
+ expect(controller.column.classList[0]).toEqual('asc');
});
});
});
diff --git a/client/item/src/diary/index.js b/client/item/src/diary/index.js
index 675b35c5f..75a7efd53 100644
--- a/client/item/src/diary/index.js
+++ b/client/item/src/diary/index.js
@@ -2,11 +2,12 @@ import ngModule from '../module';
import './style.scss';
class Controller {
- constructor($scope, $http, $state, $window) {
+ constructor($scope, $http, $state, $window, $translate) {
this.$scope = $scope;
this.$http = $http;
this.$state = $state;
this.$window = $window;
+ this.$translate = $translate;
}
$postLink() {
@@ -56,9 +57,8 @@ class Controller {
let lines = this.$scope.model.data;
for (let i = 0; i < lines.length; i++) {
let isFutureDate = new Date(lines[i].date) > new Date();
- let isGenreOut = lines[i].alertLevel != 0;
- if (!isFutureDate && !isGenreOut)
+ if (isFutureDate)
return i;
}
}
@@ -68,10 +68,14 @@ class Controller {
for (let i = this.freeLineIndex; i > 0; i--) {
let line = lines[i];
+ let currentDate = new Date();
+ currentDate.setHours(0, 0, 0);
- if (line.alertLevel == 1 && line.isPicked || line.alertLevel > 1) {
+ let isPastDate = new Date(lines[i].date) < currentDate;
+ let isPicked = line.alertLevel == 1 && line.isPicked;
+
+ if ((isPicked) || line.alertLevel > 1 || isPastDate)
return i;
- }
}
}
@@ -86,7 +90,7 @@ class Controller {
let balance = onPreparationLine.querySelector('.balance');
balance.classList.add('counter');
- balance.title = 'Visible quantity';
+ balance.title = this.$translate.instant('Visible quantity');
let headerOffset = body.querySelector('header').getBoundingClientRect();
let headerHeight = headerOffset.height;
@@ -126,7 +130,7 @@ class Controller {
}
}
-Controller.$inject = ['$scope', '$http', '$state', '$window'];
+Controller.$inject = ['$scope', '$http', '$state', '$window', '$translate'];
ngModule.component('vnItemDiary', {
template: require('./index.html'),
diff --git a/client/item/src/diary/index.spec.js b/client/item/src/diary/index.spec.js
index 559fe3ea4..c5c909ed5 100644
--- a/client/item/src/diary/index.spec.js
+++ b/client/item/src/diary/index.spec.js
@@ -40,10 +40,13 @@ describe('Item', () => {
describe('freeLineIndex()', () => {
it(`should call freeLineIndex() and return an index from line with alertLevel 0 and current date`, () => {
+ let currentDate = new Date();
+ currentDate.setDate(currentDate.getDate() + 1);
+
controller.$scope.model = {data: [
{name: 'My item 1', alertLevel: 3, date: '2018-05-02'},
{name: 'My item 2', alertLevel: 1, date: '2018-05-03'},
- {name: 'My item 3', alertLevel: 0, date: new Date()}]
+ {name: 'My item 3', alertLevel: 0, date: currentDate}]
};
let result = controller.freeLineIndex;
@@ -53,15 +56,17 @@ describe('Item', () => {
describe('onPreparationLineIndex()', () => {
it(`should call onPreparationLineIndex() and return an index from line with alertLevel 1 and isPicked true`, () => {
+ let currentDate = new Date();
+ currentDate.setDate(currentDate.getDate() + 1);
controller.$scope.model = {data: [
{name: 'My item 1', alertLevel: 3, isPicked: true, date: '2018-05-02'},
{name: 'My item 3', alertLevel: 1, isPicked: true, date: '2018-05-03'},
{name: 'My item 4', alertLevel: 1, isPicked: false, date: '2018-05-03'},
- {name: 'My item 5', alertLevel: 0, isPicked: false, date: new Date()}]
+ {name: 'My item 5', alertLevel: 0, isPicked: false, date: currentDate}]
};
let result = controller.onPreparationLineIndex;
- expect(result).toEqual(1);
+ expect(result).toEqual(2);
});
});
diff --git a/client/item/src/diary/locale/es.yml b/client/item/src/diary/locale/es.yml
new file mode 100644
index 000000000..c2d7c4683
--- /dev/null
+++ b/client/item/src/diary/locale/es.yml
@@ -0,0 +1,3 @@
+In: Entrada
+Out: Salida
+Visible quantity: Cantidad visible
\ No newline at end of file
diff --git a/client/item/src/locale/es.yml b/client/item/src/locale/es.yml
index dd49f3d90..6c1ea804d 100644
--- a/client/item/src/locale/es.yml
+++ b/client/item/src/locale/es.yml
@@ -25,8 +25,6 @@ Intrastat code: Código intrastat
Warehouse: Almacén
Code: Código
State: Estado
-In: Entrada
-Out: Salida
Species: Especie
Add tag: Añadir etiqueta
Remove tag: Quitar etiqueta
diff --git a/services/loopback/common/methods/ticket/filter.js b/services/loopback/common/methods/ticket/filter.js
index 7a94b60b8..c7523883e 100644
--- a/services/loopback/common/methods/ticket/filter.js
+++ b/services/loopback/common/methods/ticket/filter.js
@@ -89,7 +89,7 @@ module.exports = Self => {
tp.problem
FROM tmp.filter f
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.ticketFk`);
- stmt.merge(Self.buildOrderBy(filter, 'f'));
+ stmt.merge(Self.buildOrderBy(filter));
let ticketsIndex = stmts.push(stmt) - 1;
stmts.push(