diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index 9a7415055..0b97b11e1 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -207,7 +207,7 @@ module.exports = Self => { LEFT JOIN province p ON p.id = a.provinceFk LEFT JOIN warehouse w ON w.id = t.warehouseFk LEFT JOIN agencyMode am ON am.id = t.agencyModeFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id + STRAIGHT_JOIN ticketState ts ON ts.ticketFk = t.id 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 @@ -227,7 +227,7 @@ module.exports = Self => { // Get client debt balance stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt'); stmts.push(` - CREATE TEMPORARY TABLE tmp.clientGetDebt + CREATE TEMPORARY TABLE tmp.clientGetDebt (PRIMARY KEY (clientFk)) ENGINE = MEMORY SELECT DISTINCT clientFk FROM tmp.filter`); @@ -238,7 +238,7 @@ module.exports = Self => { stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.tickets'); stmt = new ParameterizedSQL(` - CREATE TEMPORARY TABLE tmp.tickets + CREATE TEMPORARY TABLE tmp.tickets (PRIMARY KEY (id)) ENGINE = MEMORY SELECT f.*, r.risk AS debt @@ -268,10 +268,10 @@ module.exports = Self => { stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems'); stmt = new ParameterizedSQL(` - CREATE TEMPORARY TABLE tmp.sale_getProblems + CREATE TEMPORARY TABLE tmp.sale_getProblems (INDEX (ticketFk)) ENGINE = MEMORY - SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped + SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped FROM tmp.filter f LEFT JOIN alertLevel al ON al.id = f.alertLevel WHERE (al.code = 'FREE' OR f.alertLevel IS NULL) @@ -377,7 +377,7 @@ module.exports = Self => { const ticketsIndex = stmts.push(stmt) - 1; stmts.push( - `DROP TEMPORARY TABLE + `DROP TEMPORARY TABLE tmp.filter, tmp.ticket_problems, tmp.sale_getProblems, diff --git a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js index a4fb1b0af..0682cef09 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js @@ -147,16 +147,12 @@ describe('SalesMonitor salesFilter()', () => { const options = {transaction: tx}; const ctx = {req: {accessToken: {userId: 9}}, args: {pending: false}}; - const filter = {}; + const filter = {order: 'alertLevel ASC'}; const result = await models.SalesMonitor.salesFilter(ctx, filter, options); const firstRow = result[0]; - const secondRow = result[1]; - const thirdRow = result[2]; expect(result.length).toEqual(12); - expect(firstRow.state).toEqual('Entregado'); - expect(secondRow.state).toEqual('Entregado'); - expect(thirdRow.state).toEqual('Entregado'); + expect(firstRow.alertLevel).not.toEqual(0); await tx.rollback(); } catch (e) {