Skip to content

Commit

Permalink
fix eval for new operations
Browse files Browse the repository at this point in the history
  • Loading branch information
lelemm committed Nov 26, 2024
1 parent 7b2d299 commit 0c0ea50
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
15 changes: 12 additions & 3 deletions packages/loot-core/src/server/accounts/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,19 @@ export class Condition {
}

case 'onBudget':
if (!object._account) {
return false;
}

return object._account.offbudget === 0;

case 'offBudget':
//both has no value, just the operation
return true;

if (!object._account) {
return false;
}

return object._account.offbudget === 1;

default:
}

Expand Down
9 changes: 8 additions & 1 deletion packages/loot-core/src/server/accounts/transaction-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../../types/models';
import { schemaConfig } from '../aql';
import * as db from '../db';
import { getPayee, getPayeeByName, insertPayee } from '../db';
import { getPayee, getPayeeByName, insertPayee, getAccount } from '../db';
import { getMappings } from '../db/mappings';
import { RuleError } from '../errors';
import { requiredFields, toDateRepr } from '../models';
Expand Down Expand Up @@ -855,6 +855,13 @@ export async function prepareTransactionForRules(
}
}

if (trans.account) {
const account = await getAccount(trans.account);
if (account) {
r._account = account;
}
}

return r;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/loot-core/src/server/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ export async function getPayee(id) {
return first(`SELECT * FROM payees WHERE id = ?`, [id]);
}

export async function getAccount(id) {
return first(`SELECT * FROM accounts WHERE id = ?`, [id]);
}

export async function insertPayee(payee) {
payee = payeeModel.validate(payee);
let id;
Expand Down
1 change: 1 addition & 0 deletions packages/loot-core/src/types/models/transaction.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export interface TransactionEntity {
subtransactions?: TransactionEntity[];
_unmatched?: boolean;
_deleted?: boolean;
_account?: AccountEntity;
}

0 comments on commit 0c0ea50

Please sign in to comment.