WIP: feat: refs #7921 sendExpeditionLost #3145

Closed
sergiodt wants to merge 1 commits from 7921-sendLostExpeditions into dev
6 changed files with 65 additions and 27 deletions
Showing only changes of commit cc6585115f - Show all commits

View File

@ -240,6 +240,7 @@
"There is already a tray with the same height": "There is already a tray with the same height", "There is already a tray with the same height": "There is already a tray with the same height",
"The height must be greater than 50cm": "The height must be greater than 50cm", "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 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", "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", "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", "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", "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,8 +123,8 @@
"Added sale to ticket": "J'ai ajouté la ligne suivante au ticket [{{ticketId}}]({{{ticketUrl}}}): {{{addition}}}", "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}}}", "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}}}", "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}}})", "Changed sale quantity": "J'ai changé {{changes}} du ticket [{{ticketId}}]({{{ticketUrl}}})",
"Changes in sales": "la quantité de {{itemId}} {{concept}} de {{oldQuantity}} ➔ {{newQuantity}}", "Changes in sales": "la quantité de {{itemId}} {{concept}} de {{oldQuantity}} ➔ {{newQuantity}}",
"State": "État", "State": "État",
"regular": "normal", "regular": "normal",
@ -362,6 +362,7 @@
"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",
} "ticketLostExpeditions": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a les expéditions perdues suivantes :{{ expeditionsId }}"
}

View File

@ -124,7 +124,7 @@
"Changed sale discount": "Desconto da venda alterado no ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Changed sale discount": "Desconto da venda alterado no ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}",
"Created claim": "Reclamação criada [{{claimId}}]({{{claimUrl}}}) no ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Created claim": "Reclamação criada [{{claimId}}]({{{claimUrl}}}) no ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}",
"Changed sale price": "Preço da venda alterado para [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* no ticket [{{ticketId}}]({{{ticketUrl}}})", "Changed sale price": "Preço da venda alterado para [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* no ticket [{{ticketId}}]({{{ticketUrl}}})",
"Changed sale quantity": "Quantidade da venda alterada para {{changes}} no ticket [{{ticketId}}]({{{ticketUrl}}})", "Changed sale quantity": "Quantidade da venda alterada para {{changes}} no ticket [{{ticketId}}]({{{ticketUrl}}})",
"Changes in sales": " [{{itemId}} {{concept}}]({{{itemUrl}}}) de {{oldQuantity}} ➔ *{{newQuantity}}* ", "Changes in sales": " [{{itemId}} {{concept}}]({{{itemUrl}}}) de {{oldQuantity}} ➔ *{{newQuantity}}* ",
"State": "Estado", "State": "Estado",
"regular": "normal", "regular": "normal",
@ -361,7 +361,8 @@
"It was not able to create the invoice": "Não foi possível criar a fatura", "It was not able to create the invoice": "Não foi possível criar a fatura",
"The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado", "The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado",
"It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso", "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", "Original invoice not found": "Fatura original não encontrada",
"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",
} "ticketLostExpeditions": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem as seguintes expedições perdidas:{{ expeditionsId }}"
}

View File

@ -37,6 +37,7 @@ module.exports = Self => {
let dms; let dms;
let isSignUploaded; let isSignUploaded;
let externalTickets = []; let externalTickets = [];
const $t = ctx.req.__;
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
@ -111,6 +112,12 @@ module.exports = Self => {
scope: { scope: {
fields: ['id'] fields: ['id']
} }
},
{
relation: 'client',
scope: {
fields: ['salesPersonFk']
}
}] }]
}, myOptions); }, myOptions);
@ -140,17 +147,41 @@ module.exports = Self => {
await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions); await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions);
await ticket.updateAttribute('isSigned', true, myOptions); await ticket.updateAttribute('isSigned', true, myOptions);
const [{stateCode}] = await Self.rawSql(` const ticketStateExpeditions = await Self.rawSql(`
SELECT WITH expeditionsLost AS (
IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), SELECT e.id
'DELIVERED','PARTIAL_DELIVERED') stateCode
FROM vn.expedition e FROM vn.expedition e
JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk
WHERE e.ticketFk = ?; WHERE e.ticketFk = ? AND est.code = 'LOST'
`, [ticketId], myOptions); ),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 = ?
)
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); 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) { 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);

View File

@ -1,12 +1,15 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('Ticket saveSign()', () => { describe('Ticket saveSign()', () => {
let ctx = {req: { let ctx = {
getLocale: () => { req: {
return 'en'; 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() => { 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({});