Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2288-item_diary

This commit is contained in:
Bernat Exposito Domenech 2020-06-03 12:32:27 +02:00
commit 34b6641e5c
8 changed files with 2518 additions and 1885 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
const app = require('vn-loopback/server/server');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('zone zone_getEvents()', () => {
fdescribe('zone zone_getEvents()', () => {
it(`should return data for a agencyMode with deliveryMethod pickup`, async() => {
let stmts = [];
let stmt;
@ -19,14 +19,13 @@ describe('zone zone_getEvents()', () => {
]);
stmts.push(stmt);
let firstResultIndex = stmts.push(stmt) - 1;
let secondResultIndex = firstResultIndex + 1;
stmts.push('ROLLBACK');
let sql = ParameterizedSQL.join(stmts, ';');
let result = await app.models.Ticket.rawStmt(sql);
let zonesEvents = result[secondResultIndex];
let zonesEvents = result[1];
expect(zonesEvents.length).toBeGreaterThan(0);
});

View File

@ -1,6 +1,7 @@
const app = require('vn-loopback/server/server');
describe('client sendSms()', () => {
// #2294 - TLS version error
xdescribe('client sendSms()', () => {
let createdLog;
afterAll(async done => {

View File

@ -1,7 +1,8 @@
const app = require('vn-loopback/server/server');
const soap = require('soap');
describe('sms send()', () => {
// #2294 - TLS version error
xdescribe('sms send()', () => {
it('should return the expected message and status code', async() => {
const code = 200;
const smsConfig = await app.models.SmsConfig.findOne();

View File

@ -1,6 +1,7 @@
const app = require('vn-loopback/server/server');
describe('ticket sendSms()', () => {
// #2294 - TLS version error
xdescribe('ticket sendSms()', () => {
let logId;
afterAll(async done => {

View File

@ -1,7 +1,8 @@
const app = require('vn-loopback/server/server');
const models = app.models;
describe('ticket deleted()', () => {
// 2296 Failing tests
xdescribe('ticket deleted()', () => {
let ticket;
let sale;
let deletedClaim;

View File

@ -4,19 +4,30 @@ const smtp = require('../core/smtp');
const config = require('../core/config');
module.exports = app => {
app.get('/api/closure', async function(request, response) {
app.get('/api/closure/by-ticket', async function(request, response) {
});
app.get('/api/closure/all', async function(request, response) {
response.status(200).json({
message: 'Task executed successfully'
});
const failedtickets = [];
const tickets = await db.rawSql(`
SELECT
t.id,
t.clientFk,
c.email recipient
c.email recipient,
c.isToBeMailed,
eu.email salesPersonEmail
FROM expedition e
JOIN ticket t ON t.id = e.ticketFk
JOIN client c ON c.id = t.clientFk
JOIN warehouse w ON w.id = t.warehouseFk AND hasComission
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
WHERE ts.code = 'PACKED'
JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission
JOIN ticketState ts ON ts.ticketFk = t.id
JOIN alertLevel al ON al.alertLevel = ts.alertLevel
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
WHERE al.code = 'PACKED'
AND DATE(t.shipped) BETWEEN DATE_ADD(CURDATE(), INTERVAL -2 DAY) AND CURDATE()
AND t.refFk IS NULL
GROUP BY e.ticketFk`);
@ -27,6 +38,21 @@ module.exports = app => {
ticketId: ticket.id
});
if (!ticket.salesPersonFk || !ticket.isToBeMailed) continue;
if (!ticket.recipient) {
const body = `No se ha podido enviar el albarán <strong>${ticket.id}</strong>
al cliente <strong>${ticket.clientFk}</strong> porque no tiene un email especificado.<br/><br/>
Para dejar de recibir esta notificación, asígnale un email o desactiva la notificación por email para este cliente.`;
smtp.send({
to: ticket.salesPersonEmail,
subject: 'No se ha podido enviar el albarán',
html: body
});
continue;
}
const args = {
ticketId: ticket.id,
recipientId: ticket.clientFk,
@ -45,7 +71,7 @@ module.exports = app => {
// Send email with failed tickets
if (failedtickets.length > 0) {
let body = 'This following tickets has failed:<br/><br/>';
let body = 'This following tickets have failed:<br/><br/>';
for (ticket of failedtickets) {
body += `Ticket: <strong>${ticket.id}</strong>
@ -54,13 +80,9 @@ module.exports = app => {
smtp.send({
to: config.app.reportEmail,
subject: '[API] Nightly ticket closure has failed',
subject: '[API] Nightly ticket closure report',
html: body
});
}
response.status(200).json({
message: 'Closure executed successfully'
});
});
};