Compare commits
6 Commits
dev
...
7025-Notif
Author | SHA1 | Date |
---|---|---|
Jorge Penadés | f33641eb2c | |
Jorge Penadés | 63993a7c65 | |
Jorge Penadés | 5c4259aec3 | |
Jorge Penadés | aad69d9a24 | |
Jorge Penadés | f087a2c318 | |
Jorge Penadés | d94f37f1f9 |
|
@ -3787,3 +3787,7 @@ INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk)
|
|||
INSERT INTO vn.workerTeam(id, team, workerFk)
|
||||
VALUES
|
||||
(8, 1, 19);
|
||||
|
||||
INSERT INTO vn.entryLog (id, originFk, userFk, `action`, creationDate, description, changedModel, oldInstance, newInstance, changedModelId, changedModelValue)
|
||||
VALUES
|
||||
(1, 1, 1, 'insert', '2024-02-23 04:35:40.000', NULL, 'Entry', NULL, '{"id":1,"supplierFk":1,"dated":null,"invoiceNumber":"IN2001","isBooked":false,"isExcludedFromAvailable":false,"isConfirmed":true,"isOrdered":false,"isRaid":false,"commission":0.0,"created":"2000-12-01T00:00:00.000Z","evaNotes":"","travelFk":1,"currencyFk":1,"companyFk":442,"gestDocFk":null,"invoiceInFk":null,"isBlocked__":false,"loadPriority":null,"kop":null,"sub":null,"pro":null,"auction":null,"invoiceAmount":null,"buyerFk":null,"typeFk":null,"reference":"Movement 1","observationEditorFk":null,"clonedFrom":null,"editorFk":100,"lockerUserFk":null,"locked":"2024-04-24T12:20:01.000Z"}', 325789, NULL);
|
|
@ -353,5 +353,6 @@
|
|||
"This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario",
|
||||
"They're not your subordinate": "No es tu subordinado/a.",
|
||||
"No results found": "No se han encontrado resultados",
|
||||
"InvoiceIn is already booked": "La factura recibida está contabilizada"
|
||||
"InvoiceIn is already booked": "La factura recibida está contabilizada",
|
||||
"Grouping cannot be zero": "Grouping cannot be zero"
|
||||
}
|
|
@ -1,5 +1,56 @@
|
|||
const LoopBackContext = require('loopback-context');
|
||||
const yaml = require('js-yaml');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const locale = {
|
||||
es: yaml.load(fs.readFileSync(path.join(__dirname, '../locale/buy/es.yml'))),
|
||||
en: yaml.load(fs.readFileSync(path.join(__dirname, '../locale/buy/en.yml'))),
|
||||
|
||||
};
|
||||
|
||||
module.exports = Self => {
|
||||
require('../methods/entry/editLatestBuys')(Self);
|
||||
require('../methods/entry/latestBuysFilter')(Self);
|
||||
require('../methods/entry/deleteBuys')(Self);
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
const models = Self.app.models;
|
||||
const loopbackContext = LoopBackContext.getCurrentContext();
|
||||
|
||||
if (ctx.isNewInstance) return;
|
||||
|
||||
const changes = ctx.data || ctx.instance;
|
||||
const orgData = ctx.currentInstance;
|
||||
const {isConfirmed} = await models.Entry.findById(orgData.entryFk, {fields: ['isConfirmed']});
|
||||
const entryLog = await models.EntryLog.findOne({
|
||||
fields: ['userFk'],
|
||||
where: {originFk: orgData.entryFk, changedModel: 'Entry', action: 'insert'}
|
||||
});
|
||||
|
||||
if (isConfirmed && entryLog?.userFk) {
|
||||
const {name, lang} = await models.VnUser.findById(entryLog.userFk, {fields: ['name', 'lang']});
|
||||
const to = `@${name}`;
|
||||
|
||||
let message = '';
|
||||
const datePattern = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(.\d{3})?Z)?$/; // ISO Date
|
||||
|
||||
for (let [key, value] of Object.entries(changes)) {
|
||||
if (key === 'printedStickers' || orgData[key] === value) continue;
|
||||
|
||||
if (datePattern.test(value)) {
|
||||
const date = new Date(value);
|
||||
value = date.toLocaleDateString('es-ES');
|
||||
value += ` ${date.toLocaleTimeString('es-ES')}`;
|
||||
}
|
||||
|
||||
const field = lang ? locale[lang].columns[key] ?? key : key;
|
||||
message += `${field}: ${value}\n`;
|
||||
}
|
||||
if (!message) return;
|
||||
|
||||
message = `**${locale[lang].name} changes**:\n${message}`;
|
||||
ctx.req = loopbackContext.active;
|
||||
await models.Chat.send(ctx, to, message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue