Compare commits

...

6 Commits

Author SHA1 Message Date
Jorge Penadés f33641eb2c fix: refs #7025 check if has the same value & gets userFk
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-04-24 13:14:24 +02:00
Jorge Penadés 63993a7c65 fix: refs #7025 bold title
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-04-24 10:21:53 +02:00
Jorge Penadés 5c4259aec3 Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 7025-NotifyOnSave
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-04-24 10:13:57 +02:00
Jorge Penadés aad69d9a24 feat: refs #7025 observe buy changes
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-04-23 17:27:09 +02:00
Jorge Penadés f087a2c318 fix: refs #7025 rollback
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-04-23 16:59:22 +02:00
Jorge Penadés d94f37f1f9 feat: refs #7025 notify changes on save
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-04-23 13:36:25 +02:00
3 changed files with 57 additions and 1 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

@ -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"
}

View File

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