Merge branch '4409-binlogQueueFn' of https://gitea.verdnatura.es/verdnatura/salix into 4409-binlogQueueFn
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Juan Ferrer 2024-04-15 10:18:07 +02:00
commit 31e27f1926
4 changed files with 84 additions and 11 deletions

View File

@ -1827,9 +1827,9 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`,
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `ticketFk`) INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `ticketFk`)
VALUES VALUES
(1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, 11), (1, util.VN_CURDATE(), 1, 1101, 19, 3, 0, util.VN_CURDATE(), 0, 11),
(2, util.VN_CURDATE(), 4, 1101, 18, 3, 0, util.VN_CURDATE(), 1, 16), (2, util.VN_CURDATE(), 4, 1101, 18, 3, 0, util.VN_CURDATE(), 1, 16),
(3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, 7), (3, util.VN_CURDATE(), 3, 1101, 19, 1, 1, util.VN_CURDATE(), 5, 7),
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, 8); (4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, 8);
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`) INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
@ -3748,7 +3748,7 @@ INSERT INTO vn.ticketLog (originFk,userFk,`action`,creationDate,changedModel,new
INSERT INTO `vn`.`supplierDms`(`supplierFk`, `dmsFk`, `editorFk`) INSERT INTO `vn`.`supplierDms`(`supplierFk`, `dmsFk`, `editorFk`)
VALUES (1, 10, 9); VALUES (1, 10, 9);
INSERT INTO `vn`.`accountReconciliation` (supplierAccountFk,operationDated,valueDated,amount,concept,debitCredit,calculatedCode,created) INSERT INTO `vn`.`accountReconciliation` (supplierAccountFk,operationDated,valueDated,amount,concept,debitCredit,calculatedCode,created)
VALUES VALUES
(241,'2023-12-13 00:00:00.000','2023-12-07 00:00:00.000',19.36,'BEL 1','debit','2','2023-12-14 08:39:53.000'), (241,'2023-12-13 00:00:00.000','2023-12-07 00:00:00.000',19.36,'BEL 1','debit','2','2023-12-14 08:39:53.000'),
(241,'2023-12-13 00:00:00.000','2023-12-07 00:00:00.000',30226.43,'BEL 2','debit','1','2023-12-14 08:39:53.000'), (241,'2023-12-13 00:00:00.000','2023-12-07 00:00:00.000',30226.43,'BEL 2','debit','1','2023-12-14 08:39:53.000'),
@ -3759,5 +3759,10 @@ INSERT INTO `vn`.`accountReconciliation` (supplierAccountFk,operationDated,value
(241,'2023-12-13 00:00:00.000','2023-12-13 00:00:00.000',3210.5,'RCBO.VOLVO','debit','121','2023-12-14 08:39:53.000'), (241,'2023-12-13 00:00:00.000','2023-12-13 00:00:00.000',3210.5,'RCBO.VOLVO','debit','121','2023-12-14 08:39:53.000'),
(241,'2023-12-13 00:00:00.000','2023-12-13 00:00:00.000',6513.7,'RCBO.ENERPLUS','debit','120','2023-12-14 08:39:53.000'); (241,'2023-12-13 00:00:00.000','2023-12-13 00:00:00.000',6513.7,'RCBO.ENERPLUS','debit','120','2023-12-14 08:39:53.000');
INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk) INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk)
VALUES (1, 1); VALUES (1, 1);
INSERT INTO vn.workerTeam(id, team, workerFk)
VALUES
(8, 1, 19);

View File

@ -79,7 +79,12 @@ module.exports = Self => {
type: 'number', type: 'number',
description: 'The claimResponsible id', description: 'The claimResponsible id',
http: {source: 'query'} http: {source: 'query'}
} },
{
arg: 'myTeam',
type: 'boolean',
description: `Team partners`
},
], ],
returns: { returns: {
type: ['object'], type: ['object'],
@ -92,6 +97,7 @@ module.exports = Self => {
}); });
Self.filter = async(ctx, filter, options) => { Self.filter = async(ctx, filter, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models; const models = Self.app.models;
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const args = ctx.args; const args = ctx.args;
@ -121,7 +127,23 @@ module.exports = Self => {
claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk); claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk);
} }
const where = buildFilter(args, (param, value) => { // Apply filter by team
const teamMembersId = [];
if (args.myTeam != null) {
const worker = await 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) => {
switch (param) { switch (param) {
case 'search': case 'search':
return /^\d+$/.test(value) return /^\d+$/.test(value)
@ -152,6 +174,11 @@ module.exports = Self => {
to.setHours(23, 59, 59, 999); to.setHours(23, 59, 59, 999);
return {'cl.created': {between: [value, to]}}; return {'cl.created': {between: [value, to]}};
case 'myTeam':
if (value)
return {'cl.workerFk': {inq: teamMembersId}};
else
return {'cl.workerFk': {nin: teamMembersId}};
} }
}); });

View File

@ -1,13 +1,25 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('claim filter()', () => { describe('claim filter()', () => {
let ctx;
beforeEach(() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
}
};
});
it('should return 1 result filtering by id', async() => { it('should return 1 result filtering by id', async() => {
const tx = await app.models.Claim.beginTransaction({}); const tx = await app.models.Claim.beginTransaction({});
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, search: 1}}, null, options); ctx.args = {search: 1};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
expect(result[0].id).toEqual(1); expect(result[0].id).toEqual(1);
@ -25,7 +37,8 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, search: 'Tony Stark'}}, null, options); ctx.args = {search: 'Tony Stark'};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
expect(result[0].id).toEqual(4); expect(result[0].id).toEqual(4);
@ -43,7 +56,8 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, workerFk: 18}}, null, options); ctx.args = {workerFk: 18};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(4); expect(result.length).toEqual(4);
expect(result[0].id).toEqual(1); expect(result[0].id).toEqual(1);
@ -64,7 +78,8 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, itemFk: 2}}, null, options); ctx.args = {itemFk: 2};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
expect(result[0].id).toEqual(1); expect(result[0].id).toEqual(1);
@ -84,7 +99,8 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, claimResponsibleFk: 7}}, null, options); ctx.args = {claimResponsibleFk: 7};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
expect(result[0].id).toEqual(2); expect(result[0].id).toEqual(2);
@ -97,4 +113,22 @@ describe('claim filter()', () => {
throw e; throw e;
} }
}); });
it('should now return claims from the worker team', async() => {
const tx = await models.Claim.beginTransaction({});
try {
const options = {transaction: tx};
ctx.args = {itemFk: null, myTeam: true};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
}); });

View File

@ -70,6 +70,13 @@
label="Responsible"> label="Responsible">
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal>
<vn-check
vn-one
label="My team"
ng-model="filter.myTeam"
triple-state="true">
</vn-horizontal>
<vn-horizontal class="vn-mt-lg"> <vn-horizontal class="vn-mt-lg">
<vn-submit label="Search"></vn-submit> <vn-submit label="Search"></vn-submit>
</vn-horizontal> </vn-horizontal>