Allow entering transactions with mixed commodities of equal cost

This commit is contained in:
RunasSudo 2025-06-09 18:55:20 +10:00
parent f97420b055
commit 1fe1aec828
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 5 additions and 6 deletions

View File

@ -339,7 +339,7 @@
async function onAmountChange(posting: EditingPosting) {
// Synchronise the amounts if only two postings
if (transaction.postings.length == 2) {
if (transaction.postings.length === 2 && posting === transaction.postings[0]) {
for (const otherPosting of transaction.postings) {
if (otherPosting !== posting) {
otherPosting.amount_abs = posting.amount_abs;

View File

@ -23,7 +23,7 @@ import { readTextFile } from '@tauri-apps/plugin-fs';
import Database from '@tauri-apps/plugin-sql';
import { reactive } from 'vue';
import { Balance } from './amounts.ts';
import { asCost } from './amounts.ts';
import { ExtendedDatabase } from './dbutil.ts';
import { CriticalError } from './error.ts';
@ -274,12 +274,11 @@ export class Transaction {
) {}
doesBalance(): boolean {
const balance = new Balance();
let total = 0;
for (const posting of this.postings) {
balance.add(posting.quantity, posting.commodity);
total += asCost(posting.quantity, posting.commodity);
}
balance.clean();
return balance.amounts.length === 0;
return total === 0;
}
}