From 1fe1aec828ada7d44a4e1c7a796d145861be391f Mon Sep 17 00:00:00 2001 From: RunasSudo <runassudo@yingtongli.me> Date: Mon, 9 Jun 2025 18:55:20 +1000 Subject: [PATCH] Allow entering transactions with mixed commodities of equal cost --- src/components/TransactionEditor.vue | 2 +- src/db.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) 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; } }