feat: solo añade los logs de salix con el model 'Sale'
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
d15e2551a2
commit
1588492f9a
|
@ -66,7 +66,8 @@
|
|||
"MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} ({{clientId}})]({{{url}}}) to *{{credit}} €*",
|
||||
"Changed client 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",
|
||||
"Change quantity": "{{concept}} change of {{oldQuantity}} to {{newQuantity}}",
|
||||
"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*",
|
||||
"Claim state has changed to canceled": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *canceled*",
|
||||
"Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member",
|
||||
|
|
|
@ -134,7 +134,8 @@
|
|||
"MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} ({{clientId}})]({{{url}}}) a *{{credit}} €*",
|
||||
"Changed client 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}}*",
|
||||
"Change quantity": "{{concept}} cambia de {{oldQuantity}} a {{newQuantity}}",
|
||||
"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*",
|
||||
"Claim state has changed to canceled": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *anulado*",
|
||||
"Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}",
|
||||
|
|
|
@ -22,29 +22,42 @@ module.exports = Self => {
|
|||
Self.getChanges = async(ctx, id, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
const $t = ctx.req.__; // $translate
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const ticketLogs = await models.TicketLog.find({where: {originFk: id}}, myOptions);
|
||||
const ticketLogs = await models.TicketLog.find(
|
||||
{
|
||||
where: {
|
||||
and: [
|
||||
{originFk: id},
|
||||
{action: 'update'},
|
||||
{changedModel: 'Sale'}
|
||||
]
|
||||
},
|
||||
fields: [
|
||||
'oldInstance',
|
||||
'newInstance',
|
||||
'changedModelId'
|
||||
],
|
||||
}, myOptions);
|
||||
|
||||
const changes = [];
|
||||
for (const ticketLog of ticketLogs) {
|
||||
const isUpdate = ticketLog.action == 'update';
|
||||
const oldQuantity = ticketLog.oldInstance.quantity;
|
||||
const newQuantity = ticketLog.newInstance.quantity;
|
||||
|
||||
if (ticketLog.description && isUpdate)
|
||||
changes.push(ticketLog.description);
|
||||
|
||||
const oldQuantity = ticketLog.oldInstance ? ticketLog.oldInstance.quantity : null;
|
||||
const newQuantity = ticketLog.newInstance ? ticketLog.newInstance.quantity : null;
|
||||
|
||||
if (ticketLog.changedModel == 'Sale' && isUpdate && ticketLog.newInstance.quantity) {
|
||||
if (oldQuantity || newQuantity) {
|
||||
const sale = await models.Sale.findById(ticketLog.changedModelId, null, myOptions);
|
||||
changes.push(`${sale.concept} cambia de ${oldQuantity} a ${newQuantity}`);
|
||||
}
|
||||
const message = $t('Change quantity', {
|
||||
concept: sale.concept,
|
||||
oldQuantity: oldQuantity || 0,
|
||||
newQuantity: newQuantity || 0,
|
||||
});
|
||||
|
||||
if (ticketLog.changedModel == 'Ticket' && isUpdate && ticketLog.newInstance.quantity)
|
||||
changes.push(`${ticketLog.oldInstance.concept} cambia de ${oldQuantity} a ${newQuantity}`);
|
||||
changes.push(message);
|
||||
}
|
||||
}
|
||||
return changes.join('\n');
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue