fix: refs #7524 filter by department
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-10-21 14:30:45 +02:00
parent cb4e8355ba
commit 1efe258ea0
2 changed files with 10 additions and 26 deletions

View File

@ -51,7 +51,8 @@ BEGIN
origin.companyFk futureCompanyFk, origin.companyFk futureCompanyFk,
IFNULL(dest.nickname, origin.nickname) nickname, IFNULL(dest.nickname, origin.nickname) nickname,
dest.landed, dest.landed,
dest.preparation dest.preparation,
origin.departmentFk
FROM ( FROM (
SELECT s.ticketFk, SELECT s.ticketFk,
c.salesPersonFk workerFk, c.salesPersonFk workerFk,
@ -71,9 +72,11 @@ BEGIN
t.addressFk, t.addressFk,
t.warehouseFk, t.warehouseFk,
t.companyFk, t.companyFk,
t.agencyModeFk t.agencyModeFk,
wd.departmentFk
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 sale s ON s.ticketFk = t.id JOIN sale s ON s.ticketFk = t.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

View File

@ -51,9 +51,9 @@ module.exports = Self => {
description: 'True when lines and stock of origin are equal' description: 'True when lines and stock of origin are equal'
}, },
{ {
arg: 'myTeam', arg: 'departmentFk',
type: 'boolean', type: 'number',
description: `Whether to show only tickets for the current logged user team (currently user tickets)` description: 'Department identifier'
}, },
{ {
arg: 'filter', arg: 'filter',
@ -74,27 +74,11 @@ module.exports = Self => {
Self.getTicketsAdvance = async(ctx, options) => { Self.getTicketsAdvance = async(ctx, options) => {
const args = ctx.args; const args = ctx.args;
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const userId = ctx.req.accessToken.userId;
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const teamMembersId = [];
if (args.myTeam != null) {
const worker = await Self.app.models.Worker.findById(userId, {
include: {
relation: 'collegues'
}
}, myOptions);
const collegues = worker.collegues() || [];
for (let collegue of collegues)
teamMembersId.push(collegue.collegueFk);
if (teamMembersId.length == 0)
teamMembersId.push(userId);
}
const where = buildFilter(ctx.args, (param, value) => { const where = buildFilter(ctx.args, (param, value) => {
switch (param) { switch (param) {
case 'id': case 'id':
@ -117,11 +101,8 @@ module.exports = Self => {
}; };
case 'isFullMovable': case 'isFullMovable':
return {'f.isFullMovable': value}; return {'f.isFullMovable': value};
case 'myTeam': case 'departmentFk':
if (value) return {'f.departmentFk': value};
return {'workerFk': {inq: teamMembersId}};
else
return {'workerFk': {nin: teamMembersId}};
} }
}); });