diff --git a/src/components/TransactionEditor.vue b/src/components/TransactionEditor.vue index ee60f32..a4bf3ec 100644 --- a/src/components/TransactionEditor.vue +++ b/src/components/TransactionEditor.vue @@ -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; diff --git a/src/db.ts b/src/db.ts index dc66945..641ac0e 100644 --- a/src/db.ts +++ b/src/db.ts @@ -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; } }