Merge branch 'dev' into 7731-clientViesCode
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Robert Ferrús 2024-10-22 06:18:51 +00:00
commit 1a5e473656
7 changed files with 75 additions and 39 deletions

View File

@ -6,25 +6,27 @@ BLOCK1: BEGIN
DECLARE vShipped DATE;
DECLARE vPreviousShipped DATE;
DECLARE vDone boolean;
DECLARE cur cursor for
SELECT clientFk, firstShipped
FROM bs.clientNewBorn;
DECLARE cur CURSOR FOR
SELECT clientFk, firstShipped
FROM bs.clientNewBorn;
DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE;
SET vDone := FALSE;
DELETE FROM bs.clientNewBorn WHERE isModified = FALSE;
INSERT INTO clientNewBorn(clientFk, firstShipped, lastShipped)
SELECT c.id, MAX(t.shipped), MAX(t.shipped)
FROM vn.client c
JOIN vn.ticket t on t.clientFk = c.id
LEFT JOIN clientNewBorn cb on cb.clientFk = c.id
WHERE t.shipped BETWEEN TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) AND util.VN_CURDATE() AND cb.isModified is null
GROUP BY c.id;
INSERT INTO clientNewBorn(clientFk, firstShipped, lastShipped)
SELECT c.id, DATE(MAX(t.shipped)), DATE(MAX(t.shipped))
FROM vn.client c
JOIN vn.ticket t ON t.clientFk = c.id
LEFT JOIN clientNewBorn cb ON cb.clientFk = c.id
WHERE t.shipped BETWEEN util.VN_CURDATE() - INTERVAL 1 YEAR
AND util.VN_CURDATE()
AND cb.isModified IS NULL
GROUP BY c.id;
OPEN cur;
LOOP1: LOOP
SET vDone := FALSE;
FETCH cur INTO vClientFk, vShipped;

View File

@ -85,16 +85,11 @@ module.exports = Self => {
const updatedClaim = await claim.updateAttributes(args, myOptions);
const salesPerson = claim.client().salesPersonUser();
if (salesPerson) {
if (changedPickup && updatedClaim.pickup)
await notifyPickUp(ctx, salesPerson.id, claim);
if (args.claimStateFk) {
const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions);
await notifyStateChange(ctx, salesPerson.id, claim, newState.description);
if (newState.code == 'canceled')
await notifyStateChange(ctx, claim.workerFk, claim, newState.description);
}
if (salesPerson && args.claimStateFk) {
const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions);
await notifyStateChange(ctx, salesPerson.id, claim, newState.description);
if (newState.code == 'canceled')
await notifyStateChange(ctx, claim.workerFk, claim, newState.description);
}
if (tx) await tx.commit();
@ -119,18 +114,4 @@ module.exports = Self => {
});
await models.Chat.sendCheckingPresence(ctx, workerId, message);
}
async function notifyPickUp(ctx, workerId, claim) {
const models = Self.app.models;
const url = await models.Url.getUrl();
const $t = ctx.req.__; // $translate
const message = $t('Claim will be picked', {
claimId: claim.id,
clientName: claim.client().name,
claimUrl: `${url}claim/${claim.id}/summary`,
claimPickup: $t(claim.pickup)
});
await models.Chat.sendCheckingPresence(ctx, workerId, message);
}
};

View File

@ -74,7 +74,8 @@ module.exports = Self => {
pm.name payMethod,
r.finished IS NULL hasRecovery,
dp.id departmentFk,
dp.name departmentName
dp.name departmentName,
dp.notificationEmail departmentEmail
FROM defaulter d
JOIN client c ON c.id = d.clientFk
JOIN country cn ON cn.id = c.countryFk

View File

@ -47,7 +47,7 @@ module.exports = Self => {
await models.Mail.create({
subject: $t('Comment added to client', {clientFk: defaulter.clientFk}),
body: body,
receiver: `${defaulter.salesPersonName}@verdnatura.es`,
receiver: `${defaulter.departmentEmail}`,
replyTo: `${user.name}@verdnatura.es`
}, myOptions);
}

View File

@ -59,6 +59,11 @@ module.exports = Self => {
arg: 'state',
type: 'string',
description: `Search request by request state`
},
{
arg: 'myTeam',
type: 'boolean',
description: `Team partners`
}
],
returns: {
@ -75,6 +80,8 @@ module.exports = Self => {
const conn = Self.dataSource.connector;
const userId = ctx.req.accessToken.userId;
const myOptions = {};
const models = Self.app.models;
const args = ctx.args;
if (typeof options == 'object')
Object.assign(myOptions, options);
@ -82,6 +89,21 @@ module.exports = Self => {
if (ctx.args.mine)
ctx.args.attenderFk = userId;
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);
}
let where = buildFilter(ctx.args, (param, value) => {
switch (param) {
case 'search':
@ -113,6 +135,11 @@ module.exports = Self => {
return {'w.id': value};
case 'salesPersonFk':
return {'c.salesPersonFk': value};
case 'myTeam':
if (value)
return {'tr.requesterFk': {inq: teamMembersId}};
else
return {'tr.requesterFk': {nin: teamMembersId}};
}
});

View File

@ -49,9 +49,12 @@ module.exports = Self => {
where: {originalTicketFk: id}
}, myOptions);
const hasRefund = !!ticketRefunds?.length;
const allDeleted = ticketRefunds.every(refund => refund.refundTicket().isDeleted);
if (ticketRefunds?.length && !allDeleted) {
if (!hasRefund) await models.TicketRefund.destroyAll({refundTicketFk: id}, myOptions);
if (hasRefund && !allDeleted) {
const notDeleted = [];
for (const refund of ticketRefunds)
if (!refund.refundTicket().isDeleted) notDeleted.push(refund.refundTicket().id);

View File

@ -113,5 +113,27 @@ describe('ticket setDeleted()', () => {
expect(error.message).not.toContain('Tickets with associated refunds');
});
it('should delete the refund - original ticket relation', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const ticketId = 24;
const refundTicket = await models.TicketRefund.findOne({where: {refundTicketFk: ticketId}}, options);
expect(refundTicket).toBeTruthy();
await models.Ticket.setDeleted(ctx, ticketId, options);
const removedRefundTicket = await models.TicketRefund.findOne({
where: {refundTicketFk: ticketId}},
options);
expect(removedRefundTicket).toBeNull();
await tx.rollback();
} catch (e) {
await tx.rollback();
}
});
});
});