Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2088-ticket_datosBasicos
This commit is contained in:
commit
6fabada18c
|
@ -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,15 +79,16 @@ module.exports = Self => {
|
|||
{relation: 'collegues'}
|
||||
]
|
||||
});
|
||||
const args = ctx.args;
|
||||
let teamIds = [];
|
||||
|
||||
if (worker.collegues().length && ctx.args.myTeam) {
|
||||
if (worker.collegues().length && args.myTeam) {
|
||||
worker.collegues().forEach(collegue => {
|
||||
teamIds.push(collegue.collegueFk);
|
||||
});
|
||||
}
|
||||
|
||||
if (worker.collegues().length === 0 && ctx.args.myTeam) {
|
||||
if (worker.collegues().length === 0 && args.myTeam) {
|
||||
worker = await Self.app.models.Worker.findOne({
|
||||
fields: ['id'],
|
||||
where: {userFk: ctx.req.accessToken.userId}
|
||||
|
@ -91,9 +96,9 @@ module.exports = Self => {
|
|||
teamIds = [worker && worker.id];
|
||||
}
|
||||
|
||||
if (ctx.args && ctx.args.myTeam)
|
||||
ctx.args.teamIds = teamIds;
|
||||
let where = buildFilter(ctx.args, (param, value) => {
|
||||
if (args && args.myTeam)
|
||||
args.teamIds = teamIds;
|
||||
let where = buildFilter(args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
return /^\d+$/.test(value)
|
||||
|
@ -101,7 +106,6 @@ module.exports = Self => {
|
|||
: {or: [
|
||||
{'c.name': {like: `%${value}%`}}
|
||||
]};
|
||||
// return {'o.id': value};
|
||||
case 'from':
|
||||
return {'o.date_send': {gte: value}};
|
||||
case 'to':
|
||||
|
@ -120,6 +124,8 @@ module.exports = Self => {
|
|||
return {'o.confirmed': value ? 1 : 0};
|
||||
case 'myTeam':
|
||||
return {'c.salesPersonFk': {inq: teamIds}};
|
||||
case 'showEmpty':
|
||||
return {'o.total': {neq: value}};
|
||||
case 'id':
|
||||
param = `o.${param}`;
|
||||
return {[param]: value};
|
||||
|
@ -159,11 +165,12 @@ module.exports = Self => {
|
|||
LEFT JOIN account.user u ON u.id = wk.userFk
|
||||
LEFT JOIN company co ON co.id = o.company_id`);
|
||||
|
||||
if (ctx.args && ctx.args.ticketFk) {
|
||||
if (args && args.ticketFk) {
|
||||
stmt.merge({
|
||||
sql: `LEFT JOIN orderTicket ort ON ort.orderFk = o.id`
|
||||
});
|
||||
}
|
||||
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
stmts.push(stmt);
|
||||
|
||||
|
@ -176,10 +183,11 @@ 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 orderIndex = stmts.push(stmt) - 1;
|
||||
|
||||
stmts.push(`
|
||||
DROP TEMPORARY TABLE
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
|
@ -23,12 +23,12 @@
|
|||
"detail": {
|
||||
"type": "belongsTo",
|
||||
"model": "CalendarHolidaysName",
|
||||
"foreignKey": "holidayDetailFk"
|
||||
"foreignKey": "calendarHolidaysNameFk"
|
||||
},
|
||||
"type": {
|
||||
"type": "belongsTo",
|
||||
"model": "CalendarHolidaysType",
|
||||
"foreignKey": "holidayTypeFk"
|
||||
"foreignKey": "calendarHolidaysTypeFk"
|
||||
},
|
||||
"workCenter": {
|
||||
"type": "belongsTo",
|
||||
|
|
Loading…
Reference in New Issue