From f9abaa409aa03f7921299d57c0ba454fa0ee8bdd Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Fri, 13 Mar 2020 13:10:04 +0100 Subject: [PATCH 1/7] fix calendar-holiday model --- modules/worker/back/models/calendar-holiday.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/models/calendar-holiday.json b/modules/worker/back/models/calendar-holiday.json index 0956893ae..544452553 100644 --- a/modules/worker/back/models/calendar-holiday.json +++ b/modules/worker/back/models/calendar-holiday.json @@ -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", From 227760d71287893d881772e887112c4464c41e52 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 14:09:22 +0100 Subject: [PATCH 2/7] 2191 - Added showEmpty filter --- modules/order/back/methods/order/filter.js | 20 ++++++++-- .../back/methods/order/specs/filter.spec.js | 38 +++++++++++++++---- modules/order/front/main/index.html | 3 +- modules/order/front/main/index.js | 6 ++- modules/order/front/search-panel/index.html | 6 +++ 5 files changed, 60 insertions(+), 13 deletions(-) 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"> + + From 920d2c66b0fe3122500eac702c855ec2a3245572 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 14:25:34 +0100 Subject: [PATCH 3/7] Added translation --- modules/order/front/search-panel/index.html | 3 +-- modules/order/front/search-panel/locale/es.yml | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/order/front/search-panel/index.html b/modules/order/front/search-panel/index.html index e73e0d1dc..f9b214578 100644 --- a/modules/order/front/search-panel/index.html +++ b/modules/order/front/search-panel/index.html @@ -79,8 +79,7 @@ + ng-model="filter.showEmpty"> diff --git a/modules/order/front/search-panel/locale/es.yml b/modules/order/front/search-panel/locale/es.yml index 8f8620ac8..949f9b202 100644 --- a/modules/order/front/search-panel/locale/es.yml +++ b/modules/order/front/search-panel/locale/es.yml @@ -6,4 +6,5 @@ To: Hasta Agency: Agencia Application: Aplicación SalesPerson: Comercial -Order confirmed: Pedido confirmado \ No newline at end of file +Order confirmed: Pedido confirmado +Show empty: Mostrar vacías \ No newline at end of file From 55ff624394f05a65d6c375fa91525aab37617eac Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 14:09:22 +0100 Subject: [PATCH 4/7] 2191 - Added showEmpty filter --- modules/order/back/methods/order/filter.js | 20 ++++++++-- .../back/methods/order/specs/filter.spec.js | 38 +++++++++++++++---- modules/order/front/main/index.html | 3 +- modules/order/front/main/index.js | 6 ++- modules/order/front/search-panel/index.html | 6 +++ 5 files changed, 60 insertions(+), 13 deletions(-) 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"> + + From 2d2441707896a38935fc14accf1fa0b46650bfad Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 14:25:34 +0100 Subject: [PATCH 5/7] Added translation --- modules/order/front/search-panel/index.html | 3 +-- modules/order/front/search-panel/locale/es.yml | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/order/front/search-panel/index.html b/modules/order/front/search-panel/index.html index e73e0d1dc..f9b214578 100644 --- a/modules/order/front/search-panel/index.html +++ b/modules/order/front/search-panel/index.html @@ -79,8 +79,7 @@ + ng-model="filter.showEmpty"> diff --git a/modules/order/front/search-panel/locale/es.yml b/modules/order/front/search-panel/locale/es.yml index 8f8620ac8..949f9b202 100644 --- a/modules/order/front/search-panel/locale/es.yml +++ b/modules/order/front/search-panel/locale/es.yml @@ -6,4 +6,5 @@ To: Hasta Agency: Agencia Application: Aplicación SalesPerson: Comercial -Order confirmed: Pedido confirmado \ No newline at end of file +Order confirmed: Pedido confirmado +Show empty: Mostrar vacías \ No newline at end of file From 36ad778a590b4d432c2dea54a2d53b5f57d6d758 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 15:02:51 +0100 Subject: [PATCH 6/7] Removed default filter --- modules/order/front/main/index.js | 2 +- modules/order/front/search-panel/index.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/order/front/main/index.js b/modules/order/front/main/index.js index caf819c9d..afab4fc6e 100644 --- a/modules/order/front/main/index.js +++ b/modules/order/front/main/index.js @@ -3,7 +3,7 @@ import ModuleMain from 'salix/components/module-main'; export default class Order extends ModuleMain { $postLink() { - this.filter = {showEmpty: false}; + // this.filter = {showEmpty: false}; } } diff --git a/modules/order/front/search-panel/index.html b/modules/order/front/search-panel/index.html index f9b214578..991daa2e6 100644 --- a/modules/order/front/search-panel/index.html +++ b/modules/order/front/search-panel/index.html @@ -76,11 +76,11 @@ triple-state="true" ng-model="filter.isConfirmed"> - - + --> From 7987603d7b64df95df991f7f3a5a53ec2edf826f Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 17:22:59 +0100 Subject: [PATCH 7/7] Updated filter --- modules/order/back/methods/order/filter.js | 22 ++++++++------------- modules/order/front/main/index.js | 2 +- modules/order/front/search-panel/index.html | 4 ++-- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js index 3b891ebad..5b6af92b1 100644 --- a/modules/order/back/methods/order/filter.js +++ b/modules/order/back/methods/order/filter.js @@ -82,13 +82,13 @@ module.exports = Self => { 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} @@ -96,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) @@ -106,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': @@ -125,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}; @@ -164,7 +165,7 @@ 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` }); @@ -186,13 +187,6 @@ module.exports = Self => { `SELECT f.*, ot.* FROM tmp.filter f 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(` diff --git a/modules/order/front/main/index.js b/modules/order/front/main/index.js index afab4fc6e..caf819c9d 100644 --- a/modules/order/front/main/index.js +++ b/modules/order/front/main/index.js @@ -3,7 +3,7 @@ import ModuleMain from 'salix/components/module-main'; export default class Order extends ModuleMain { $postLink() { - // this.filter = {showEmpty: false}; + this.filter = {showEmpty: false}; } } diff --git a/modules/order/front/search-panel/index.html b/modules/order/front/search-panel/index.html index 991daa2e6..f9b214578 100644 --- a/modules/order/front/search-panel/index.html +++ b/modules/order/front/search-panel/index.html @@ -76,11 +76,11 @@ triple-state="true" ng-model="filter.isConfirmed"> - +