2094 Regularize claim send chat even if doesn't have destination
gitea/salix/2094-claim_send_chat This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-02-13 13:20:31 +01:00
parent fe91ca080e
commit 39470e837b
4 changed files with 28 additions and 27 deletions

View File

@ -36,7 +36,7 @@ module.exports = Self => {
relation: 'department'
}
});
const department = workerDepartment.department();
const department = workerDepartment && workerDepartment.department();
const channelName = department.chatName;
if (channelName)

View File

@ -61,7 +61,7 @@
"MESSAGE_BOUGHT_UNITS": "Bought {{quantity}} units of {{concept}} (#{{itemId}}) for the ticket id [#{{ticketId}}]({{{url}}})",
"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}}})",
"MESSAGE_CLAIM_ITEM_REGULARIZE": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to {{nickname}} coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})",
"Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})",
"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",
"Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}"

View File

@ -124,7 +124,7 @@
"MESSAGE_BOUGHT_UNITS": "Se ha comprado {{quantity}} unidades de {{concept}} (#{{itemId}}) para el ticket id [#{{ticketId}}]({{{url}}})",
"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}}})",
"MESSAGE_CLAIM_ITEM_REGULARIZE": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a {{nickname}} provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})",
"Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})",
"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"
}

View File

@ -37,27 +37,43 @@ module.exports = Self => {
for (let i = 0; i < claimEnds.length; i++) {
const claimEnd = claimEnds[i];
const destination = claimEnd.claimDestination();
const addressFk = destination && destination.addressFk;
const sale = await getSale(claimEnd.saleFk, options);
const addressId = destination && destination.addressFk;
if (!addressFk) continue;
let address;
if (addressId)
address = await models.Address.findById(addressId, null, options);
const salesPerson = sale.ticket().client().salesPerson();
if (salesPerson) {
const nickname = address && address.nickname || destination.description;
const origin = ctx.req.headers.origin;
const message = $t('Sent units from ticket', {
quantity: sale.quantity,
concept: sale.concept,
itemId: sale.itemFk,
ticketId: sale.ticketFk,
nickname: nickname,
ticketUrl: `${origin}/#!/ticket/${sale.ticketFk}/summary`,
itemUrl: `${origin}/#!/item/${sale.itemFk}/summary`
});
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
}
if (!address) continue;
let sale = await getSale(claimEnd.saleFk, options);
let ticketFk = await getTicketId({
addressFk: addressFk,
addressFk: addressId,
companyFk: sale.ticket().companyFk,
warehouseFk: sale.ticket().warehouseFk
}, options);
let address = await models.Address.findOne({
where: {id: addressFk}
}, options);
if (!ticketFk) {
ticketFk = await createTicket(ctx, {
clientId: address.clientFk,
warehouseId: sale.ticket().warehouseFk,
companyId: sale.ticket().companyFk,
addressId: addressFk
addressId: addressId
}, options);
}
@ -69,21 +85,6 @@ module.exports = Self => {
price: sale.price,
discount: 100
}, options);
const salesPerson = sale.ticket().client().salesPerson();
if (salesPerson) {
const origin = ctx.req.headers.origin;
const message = $t('MESSAGE_CLAIM_ITEM_REGULARIZE', {
quantity: sale.quantity,
concept: sale.concept,
itemId: sale.itemFk,
ticketId: sale.ticketFk,
nickname: address.nickname,
ticketUrl: `${origin}/#!/ticket/${sale.ticketFk}/summary`,
itemUrl: `${origin}/#!/item/${sale.itemFk}/summary`
});
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
}
}
let claim = await Self.findById(params.claimFk, null, options);