diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index 44ef7c4860..58c440e950 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -83,6 +83,11 @@ module.exports = Self => { type: 'boolean', description: `Whether to show only tickets with problems` }, + { + arg: 'hasRoute', + type: 'boolean', + description: `Whether to show only tickets with route` + }, { arg: 'pending', type: 'boolean', @@ -188,6 +193,10 @@ module.exports = Self => { case 'alertLevel': return {'ts.alertLevel': value}; + case 'hasRoute': + if (value == true) + return {'t.routeFk': {neq: null}}; + return {'t.routeFk': null}; case 'pending': if (value) { return {and: [ @@ -266,7 +275,8 @@ module.exports = Self => { LEFT JOIN state st ON st.id = ts.stateFk LEFT JOIN client c ON c.id = t.clientFk LEFT JOIN worker wk ON wk.id = c.salesPersonFk - LEFT JOIN account.user u ON u.id = wk.userFk`); + LEFT JOIN account.user u ON u.id = wk.userFk + LEFT JOIN route r ON r.id = t.routeFk`); if (args.orderFk) { stmt.merge({ diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 14ada5c6e8..b251d53356 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -221,4 +221,61 @@ describe('ticket filter()', () => { throw e; } }); + + it('should return the tickets matching the route on true', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 9}}, args: {hasRoute: true}}; + const filter = {}; + const result = await models.Ticket.filter(ctx, filter, options); + + expect(result.length).toEqual(22); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the route on false', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 9}}, args: {hasRoute: false}}; + const filter = {}; + const result = await models.Ticket.filter(ctx, filter, options); + + expect(result.length).toEqual(5); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the route on null', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 9}}, args: {hasRoute: null}}; + const filter = {}; + const result = await models.Ticket.filter(ctx, filter, options); + + expect(result.length).toEqual(27); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/ticket/front/search-panel/index.html b/modules/ticket/front/search-panel/index.html index 4457299525..b0d4963bd5 100644 --- a/modules/ticket/front/search-panel/index.html +++ b/modules/ticket/front/search-panel/index.html @@ -135,6 +135,12 @@ ng-model="filter.pending" triple-state="true"> </vn-check> + <vn-check + vn-one + label="Has route" + ng-model="filter.hasRoute" + triple-state="true"> + </vn-check> </vn-horizontal> <vn-horizontal class="vn-px-lg vn-pb-lg vn-mt-lg"> <vn-submit label="Search"></vn-submit> diff --git a/modules/ticket/front/search-panel/locale/es.yml b/modules/ticket/front/search-panel/locale/es.yml index d6d01d0aac..52cc04d6eb 100644 --- a/modules/ticket/front/search-panel/locale/es.yml +++ b/modules/ticket/front/search-panel/locale/es.yml @@ -12,6 +12,7 @@ Order id: Id cesta Grouped States: Estado agrupado Days onward: Días adelante With problems: Con problemas +Has route: Con ruta Pending: Pendiente FREE: Libre DELIVERED: Servido