From d4c6695629033100a426e8960f2e9fac334dcae1 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 7 Apr 2021 07:45:00 +0200 Subject: [PATCH 1/2] 2631 - Notify status change to incomplete --- db/dump/fixtures.sql | 4 +- loopback/locale/en.json | 2 +- loopback/locale/es.json | 3 +- .../claim/back/methods/claim/updateClaim.js | 52 +++++++++++++++---- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index e999884108..a9ebb9e29a 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1579,9 +1579,9 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`) ( 2, 'managed', 'Gestionado', 1, 5), ( 3, 'resolved', 'Resuelto', 72, 7), ( 4, 'canceled', 'Anulado', 72, 6), - ( 5, 'disputed', 'Cuestionado', 72, 3), + ( 5, 'incomplete', 'Incompleta', 72, 3), ( 6, 'mana', 'Mana', 1, 4), - ( 7, 'inProgress', 'En Curso', 1, 2); + ( 7, 'lack', 'Faltas', 1, 2); INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `observation`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created` ) VALUES diff --git a/loopback/locale/en.json b/loopback/locale/en.json index c147e6c105..aa7e956782 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -61,7 +61,7 @@ "MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} ({{clientId}})]({{{url}}}) to *{{credit}} €*", "MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} ({{clientId}})]({{{url}}})", "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} ({{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [{{ticketId}}]({{{ticketUrl}}})", - "Claim will be picked": "The product from the claim ({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked", + "Claim will be picked": "The product from the claim [({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked", "This ticket is not an stowaway anymore": "The ticket id [{{ticketId}}]({{{ticketUrl}}}) is not an stowaway anymore", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 79ebc1e54b..b113655776 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -125,7 +125,8 @@ "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} ({{clientId}})]({{{url}}}) a *{{credit}} €*", "MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} ({{clientId}})]({{{url}}})", "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} ({{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})", - "Claim will be picked": "Se recogerá el género de la reclamación ({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", + "Claim will be picked": "Se recogerá el género de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", + "Claim state has changed to incomplete": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *incompleta*", "This ticket is not an stowaway anymore": "El ticket id [{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón", "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 02515ed668..68df9481c6 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -43,7 +43,6 @@ module.exports = Self => { const models = Self.app.models; const userId = ctx.req.accessToken.userId; const args = ctx.args; - const $t = ctx.req.__; // $translate let tx; let myOptions = {}; @@ -66,10 +65,14 @@ module.exports = Self => { } } }, myOptions); + // Get sales person from claim client + const salesPerson = claim.client().salesPersonUser(); + let changedHasToPickUp = false; if (args.hasToPickUp) changedHasToPickUp = true; + // Validate when claimState has been changed if (args.claimStateFk) { const canUpdate = await canChangeState(ctx, claim.claimStateFk, myOptions); const hasRights = await canChangeState(ctx, args.claimStateFk, myOptions); @@ -78,18 +81,20 @@ module.exports = Self => { if (!canUpdate || !hasRights || changedHasToPickUp && !isClaimManager) throw new UserError(`You don't have enough privileges to change that field`); } + delete args.ctx; const updatedClaim = await claim.updateAttributes(args, myOptions); - // Get sales person from claim client - const salesPerson = claim.client().salesPersonUser(); - if (salesPerson && changedHasToPickUp && updatedClaim.hasToPickUp) { - const origin = ctx.req.headers.origin; - const message = $t('Claim will be picked', { - claimId: claim.id, - clientName: claim.client().name, - claimUrl: `${origin}/#!/claim/${claim.id}/summary` - }); - await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); + + // When hasToPickUp has been changed + if (salesPerson && changedHasToPickUp && updatedClaim.hasToPickUp) + notifyPickUp(ctx, salesPerson.id, claim); + + // When claimState has been changed + if (args.claimStateFk) { + const newState = await models.ClaimState.findById(args.claimStateFk, null, options); + + if (newState.code == 'incomplete') + notifyStateChange(ctx, salesPerson.id, claim); } if (tx) await tx.commit(); @@ -115,4 +120,29 @@ module.exports = Self => { return canUpdate; } + + async function notifyStateChange(ctx, workerId, claim) { + const origin = ctx.req.headers.origin; + const models = Self.app.models; + const $t = ctx.req.__; // $translate + const message = $t('Claim state has changed to incomplete', { + claimId: claim.id, + clientName: claim.client().name, + claimUrl: `${origin}/#!/claim/${claim.id}/summary` + }); + await models.Chat.sendCheckingPresence(ctx, workerId, message); + } + + async function notifyPickUp(ctx, workerId, claim) { + const origin = ctx.req.headers.origin; + const models = Self.app.models; + const $t = ctx.req.__; // $translate + + const message = $t('Claim will be picked', { + claimId: claim.id, + clientName: claim.client().name, + claimUrl: `${origin}/#!/claim/${claim.id}/summary` + }); + await models.Chat.sendCheckingPresence(ctx, workerId, message); + } }; From 1a572ae256cd832e94a2a168d2f08086764932d8 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 7 Apr 2021 11:25:13 +0200 Subject: [PATCH 2/2] Added english translation --- loopback/locale/en.json | 1 + 1 file changed, 1 insertion(+) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index aa7e956782..f9fe404889 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -62,6 +62,7 @@ "MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} ({{clientId}})]({{{url}}})", "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} ({{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [{{ticketId}}]({{{ticketUrl}}})", "Claim will be picked": "The product from the claim [({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked", + "Claim state has changed to incomplete": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *incomplete*", "This ticket is not an stowaway anymore": "The ticket id [{{ticketId}}]({{{ticketUrl}}}) is not an stowaway anymore", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member",