Merge branch '2191-order_empties_filter' of verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-03-13 13:36:49 +00:00 committed by Gitea
commit cb4f54391e
6 changed files with 61 additions and 14 deletions

View File

@ -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

View File

@ -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();
});
});

View File

@ -2,7 +2,8 @@
<vn-searchbar
search-state="order.index"
panel="vn-order-search-panel"
info="Search orders by id">
info="Search orders by id"
filter="$ctrl.filter">
</vn-searchbar>
</vn-portal>
<vn-portal slot="menu">

View File

@ -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,

View File

@ -76,6 +76,11 @@
triple-state="true"
ng-model="filter.isConfirmed">
</vn-check>
<vn-check
vn-one
label="Show empty"
ng-model="filter.showEmpty">
</vn-check>
</vn-horizontal>
<vn-horizontal class="vn-mt-lg">
<vn-submit label="Search"></vn-submit>

View File

@ -6,4 +6,5 @@ To: Hasta
Agency: Agencia
Application: Aplicación
SalesPerson: Comercial
Order confirmed: Pedido confirmado
Order confirmed: Pedido confirmado
Show empty: Mostrar vacías