Merge pull request '2631 - Notify claim status change to incomplete' (#596) from 2631-notify_incomplete into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #596
This commit is contained in:
commit
f5b95a0c4d
|
@ -1584,9 +1584,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
|
||||
|
|
|
@ -61,7 +61,8 @@
|
|||
"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",
|
||||
"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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue