feat: refs #7921 sendExpeditionLost
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Sergio De la torre 2024-10-24 10:56:30 +02:00
parent 7ae99fe6a1
commit cc6585115f
6 changed files with 65 additions and 27 deletions

View File

@ -241,5 +241,6 @@
"The height must be greater than 50cm": "The height must be greater than 50cm",
"The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm",
"The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line",
"There are tickets for this area, delete them first": "There are tickets for this area, delete them first"
"There are tickets for this area, delete them first": "There are tickets for this area, delete them first",
"ticketLostExpeditions": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expeditions :{{ expeditionsId }}"
}

View File

@ -384,5 +384,6 @@
"No valid travel thermograph found": "No se encontró un termógrafo válido",
"The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea",
"type cannot be blank": "Se debe rellenar el tipo",
"There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero"
"There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero",
"ticketLostExpeditions": "El ticket [{{ticketId}}]({{{ticketUrl}}}) tiene las siguientes expediciones perdidas :{{ expeditionsId }}"
}

View File

@ -123,7 +123,7 @@
"Added sale to ticket": "J'ai ajouté la ligne suivante au ticket [{{ticketId}}]({{{ticketUrl}}}): {{{addition}}}",
"Changed sale discount": "J'ai changé le rabais des lignes suivantes du ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}",
"Created claim": "J'ai créé la réclamation [{{claimId}}]({{{claimUrl}}}) des lignes suivantes du ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}",
"Changed sale price": " le prix de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* du ticket [{{ticketId}}]({{{ticketUrl}}})",,
"Changed sale price": " le prix de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* du ticket [{{ticketId}}]({{{ticketUrl}}})",
"Changed sale quantity": "J'ai changé {{changes}} du ticket [{{ticketId}}]({{{ticketUrl}}})",
"Changes in sales": "la quantité de {{itemId}} {{concept}} de {{oldQuantity}} ➔ {{newQuantity}}",
"State": "État",
@ -363,5 +363,6 @@
"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",
"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",
"ticketLostExpeditions": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a les expéditions perdues suivantes :{{ expeditionsId }}"
}

View File

@ -363,5 +363,6 @@
"It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso",
"Original invoice not found": "Fatura original não encontrada",
"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",
"ticketLostExpeditions": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem as seguintes expedições perdidas:{{ expeditionsId }}"
}

View File

@ -37,6 +37,7 @@ module.exports = Self => {
let dms;
let isSignUploaded;
let externalTickets = [];
const $t = ctx.req.__;
if (typeof options == 'object')
Object.assign(myOptions, options);
@ -111,6 +112,12 @@ module.exports = Self => {
scope: {
fields: ['id']
}
},
{
relation: 'client',
scope: {
fields: ['salesPersonFk']
}
}]
}, myOptions);
@ -140,17 +147,41 @@ module.exports = Self => {
await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions);
await ticket.updateAttribute('isSigned', true, myOptions);
const [{stateCode}] = await Self.rawSql(`
const ticketStateExpeditions = await Self.rawSql(`
WITH expeditionsLost AS (
SELECT e.id
FROM vn.expedition e
JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk
WHERE e.ticketFk = ? AND est.code = 'LOST'
),ticketStateCode AS (
SELECT
IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)),
'DELIVERED', 'PARTIAL_DELIVERED') stateCode
FROM vn.expedition e
JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk
WHERE e.ticketFk = ?;
`, [ticketId], myOptions);
WHERE e.ticketFk = ?
)
SELECT el.id, ts.stateCode
FROM ticketStateCode ts
LEFT JOIN expeditionsLost el ON TRUE;
`, [ticketId, ticketId], myOptions);
const stateCode = ticketStateExpeditions[0]?.stateCode;
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions);
const expeditionsIds = ticketStateExpeditions.map(result => result.id).filter(id => id !== null);
const url = await Self.app.models.Url.getUrl();
expeditionsIds.length
&& ticket.client()?.salesPersonFk
&& await models.Chat.sendCheckingPresence(ctx, ticket.client().salesPersonFk,
$t('ticketLostExpeditions', {
ticketId: ticket.id,
ticketUrl: `${url}ticket/${ticket.id}/expedition`,
expeditionsId: expeditionsIds
})
);
if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.cmrFk) {
await models.Ticket.saveCmr(ctx, [ticketId], myOptions);
externalTickets.push(ticketId);

View File

@ -1,11 +1,14 @@
const models = require('vn-loopback/server/server').models;
describe('Ticket saveSign()', () => {
let ctx = {req: {
let ctx = {
req: {
getLocale: () => {
return 'en';
},
accessToken: {userId: 9}
accessToken: {userId: 9},
headers: {origin: 'http://localhost'},
__: value => value
}};
it(`should throw error if the ticket's alert level is lower than 2`, async() => {