fix: refs #7025 check if has the same value & gets userFk
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
63993a7c65
commit
f33641eb2c
|
@ -3787,3 +3787,7 @@ INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk)
|
||||||
INSERT INTO vn.workerTeam(id, team, workerFk)
|
INSERT INTO vn.workerTeam(id, team, workerFk)
|
||||||
VALUES
|
VALUES
|
||||||
(8, 1, 19);
|
(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);
|
|
@ -22,16 +22,20 @@ module.exports = Self => {
|
||||||
const changes = ctx.data || ctx.instance;
|
const changes = ctx.data || ctx.instance;
|
||||||
const orgData = ctx.currentInstance;
|
const orgData = ctx.currentInstance;
|
||||||
const {isConfirmed} = await models.Entry.findById(orgData.entryFk, {fields: ['isConfirmed']});
|
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) {
|
if (isConfirmed && entryLog?.userFk) {
|
||||||
const {name, lang} = await models.VnUser.findById(orgData.editorFk, {fields: ['name', 'lang']});
|
const {name, lang} = await models.VnUser.findById(entryLog.userFk, {fields: ['name', 'lang']});
|
||||||
const to = `@${name}`;
|
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
|
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)) {
|
for (let [key, value] of Object.entries(changes)) {
|
||||||
if (key === 'printedStickers') continue;
|
if (key === 'printedStickers' || orgData[key] === value) continue;
|
||||||
|
|
||||||
if (datePattern.test(value)) {
|
if (datePattern.test(value)) {
|
||||||
const date = new Date(value);
|
const date = new Date(value);
|
||||||
|
@ -39,9 +43,12 @@ module.exports = Self => {
|
||||||
value += ` ${date.toLocaleTimeString('es-ES')}`;
|
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`;
|
message += `${field}: ${value}\n`;
|
||||||
}
|
}
|
||||||
|
if (!message) return;
|
||||||
|
|
||||||
|
message = `**${locale[lang].name} changes**:\n${message}`;
|
||||||
ctx.req = loopbackContext.active;
|
ctx.req = loopbackContext.active;
|
||||||
await models.Chat.send(ctx, to, message);
|
await models.Chat.send(ctx, to, message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue