diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index e8fc70bba..cee706e08 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -52,7 +52,8 @@ BEGIN IFNULL(dest.nickname, origin.nickname) nickname, dest.landed, dest.preparation, - origin.departmentFk + origin.departmentFk, + origin.saleClonedFk FROM ( SELECT s.ticketFk, c.salesPersonFk workerFk, @@ -73,11 +74,13 @@ BEGIN t.warehouseFk, t.companyFk, t.agencyModeFk, - wd.departmentFk + wd.departmentFk, + sc.saleClonedFk FROM ticket t JOIN client c ON c.id = t.clientFk JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk JOIN sale s ON s.ticketFk = t.id + LEFT JOIN saleCloned sc ON sc.saleClonedFk = s.id JOIN saleVolume sv ON sv.saleFk = s.id JOIN item i ON i.id = s.itemFk JOIN ticketState ts ON ts.ticketFk = t.id diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 41f3ee79a..58d46173c 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -55,6 +55,11 @@ module.exports = Self => { type: 'number', description: 'Department identifier' }, + { + arg: 'onlyWithDestination', + type: 'Boolean', + description: 'True when only tickets with destination are returned' + }, { arg: 'filter', type: 'object', @@ -103,6 +108,8 @@ module.exports = Self => { return {'f.isFullMovable': value}; case 'departmentFk': return {'f.departmentFk': value}; + case 'onlyWithDestination': + return {'f.id': value ? {neq: null} : null}; } }); diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index a941013cd..157cdb1ff 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -8,6 +8,7 @@ describe('TicketFuture getTicketsAdvance()', () => { tomorrow.setDate(today.getDate() + 1); const salesDeptId = 43; const spain1DeptId = 95; + const warehouseId = 1; beforeAll.mockLoopBackContext(); it('should return the tickets passing the required data', async() => { @@ -19,7 +20,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, }; ctx.args = args; @@ -42,7 +43,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, isFullMovable: true }; @@ -67,7 +68,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, isFullMovable: false }; @@ -92,7 +93,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, ipt: 'V' }; @@ -117,7 +118,7 @@ describe('TicketFuture getTicketsAdvance()', () => { const args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, tfIpt: 'V' }; @@ -141,7 +142,7 @@ describe('TicketFuture getTicketsAdvance()', () => { ctx.args = { dateFuture: tomorrow, dateToAdvance: today, - warehouseFk: 1, + warehouseFk: warehouseId, }; await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options); @@ -167,4 +168,56 @@ describe('TicketFuture getTicketsAdvance()', () => { throw e; } }); + + it('should return the tickets with only destination', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const args = { + dateFuture: today, + dateToAdvance: today.setHours(23, 59, 59, 999), + warehouseFk: warehouseId, + }; + ctx.args = args; + + const allTickets = await models.Ticket.getTicketsAdvance(ctx, options); + ctx.args.onlyWithDestination = true; + const withDestinationTickets = await models.Ticket.getTicketsAdvance(ctx, options); + + expect(allTickets.filter(ticket => ticket.id).length).toBe(withDestinationTickets.length); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets without only destination', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const args = { + dateFuture: today, + dateToAdvance: today.setHours(23, 59, 59, 999), + warehouseFk: warehouseId, + }; + ctx.args = args; + + const allTickets = await models.Ticket.getTicketsAdvance(ctx, options); + ctx.args.onlyWithDestination = false; + const withoutDestinationTickets = await models.Ticket.getTicketsAdvance(ctx, options); + + expect(allTickets.filter(ticket => !ticket.id).length).toBe(withoutDestinationTickets.length); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); });