Merge pull request '#6583 add new opt in where builder' (!3162) from 6583-addOnlyDestination into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #3162
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Jorge Penadés 2024-12-18 08:48:41 +00:00
commit 3deaa8a95b
3 changed files with 71 additions and 8 deletions

View File

@ -52,7 +52,8 @@ BEGIN
IFNULL(dest.nickname, origin.nickname) nickname, IFNULL(dest.nickname, origin.nickname) nickname,
dest.landed, dest.landed,
dest.preparation, dest.preparation,
origin.departmentFk origin.departmentFk,
origin.saleClonedFk
FROM ( FROM (
SELECT s.ticketFk, SELECT s.ticketFk,
c.salesPersonFk workerFk, c.salesPersonFk workerFk,
@ -73,11 +74,13 @@ BEGIN
t.warehouseFk, t.warehouseFk,
t.companyFk, t.companyFk,
t.agencyModeFk, t.agencyModeFk,
wd.departmentFk wd.departmentFk,
sc.saleClonedFk
FROM ticket t FROM ticket t
JOIN client c ON c.id = t.clientFk JOIN client c ON c.id = t.clientFk
JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk
JOIN sale s ON s.ticketFk = t.id 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 saleVolume sv ON sv.saleFk = s.id
JOIN item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk
JOIN ticketState ts ON ts.ticketFk = t.id JOIN ticketState ts ON ts.ticketFk = t.id

View File

@ -55,6 +55,11 @@ module.exports = Self => {
type: 'number', type: 'number',
description: 'Department identifier' description: 'Department identifier'
}, },
{
arg: 'onlyWithDestination',
type: 'Boolean',
description: 'True when only tickets with destination are returned'
},
{ {
arg: 'filter', arg: 'filter',
type: 'object', type: 'object',
@ -103,6 +108,8 @@ module.exports = Self => {
return {'f.isFullMovable': value}; return {'f.isFullMovable': value};
case 'departmentFk': case 'departmentFk':
return {'f.departmentFk': value}; return {'f.departmentFk': value};
case 'onlyWithDestination':
return {'f.id': value ? {neq: null} : null};
} }
}); });

View File

@ -8,6 +8,7 @@ describe('TicketFuture getTicketsAdvance()', () => {
tomorrow.setDate(today.getDate() + 1); tomorrow.setDate(today.getDate() + 1);
const salesDeptId = 43; const salesDeptId = 43;
const spain1DeptId = 95; const spain1DeptId = 95;
const warehouseId = 1;
beforeAll.mockLoopBackContext(); beforeAll.mockLoopBackContext();
it('should return the tickets passing the required data', async() => { it('should return the tickets passing the required data', async() => {
@ -19,7 +20,7 @@ describe('TicketFuture getTicketsAdvance()', () => {
const args = { const args = {
dateFuture: tomorrow, dateFuture: tomorrow,
dateToAdvance: today, dateToAdvance: today,
warehouseFk: 1, warehouseFk: warehouseId,
}; };
ctx.args = args; ctx.args = args;
@ -42,7 +43,7 @@ describe('TicketFuture getTicketsAdvance()', () => {
const args = { const args = {
dateFuture: tomorrow, dateFuture: tomorrow,
dateToAdvance: today, dateToAdvance: today,
warehouseFk: 1, warehouseFk: warehouseId,
isFullMovable: true isFullMovable: true
}; };
@ -67,7 +68,7 @@ describe('TicketFuture getTicketsAdvance()', () => {
const args = { const args = {
dateFuture: tomorrow, dateFuture: tomorrow,
dateToAdvance: today, dateToAdvance: today,
warehouseFk: 1, warehouseFk: warehouseId,
isFullMovable: false isFullMovable: false
}; };
@ -92,7 +93,7 @@ describe('TicketFuture getTicketsAdvance()', () => {
const args = { const args = {
dateFuture: tomorrow, dateFuture: tomorrow,
dateToAdvance: today, dateToAdvance: today,
warehouseFk: 1, warehouseFk: warehouseId,
ipt: 'V' ipt: 'V'
}; };
@ -117,7 +118,7 @@ describe('TicketFuture getTicketsAdvance()', () => {
const args = { const args = {
dateFuture: tomorrow, dateFuture: tomorrow,
dateToAdvance: today, dateToAdvance: today,
warehouseFk: 1, warehouseFk: warehouseId,
tfIpt: 'V' tfIpt: 'V'
}; };
@ -141,7 +142,7 @@ describe('TicketFuture getTicketsAdvance()', () => {
ctx.args = { ctx.args = {
dateFuture: tomorrow, dateFuture: tomorrow,
dateToAdvance: today, dateToAdvance: today,
warehouseFk: 1, warehouseFk: warehouseId,
}; };
await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options); await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options);
@ -167,4 +168,56 @@ describe('TicketFuture getTicketsAdvance()', () => {
throw e; 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;
}
});
}); });