Compare commits
15 Commits
8227-roadm
...
dev
Author | SHA1 | Date |
---|---|---|
Alex Moreno | 9d289fa11e | |
Alex Moreno | ded035285b | |
Alex Moreno | 05b383ecb0 | |
Sergio De la torre | 6f73758cad | |
Sergio De la torre | c50ff6a43a | |
Sergio De la torre | eee73f001d | |
Sergio De la torre | 7f17cd59e7 | |
Sergio De la torre | ef68884fe0 | |
Sergio De la torre | b5e27707a7 | |
Sergio De la torre | 0340612645 | |
Sergio De la torre | a1e1d4fa72 | |
Sergio De la torre | 12fa87a93c | |
Sergio De la torre | 05b8c3451a | |
Sergio De la torre | 2c672951c6 | |
Sergio De la torre | 31a6db5da0 |
|
@ -2749,13 +2749,13 @@ INSERT INTO `vn`.`roadmapAddress` (`addressFk`)
|
||||||
(3),
|
(3),
|
||||||
(4);
|
(4);
|
||||||
|
|
||||||
INSERT INTO `vn`.`roadmap` (`id`, `name`, `tractorPlate`, `trailerPlate`, `phone`, `supplierFk`, `etd`, `observations`, `editorFk`, `price`, `driverName`)
|
INSERT INTO `vn`.`roadmap` (`id`, `name`, `tractorPlate`, `trailerPlate`, `phone`, `supplierFk`, `etd`, `observations`, `userFk`, `price`, `driverName`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'val-algemesi', '1234-BCD', '9876-BCD', '111111111', 1, util.VN_NOW(), 'this is test observation', 1, 15, 'Batman'),
|
(1, 'val-algemesi', '1234-BCD', '9876-BCD', '111111111', 1, util.VN_NOW(), 'this is test observation', 1, 15, 'Batman'),
|
||||||
(2, 'alg-valencia', '2345-CDF', '8765-BCD', '111111111', 1, util.VN_NOW(), 'test observation', 1, 20, 'Robin'),
|
(2, 'alg-valencia', '2345-CDF', '8765-BCD', '111111111', 1, util.VN_NOW(), 'test observation', 1, 20, 'Robin'),
|
||||||
(3, 'alz-algemesi', '3456-DFG', '7654-BCD', '222222222', 2, DATE_ADD(util.VN_NOW(), INTERVAL 2 DAY), 'observations...', 2, 25, 'Driverman');
|
(3, 'alz-algemesi', '3456-DFG', '7654-BCD', '222222222', 2, DATE_ADD(util.VN_NOW(), INTERVAL 2 DAY), 'observations...', 2, 25, 'Driverman');
|
||||||
|
|
||||||
INSERT INTO `vn`.`roadmapStop` (`id`, `roadmapFk`, `addressFk`, `eta`, `description`, `editorFk`)
|
INSERT INTO `vn`.`roadmapStop` (`id`, `roadmapFk`, `addressFk`, `eta`, `description`, `userFk`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 1, 1, DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY), 'Best truck in fleet', 1),
|
(1, 1, 1, DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY), 'Best truck in fleet', 1),
|
||||||
(2, 1, 2, DATE_ADD(util.VN_NOW(), INTERVAL '1 2' DAY_HOUR), 'Second truck in fleet', 1),
|
(2, 1, 2, DATE_ADD(util.VN_NOW(), INTERVAL '1 2' DAY_HOUR), 'Second truck in fleet', 1),
|
||||||
|
|
|
@ -1,30 +1,17 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`vehicle_checkNumberPlate`(
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`vehicle_checkNumberPlate`(vNumberPlate VARCHAR(10), vCountryCodeFk VARCHAR(2))
|
||||||
vNumberPlate VARCHAR(10),
|
|
||||||
vCountryCodeFk VARCHAR(2)
|
|
||||||
)
|
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Comprueba si la matricula pasada tiene el formato
|
* Comprueba si la matricula pasada tiene el formato correcto dependiendo del pais del vehiculo
|
||||||
* correcto dependiendo del pais del vehiculo.
|
|
||||||
*
|
|
||||||
* @param vNumberPlate Número de matricula
|
|
||||||
* @param vCountryCodeFk Código de pais
|
|
||||||
*/
|
*/
|
||||||
DECLARE vRegex VARCHAR(45);
|
DECLARE vRegex VARCHAR(45);
|
||||||
|
|
||||||
IF vCountryCodeFk IS NULL THEN
|
SELECT vp.regex INTO vRegex
|
||||||
SET vRegex = '^[A-Z0-9 -]{6,12}$';
|
FROM vehiclePlateRegex vp
|
||||||
ELSE
|
WHERE vp.countryCodeFk = vCountryCodeFk;
|
||||||
SELECT regex INTO vRegex
|
|
||||||
FROM vehiclePlateRegex
|
|
||||||
WHERE countryCodeFk = vCountryCodeFk;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
IF NOT vNumberPlate REGEXP BINARY (vRegex)THEN
|
IF NOT vNumberPlate REGEXP BINARY (vRegex)THEN
|
||||||
CALL util.throw(CONCAT('La matricula ', vNumberPlate,
|
CALL util.throw(CONCAT('Error: la matricula ', vNumberPlate, ' no es valida para ',vCountryCodeFk));
|
||||||
' no es valida', IF(vCountryCodeFk IS NOT NULL,
|
|
||||||
CONCAT(' para ', vCountryCodeFk), '')));
|
|
||||||
END IF;
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -3,12 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeInser
|
||||||
BEFORE INSERT ON `roadmapStop`
|
BEFORE INSERT ON `roadmapStop`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
|
||||||
SET NEW.description = UCASE(NEW.description);
|
SET NEW.description = UCASE(NEW.description);
|
||||||
IF NEW.roadmapFk IS NOT NULL THEN
|
|
||||||
IF NEW.eta < (SELECT etd FROM roadmap WHERE id = NEW.roadmapFk) THEN
|
|
||||||
CALL util.throw('Departure time can not be after arrival time');
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -3,14 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeUpdat
|
||||||
BEFORE UPDATE ON `roadmapStop`
|
BEFORE UPDATE ON `roadmapStop`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
|
||||||
SET NEW.description = UCASE(NEW.description);
|
|
||||||
IF (NOT (NEW.roadmapFk <=> OLD.roadmapFk) AND NEW.roadmapFk IS NOT NULL)
|
|
||||||
OR (NOT (NEW.eta <=> OLD.eta) AND NEW.eta IS NOT NULL) THEN
|
|
||||||
|
|
||||||
IF NEW.eta < (SELECT etd FROM roadmap WHERE id = NEW.roadmapFk) THEN
|
SET NEW.description = UCASE(NEW.description);
|
||||||
CALL util.throw('Departure time can not be after arrival time');
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -3,12 +3,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_beforeInsert`
|
||||||
BEFORE INSERT ON `roadmap`
|
BEFORE INSERT ON `roadmap`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
IF NEW.driver1Fk IS NOT NULL THEN
|
||||||
IF NEW.tractorPlate IS NOT NULL THEN
|
SET NEW.driverName = (SELECT firstName FROM worker WHERE id = NEW.driver1Fk);
|
||||||
CALL vehicle_checkNumberPlate(NEW.tractorPlate, NULL);
|
ELSE
|
||||||
END IF;
|
SET NEW.driverName = NULL;
|
||||||
IF NEW.trailerPlate IS NOT NULL THEN
|
|
||||||
CALL vehicle_checkNumberPlate(NEW.trailerPlate, NULL);
|
|
||||||
END IF;
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -3,12 +3,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_beforeUpdate`
|
||||||
BEFORE UPDATE ON `roadmap`
|
BEFORE UPDATE ON `roadmap`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
IF NEW.driver1Fk IS NOT NULL THEN
|
||||||
IF NEW.tractorPlate IS NOT NULL THEN
|
SET NEW.driverName = (SELECT firstName FROM worker WHERE id = NEW.driver1Fk);
|
||||||
CALL vehicle_checkNumberPlate(NEW.tractorPlate, NULL);
|
ELSE
|
||||||
END IF;
|
SET NEW.driverName = NULL;
|
||||||
IF NEW.trailerPlate IS NOT NULL THEN
|
|
||||||
CALL vehicle_checkNumberPlate(NEW.trailerPlate, NULL);
|
|
||||||
END IF;
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -1,5 +0,0 @@
|
||||||
ALTER TABLE vn.roadmap
|
|
||||||
MODIFY COLUMN m3 int(10) unsigned DEFAULT NULL NULL COMMENT 'Capacidad máxima del remolque',
|
|
||||||
CHANGE driver1Fk driverFk int(10) unsigned DEFAULT NULL NULL COMMENT 'Conductor principal' AFTER driverName,
|
|
||||||
CHANGE driver2Fk codriverFk int(10) unsigned DEFAULT NULL NULL COMMENT 'Copiloto' AFTER driverFk,
|
|
||||||
CHANGE userFk editorFk int(10) unsigned DEFAULT NULL NULL AFTER m3;
|
|
|
@ -1 +0,0 @@
|
||||||
ALTER TABLE vn.roadmapStop CHANGE userFk editorFk int(10) unsigned DEFAULT NULL NULL;
|
|
|
@ -1,4 +0,0 @@
|
||||||
ALTER TABLE vn.route
|
|
||||||
ADD roadmapStopFk int(11) NULL,
|
|
||||||
ADD CONSTRAINT route_roadmapStop_FK FOREIGN KEY (roadmapStopFk) REFERENCES vn.roadmapStop(id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
|
||||||
CHANGE editorFk editorFk int(10) unsigned DEFAULT NULL NULL AFTER roadmapStopFk;
|
|
|
@ -238,25 +238,11 @@ describe('Ticket Edit sale path', () => {
|
||||||
await page.waitToClick(selectors.globalItems.cancelButton);
|
await page.waitToClick(selectors.globalItems.cancelButton);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should select the third sale and create a claim of it', async() => {
|
it('should select the third sale and delete it', async() => {
|
||||||
await page.accessToSearchResult('16');
|
|
||||||
await page.accessToSection('ticket.card.sale');
|
|
||||||
await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox);
|
|
||||||
await page.waitToClick(selectors.ticketSales.moreMenu);
|
|
||||||
await page.waitToClick(selectors.ticketSales.moreMenuCreateClaim);
|
|
||||||
await page.waitToClick(selectors.globalItems.acceptButton);
|
|
||||||
await page.waitForNavigation();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should search for a ticket then access to the sales section', async() => {
|
|
||||||
await page.goBack();
|
|
||||||
await page.goBack();
|
|
||||||
await page.loginAndModule('salesPerson', 'ticket');
|
await page.loginAndModule('salesPerson', 'ticket');
|
||||||
await page.accessToSearchResult('16');
|
await page.accessToSearchResult('16');
|
||||||
await page.accessToSection('ticket.card.sale');
|
await page.accessToSection('ticket.card.sale');
|
||||||
});
|
|
||||||
|
|
||||||
it('should select the third sale and delete it', async() => {
|
|
||||||
await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox);
|
await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox);
|
||||||
await page.waitToClick(selectors.ticketSales.deleteSaleButton);
|
await page.waitToClick(selectors.ticketSales.deleteSaleButton);
|
||||||
await page.waitToClick(selectors.globalItems.acceptButton);
|
await page.waitToClick(selectors.globalItems.acceptButton);
|
||||||
|
|
|
@ -75,7 +75,7 @@ describe('Ticket Edit basic data path', () => {
|
||||||
const result = await page
|
const result = await page
|
||||||
.waitToGetProperty(selectors.ticketBasicData.stepTwoTotalPriceDif, 'innerText');
|
.waitToGetProperty(selectors.ticketBasicData.stepTwoTotalPriceDif, 'innerText');
|
||||||
|
|
||||||
expect(result).toContain('-€228.25');
|
expect(result).toContain('-€111.75');
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should select a new reason for the changes made then click on finalize`, async() => {
|
it(`should select a new reason for the changes made then click on finalize`, async() => {
|
||||||
|
|
|
@ -211,7 +211,7 @@
|
||||||
"Name should be uppercase": "Name should be uppercase",
|
"Name should be uppercase": "Name should be uppercase",
|
||||||
"You cannot update these fields": "You cannot update these fields",
|
"You cannot update these fields": "You cannot update these fields",
|
||||||
"CountryFK cannot be empty": "Country cannot be empty",
|
"CountryFK cannot be empty": "Country cannot be empty",
|
||||||
"No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements",
|
"No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements",
|
||||||
"You are not allowed to modify the alias": "You are not allowed to modify the alias",
|
"You are not allowed to modify the alias": "You are not allowed to modify the alias",
|
||||||
"You already have the mailAlias": "You already have the mailAlias",
|
"You already have the mailAlias": "You already have the mailAlias",
|
||||||
"This machine is already in use.": "This machine is already in use.",
|
"This machine is already in use.": "This machine is already in use.",
|
||||||
|
@ -247,9 +247,11 @@
|
||||||
"ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}",
|
"ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}",
|
||||||
"The raid information is not correct": "The raid information is not correct",
|
"The raid information is not correct": "The raid information is not correct",
|
||||||
"Payment method is required": "Payment method is required",
|
"Payment method is required": "Payment method is required",
|
||||||
"Sales already moved": "Sales already moved",
|
|
||||||
"Holidays to past days not available": "Holidays to past days not available",
|
|
||||||
"Price cannot be blank": "Price cannot be blank",
|
"Price cannot be blank": "Price cannot be blank",
|
||||||
"There are tickets to be invoiced": "There are tickets to be invoiced",
|
"There are tickets to be invoiced": "There are tickets to be invoiced",
|
||||||
"The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent"
|
"The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent",
|
||||||
}
|
"Sales already moved": "Sales already moved",
|
||||||
|
"Holidays to past days not available": "Holidays to past days not available",
|
||||||
|
"Incorrect delivery order alert on route": "Incorrect delivery order alert on route: {{ route }} zone: {{ zone }}",
|
||||||
|
"Ticket has been delivered out of order": "The ticket {{ticket}} {{{fullUrl}}} has been delivered out of order."
|
||||||
|
}
|
|
@ -390,14 +390,11 @@
|
||||||
"The web user's email already exists": "El correo del usuario web ya existe",
|
"The web user's email already exists": "El correo del usuario web ya existe",
|
||||||
"Sales already moved": "Ya han sido transferidas",
|
"Sales already moved": "Ya han sido transferidas",
|
||||||
"The raid information is not correct": "La información de la redada no es correcta",
|
"The raid information is not correct": "La información de la redada no es correcta",
|
||||||
"No trips found because input coordinates are not connected": "No se encontraron rutas porque las coordenadas de entrada no están conectadas",
|
|
||||||
"This request is not supported": "Esta solicitud no es compatible",
|
|
||||||
"Invalid options or too many coordinates": "Opciones invalidas o demasiadas coordenadas",
|
|
||||||
"No address has coordinates": "Ninguna dirección tiene coordenadas",
|
|
||||||
"An item type with the same code already exists": "Un tipo con el mismo código ya existe",
|
"An item type with the same code already exists": "Un tipo con el mismo código ya existe",
|
||||||
"Holidays to past days not available": "Las vacaciones a días pasados no están disponibles",
|
"Holidays to past days not available": "Las vacaciones a días pasados no están disponibles",
|
||||||
"All tickets have a route order": "Todos los tickets tienen orden de ruta",
|
"All tickets have a route order": "Todos los tickets tienen orden de ruta",
|
||||||
"Price cannot be blank": "Price cannot be blank",
|
|
||||||
"There are tickets to be invoiced": "La zona tiene tickets por facturar",
|
"There are tickets to be invoiced": "La zona tiene tickets por facturar",
|
||||||
"Social name should be uppercase": "La razón social debe ir en mayúscula"
|
"Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}",
|
||||||
|
"Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden.",
|
||||||
|
"Price cannot be blank": "El precio no puede estar en blanco"
|
||||||
}
|
}
|
|
@ -362,9 +362,11 @@
|
||||||
"The invoices have been created but the PDFs could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré",
|
"The invoices have been created but the PDFs could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré",
|
||||||
"It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré",
|
"It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré",
|
||||||
"Cannot send mail": "Impossible d'envoyer le mail",
|
"Cannot send mail": "Impossible d'envoyer le mail",
|
||||||
"Original invoice not found": "Facture originale introuvable",
|
"Original invoice not found": "Facture originale introuvable",
|
||||||
"The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne",
|
"The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne",
|
||||||
"You do not have permission to modify the booked field": "Vous n'avez pas la permission de modifier le champ comptabilisé",
|
"You do not have permission to modify the booked field": "Vous n'avez pas la permission de modifier le champ comptabilisé",
|
||||||
"ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}",
|
"ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}",
|
||||||
"The web user's email already exists": "L'email de l'internaute existe déjà"
|
"The web user's email already exists": "L'email de l'internaute existe déjà",
|
||||||
}
|
"Incorrect delivery order alert on route": "Alerte de bon de livraison incorrect sur l'itinéraire: {{ route }} zone : {{ zone }}",
|
||||||
|
"Ticket has been delivered out of order": "Le ticket {{ticket}} {{{fullUrl}}} a été livré hors ordre."
|
||||||
|
}
|
|
@ -365,5 +365,7 @@
|
||||||
"Cannot send mail": "Não é possível enviar o email",
|
"Cannot send mail": "Não é possível enviar o email",
|
||||||
"The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha",
|
"The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha",
|
||||||
"ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}",
|
"ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}",
|
||||||
"The web user's email already exists": "O e-mail do utilizador da web já existe."
|
"The web user's email already exists": "O e-mail do utilizador da web já existe.",
|
||||||
}
|
"Incorrect delivery order alert on route": "Alerta de ordem de entrega incorreta na rota: {{ route }} zona: {{ zone }}",
|
||||||
|
"Ticket has been delivered out of order": "O ticket {{ticket}} {{{fullUrl}}} foi entregue fora de ordem."
|
||||||
|
}
|
|
@ -28,7 +28,6 @@ module.exports = Self => {
|
||||||
verb: 'POST'
|
verb: 'POST'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.saveSign = async(ctx, tickets, location, signedTime, options) => {
|
Self.saveSign = async(ctx, tickets, location, signedTime, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||||
|
@ -111,6 +110,12 @@ module.exports = Self => {
|
||||||
scope: {
|
scope: {
|
||||||
fields: ['id']
|
fields: ['id']
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relation: 'zone',
|
||||||
|
scope: {
|
||||||
|
fields: ['id', 'zoneFk,', 'name']
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
@ -151,6 +156,28 @@ module.exports = Self => {
|
||||||
|
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions);
|
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions);
|
||||||
|
|
||||||
|
if (stateCode == 'DELIVERED' && ticket.priority) {
|
||||||
|
const orderState = await models.State.findOne({
|
||||||
|
where: {code: 'DELIVERED'},
|
||||||
|
fields: ['id']
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const ticketIncorrect = await Self.rawSql(`
|
||||||
|
SELECT t.id
|
||||||
|
FROM ticket t
|
||||||
|
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||||
|
JOIN state s ON s.code = ts.code
|
||||||
|
WHERE t.routeFk = ?
|
||||||
|
AND s.\`order\` < ?
|
||||||
|
AND priority <(SELECT t.priority
|
||||||
|
FROM ticket t
|
||||||
|
WHERE t.id = ?)`
|
||||||
|
, [ticket.routeFk, orderState.id, ticket.id], myOptions);
|
||||||
|
|
||||||
|
if (ticketIncorrect?.length > 0)
|
||||||
|
await sendMail(ctx, ticket.routeFk, ticket.id, ticket.zone().name);
|
||||||
|
}
|
||||||
|
|
||||||
if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.$cmrFk) {
|
if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.$cmrFk) {
|
||||||
await models.Ticket.saveCmr(ctx, [ticketId], myOptions);
|
await models.Ticket.saveCmr(ctx, [ticketId], myOptions);
|
||||||
externalTickets.push(ticketId);
|
externalTickets.push(ticketId);
|
||||||
|
@ -163,4 +190,25 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
await models.Ticket.sendCmrEmail(ctx, externalTickets);
|
await models.Ticket.sendCmrEmail(ctx, externalTickets);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function sendMail(ctx, route, ticket, zoneName) {
|
||||||
|
const $t = ctx.req.__;
|
||||||
|
const url = await Self.app.models.Url.getUrl();
|
||||||
|
const sendTo = 'repartos@verdnatura.es';
|
||||||
|
const fullUrl = `${url}route/${route}/summary`;
|
||||||
|
const emailSubject = $t('Incorrect delivery order alert on route', {
|
||||||
|
route,
|
||||||
|
zone: zoneName
|
||||||
|
});
|
||||||
|
const emailBody = $t('Ticket has been delivered out of order', {
|
||||||
|
ticket,
|
||||||
|
fullUrl
|
||||||
|
});
|
||||||
|
|
||||||
|
await Self.app.models.Mail.create({
|
||||||
|
receiver: sendTo,
|
||||||
|
subject: emailSubject,
|
||||||
|
body: emailBody
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Ticket saveSign()', () => {
|
describe('Ticket saveSign()', () => {
|
||||||
let ctx = {req: {
|
let ctx = {req: {
|
||||||
getLocale: () => {
|
getLocale: () => {
|
||||||
return 'en';
|
return 'en';
|
||||||
},
|
},
|
||||||
|
__: () => {},
|
||||||
accessToken: {userId: 9}
|
accessToken: {userId: 9}
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: ctx
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it(`should throw error if the ticket's alert level is lower than 2`, async() => {
|
it(`should throw error if the ticket's alert level is lower than 2`, async() => {
|
||||||
const tx = await models.TicketDms.beginTransaction({});
|
const tx = await models.TicketDms.beginTransaction({});
|
||||||
|
@ -51,4 +59,46 @@ describe('Ticket saveSign()', () => {
|
||||||
|
|
||||||
expect(ticketTrackingAfter.name).toBe('Entregado en parte');
|
expect(ticketTrackingAfter.name).toBe('Entregado en parte');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should send an email to notify that the delivery order is not correct', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
const ticketFk = 8;
|
||||||
|
const priority = 5;
|
||||||
|
const stateFk = 10;
|
||||||
|
const stateTicketFk = 2;
|
||||||
|
const expeditionFk = 11;
|
||||||
|
const expeditionStateFK = 2;
|
||||||
|
|
||||||
|
let mailCountBefore;
|
||||||
|
let mailCountAfter;
|
||||||
|
spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 1}]);
|
||||||
|
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const tickets = [ticketFk];
|
||||||
|
|
||||||
|
const expedition = await models.Expedition.findById(expeditionFk, null, options);
|
||||||
|
expedition.updateAttribute('stateTypeFk', expeditionStateFK, options);
|
||||||
|
|
||||||
|
const ticket = await models.Ticket.findById(ticketFk, null, options);
|
||||||
|
ticket.updateAttribute('priority', priority, options);
|
||||||
|
|
||||||
|
const filter = {where: {
|
||||||
|
ticketFk: ticketFk,
|
||||||
|
stateFk: stateTicketFk}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const ticketTracking = await models.TicketTracking.findOne(filter, options);
|
||||||
|
ticketTracking.updateAttribute('stateFk', stateFk, options);
|
||||||
|
mailCountBefore = await models.Mail.count(options);
|
||||||
|
await models.Ticket.saveSign(ctx, tickets, null, null, options);
|
||||||
|
mailCountAfter = await models.Mail.count(options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(mailCountAfter).toBeGreaterThan(mailCountBefore);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "salix-back",
|
"name": "salix-back",
|
||||||
"version": "25.04.0",
|
"version": "25.06.0",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "Salix backend",
|
"description": "Salix backend",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
Loading…
Reference in New Issue