diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js
index 1eaa167a7..3b891ebad 100644
--- a/modules/order/back/methods/order/filter.js
+++ b/modules/order/back/methods/order/filter.js
@@ -55,6 +55,10 @@ module.exports = Self => {
arg: 'isConfirmed',
type: 'Boolean',
description: `Order is confirmed`
+ }, {
+ arg: 'showEmpty',
+ type: 'boolean',
+ description: `Show empty orders`
}
],
returns: {
@@ -75,6 +79,7 @@ module.exports = Self => {
{relation: 'collegues'}
]
});
+ const args = ctx.args;
let teamIds = [];
if (worker.collegues().length && ctx.args.myTeam) {
@@ -164,6 +169,7 @@ module.exports = Self => {
sql: `LEFT JOIN orderTicket ort ON ort.orderFk = o.id`
});
}
+
stmt.merge(conn.makeSuffix(filter));
stmts.push(stmt);
@@ -176,10 +182,18 @@ module.exports = Self => {
stmts.push('CALL hedera.order_getTotal()');
- let orderIndex = stmts.push(`
- SELECT f.*, ot.*
+ stmt = new ParameterizedSQL(
+ `SELECT f.*, ot.*
FROM tmp.filter f
- LEFT JOIN tmp.orderTotal ot ON ot.orderFk = f.id`) - 1;
+ LEFT JOIN tmp.orderTotal ot ON ot.orderFk = f.id`);
+ const filterWhere = {};
+
+ if (args && args.showEmpty === false)
+ filterWhere.total = {neq: 0};
+
+ stmt.merge(conn.makeWhere(filterWhere));
+
+ const orderIndex = stmts.push(stmt) - 1;
stmts.push(`
DROP TEMPORARY TABLE
diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js
index fc987613a..13cb8fdeb 100644
--- a/modules/order/back/methods/order/specs/filter.spec.js
+++ b/modules/order/back/methods/order/specs/filter.spec.js
@@ -1,32 +1,54 @@
const app = require('vn-loopback/server/server');
describe('order filter()', () => {
- let ctx = {
+ const ctx = {
req: {accessToken: {userId: 9}},
args: {},
params: {}
};
it('should call the filter method with a basic search', async() => {
- let filter = {where: {'o.id': 2}};
- let result = await app.models.Order.filter(ctx, filter);
- let orderId = result[0].id;
+ const filter = {where: {'o.id': 2}};
+ const result = await app.models.Order.filter(ctx, filter);
+ const orderId = result[0].id;
expect(orderId).toEqual(2);
});
it('should call the filter method with a single advanced search', async() => {
- let filter = {where: {'o.confirmed': false}};
- let result = await app.models.Order.filter(ctx, filter);
+ const filter = {where: {'o.confirmed': false}};
+ const result = await app.models.Order.filter(ctx, filter);
expect(result.length).toEqual(16);
});
it('should call the filter method with a complex advanced search', async() => {
- let filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 19}};
- let result = await app.models.Order.filter(ctx, filter);
+ const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 19}};
+ const result = await app.models.Order.filter(ctx, filter);
expect(result.length).toEqual(7);
expect(result[0].id).toEqual(16);
});
+
+ it('should return the orders matching the showEmpty on false', async() => {
+ const filter = {};
+ ctx.args = {showEmpty: false};
+ const result = await app.models.Order.filter(ctx, filter);
+ const hasEmptyLines = result.some(order => {
+ return order.total === 0;
+ });
+
+ expect(hasEmptyLines).toBeFalsy();
+ });
+
+ it('should return the orders matching the showEmpty on true', async() => {
+ const filter = {};
+ ctx.args = {showEmpty: true};
+ const result = await app.models.Order.filter(ctx, filter);
+ const hasEmptyLines = result.some(order => {
+ return order.total === 0;
+ });
+
+ expect(hasEmptyLines).toBeTruthy();
+ });
});
diff --git a/modules/order/front/main/index.html b/modules/order/front/main/index.html
index 09d498599..7948e591a 100644
--- a/modules/order/front/main/index.html
+++ b/modules/order/front/main/index.html
@@ -2,7 +2,8 @@
+ info="Search orders by id"
+ filter="$ctrl.filter">
diff --git a/modules/order/front/main/index.js b/modules/order/front/main/index.js
index 7513d2144..caf819c9d 100644
--- a/modules/order/front/main/index.js
+++ b/modules/order/front/main/index.js
@@ -1,7 +1,11 @@
import ngModule from '../module';
import ModuleMain from 'salix/components/module-main';
-export default class Order extends ModuleMain {}
+export default class Order extends ModuleMain {
+ $postLink() {
+ this.filter = {showEmpty: false};
+ }
+}
ngModule.vnComponent('vnOrder', {
controller: Order,
diff --git a/modules/order/front/search-panel/index.html b/modules/order/front/search-panel/index.html
index 383df455f..e73e0d1dc 100644
--- a/modules/order/front/search-panel/index.html
+++ b/modules/order/front/search-panel/index.html
@@ -76,6 +76,12 @@
triple-state="true"
ng-model="filter.isConfirmed">
+
+