fix: refs #7025 check if has the same value & gets userFk
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-04-24 13:14:24 +02:00
parent 63993a7c65
commit f33641eb2c
2 changed files with 16 additions and 5 deletions

View File

@ -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);

View File

@ -22,16 +22,20 @@ module.exports = Self => {
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 && orgData.editorFk) {
const {name, lang} = await models.VnUser.findById(orgData.editorFk, {fields: ['name', 'lang']});
if (isConfirmed && entryLog?.userFk) {
const {name, lang} = await models.VnUser.findById(entryLog.userFk, {fields: ['name', 'lang']});
const to = `@${name}`;
let message = `**${locale[lang].name} changes**:\n`;
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') continue;
if (key === 'printedStickers' || orgData[key] === value) continue;
if (datePattern.test(value)) {
const date = new Date(value);
@ -39,9 +43,12 @@ module.exports = Self => {
value += ` ${date.toLocaleTimeString('es-ES')}`;
}
const field = lang ? locale[lang].columns[key] : key;
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);
}