Fixed monitor problems filter
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-10-15 12:10:28 +02:00
parent 85b4730c6c
commit b6a9896cba
2 changed files with 14 additions and 5 deletions

View File

@ -251,7 +251,7 @@ module.exports = Self => {
// Remove positive risks
stmts.push(`
UPDATE tmp.tickets t
SET debt = NULL
SET debt = 0
WHERE t.debt + t.credit >= 0
`);
@ -267,9 +267,18 @@ module.exports = Self => {
AND f.shipped >= CURDATE()`);
stmts.push('CALL ticket_getProblems(FALSE)');
stmts.push(`
INSERT INTO tmp.ticket_problems (ticketFk, risk, totalProblems)
SELECT t.id, t.debt + t.credit AS risk, 1
FROM tmp.tickets t
WHERE (t.debt + t.credit) < 0
ON DUPLICATE KEY UPDATE
risk = t.debt + t.credit, totalProblems = totalProblems + 1
`);
stmt = new ParameterizedSQL(`
SELECT t.*, tp.*, t.debt + t.credit AS risk,
((t.debt + t.credit) + cc.riskTolerance < 0) AS hasHighRisk
SELECT t.*, tp.*,
((tp.risk) + cc.riskTolerance < 0) AS hasHighRisk
FROM tmp.tickets t
LEFT JOIN tmp.ticket_problems tp ON tp.ticketFk = t.id
JOIN clientConfig cc`);
@ -283,7 +292,7 @@ module.exports = Self => {
if (hasProblems === true) {
whereProblems = {or: [
{'tp.isFreezed': true},
{'tp.risk': {gt: 0}},
{'tp.risk': {lt: 0}},
{'tp.hasTicketRequest': true},
{'tp.hasComponentLack': true},
{'tp.isTaxDataChecked': false},

View File

@ -23,7 +23,7 @@ describe('SalesMonitor salesFilter()', () => {
const filter = {};
const result = await app.models.SalesMonitor.salesFilter(ctx, filter);
expect(result.length).toEqual(9);
expect(result.length).toEqual(13);
});
it('should return the tickets matching the problems on false', async() => {