Commit d03afa63 authored by Nicolas Frandeboeuf's avatar Nicolas Frandeboeuf
Browse files

Alerts: add access name next to account's name (fix #719)

parent 7342ab6a
Pipeline #199983 passed with stages
in 8 minutes and 22 seconds
......@@ -37,11 +37,12 @@ ${$t('server.email.signature')}
async checkAlertsForOperations(userId, access, operations) {
try {
// Map account to names
let accessLabel = access.getLabel();
let accounts = await Accounts.byAccess(userId, access);
let accountsMap = new Map();
for (let a of accounts) {
accountsMap.set(a.id, {
label: displayLabel(a),
label: `${accessLabel}${displayLabel(a)}`,
formatCurrency: await a.getCurrencyFormatter()
});
}
......@@ -91,6 +92,7 @@ ${$t('server.email.signature')}
async checkAlertsForAccounts(userId, access) {
try {
let accounts = await Accounts.byAccess(userId, access);
let accessLabel = access.getLabel();
for (let account of accounts) {
let alerts = await Alerts.byAccountAndType(userId, account.id, 'balance');
if (!alerts) {
......@@ -106,7 +108,7 @@ ${$t('server.email.signature')}
// Set the currency formatter
let formatCurrency = await account.getCurrencyFormatter();
let text = alert.formatAccountMessage(
displayLabel(account),
`${accessLabel}${displayLabel(account)}`,
balance,
formatCurrency
);
......
......@@ -10,6 +10,7 @@ import {
import Emailer from './emailer';
import Accesses from '../models/accesses';
import Accounts from '../models/accounts';
import Alerts from '../models/alerts';
import Transactions from '../models/transactions';
......@@ -112,7 +113,12 @@ class ReportManager {
}
if (count) {
let email = await this.getTextContent(accounts, operationsByAccount, frequencyKey);
let email = await this.getTextContent(
userId,
accounts,
operationsByAccount,
frequencyKey
);
let { subject, content } = email;
......@@ -128,7 +134,7 @@ class ReportManager {
}
}
async getTextContent(accounts, operationsByAccount, frequencyKey) {
async getTextContent(userId, accounts, operationsByAccount, frequencyKey) {
let frequency;
switch (frequencyKey) {
case 'daily':
......@@ -152,10 +158,17 @@ class ReportManager {
content += $t('server.email.report.pre', { today });
content += '\n';
let accountsNameMap = new Map();
for (let account of accounts) {
if (!accountsNameMap.has(account.id)) {
let access = await Accesses.find(userId, account.accessId);
accountsNameMap.set(account.id, `${access.getLabel()}${displayLabel(account)}`);
}
let lastCheckDate = formatDate.toShortString(account.lastCheckDate);
let balance = await account.computeBalance();
content += `\t* ${displayLabel(account)} : `;
content += `\t* ${accountsNameMap.get(account.id)} : `;
content += `${account.formatCurrency(balance)} (`;
content += $t('server.email.report.last_sync');
content += ` ${lastCheckDate})\n`;
......@@ -179,7 +192,7 @@ class ReportManager {
return 1;
});
content += `\n${displayLabel(pair.account)}:\n`;
content += `\n${accountsNameMap.get(pair.account.id)}:\n`;
for (let op of operations) {
let date = formatDate.toShortString(op.date);
content += `\t* ${date} - ${op.label} : `;
......
import * as cozydb from 'cozydb';
import AccessFields from './access-fields';
import { bankVendorByUuid } from '../../lib/bank-vendors';
import { assert, makeLogger, promisify, promisifyModel, FETCH_STATUS_SUCCESS } from '../../helpers';
......@@ -153,4 +154,13 @@ Access.prototype.canBePolled = function() {
);
};
// Returns the access name
Access.prototype.getLabel = function() {
if (this.customLabel) {
return this.customLabel;
}
return bankVendorByUuid(this.vendorId).name;
};
module.exports = Access;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment