Commit e826d5bc authored by Phyks (Lucas Verney)'s avatar Phyks (Lucas Verney)
Browse files

Fix initial amount

parent 0c01bf2d
Pipeline #72289 failed with stages
in 2 minutes and 20 seconds
......@@ -395,13 +395,14 @@ to be resynced, by an offset of ${balanceOffset}.`);
let retrievedAccount = accounts.find(acc => acc.accountNumber === account.accountNumber);
if (typeof retrievedAccount !== 'undefined') {
let realBalance = retrievedAccount.initialAmount;
const initialBalance = account.initialAmount || 0;
const realBalance = retrievedAccount.initialAmount || 0;
let kresusBalance = await account.computeBalance();
if (Math.abs(realBalance - kresusBalance) > 0.01) {
log.info(`Updating balance for account ${account.accountNumber}`);
account.initialAmount = account.initialAmount + realBalance - kresusBalance;
account.initialAmount = initialBalance + realBalance - kresusBalance;
await account.save();
}
} else {
......
......@@ -106,7 +106,7 @@ Account.prototype.computeBalance = async function computeBalance() {
today.isAfter(op.debitDate || op.date, 'day') &&
(op.type !== 'type.deferred_card' || this.type === 'account-type.card')
)
.reduce((sum, op) => sum + op.amount, this.initialAmount);
.reduce((sum, op) => sum + op.amount, this.initialAmount || 0);
return Math.round(s * 100) / 100;
};
......
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