Merge pull request '#7524 myteam filter' (!3134) from 7524-hotfix-myTeamFilter into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #3134
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Javi Gallego 2024-10-22 11:59:44 +00:00
commit 4844bcf06f
4 changed files with 51 additions and 3 deletions

View File

@ -403,7 +403,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city
(1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses');
INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`)
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), UPPER(CONCAT(name, 'Street')), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1
FROM `account`.`role` `r`
WHERE `r`.`hasLogin` = 1;

View File

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

View File

@ -50,6 +50,11 @@ module.exports = Self => {
type: 'boolean',
description: 'True when lines and stock of origin are equal'
},
{
arg: 'departmentFk',
type: 'number',
description: 'Department identifier'
},
{
arg: 'filter',
type: 'object',
@ -96,6 +101,8 @@ module.exports = Self => {
};
case 'isFullMovable':
return {'f.isFullMovable': value};
case 'departmentFk':
return {'f.departmentFk': value};
}
});

View File

@ -6,6 +6,9 @@ describe('TicketFuture getTicketsAdvance()', () => {
today.setHours(0, 0, 0, 0);
let tomorrow = Date.vnNew();
tomorrow.setDate(today.getDate() + 1);
const salesDeptId = 43;
const spain1DeptId = 95;
beforeAll.mockLoopBackContext();
it('should return the tickets passing the required data', async() => {
const tx = await models.Ticket.beginTransaction({});
@ -129,4 +132,39 @@ describe('TicketFuture getTicketsAdvance()', () => {
throw e;
}
});
it('should return the tickets matching the right department', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
ctx.args = {
dateFuture: tomorrow,
dateToAdvance: today,
warehouseFk: 1,
};
await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options);
const client = await models.Client.findById(1, null, options);
await client.updateAttribute('salesPersonFk', 1, options);
const business = await models.Business.findById(1, null, options);
await business.updateAttributes({departmentFk: spain1DeptId}, options);
const saleTickets = await models.Ticket.getTicketsAdvance(ctx, options);
const filteredSaleTickets = await models.Ticket.getTicketsAdvance(
{args: {...ctx.args, departmentFk: spain1DeptId}},
options);
expect(saleTickets.length).toBeGreaterThan(filteredSaleTickets.length);
expect(saleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeTrue();
expect(saleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue();
expect(filteredSaleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeFalse();
expect(filteredSaleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});