From 78ef5be7b2de12490781dac62a4698e761326e9e Mon Sep 17 00:00:00 2001 From: John Ralls Date: Mon, 30 Sep 2024 14:06:30 -0700 Subject: [PATCH] Warn and don't try to balance a transaction with a too-small imbalance. In a book using trading accounts, if the user sets an account's minimum fraction to be smaller than the commodity's and makes use of the extra fraction, GnuCash can't create a correct trading split because that uses the commodity fraction. Instead of offering to balance the transaction, put up an error dialog explaing that the transaction can't be balanced. Ref Bug 799432 (https://bugs.gnucash.org/show_bug.cgi?id=799423) --- gnucash/register/ledger-core/split-register-control.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gnucash/register/ledger-core/split-register-control.cpp b/gnucash/register/ledger-core/split-register-control.cpp index a44d2649457..e213ec8928e 100644 --- a/gnucash/register/ledger-core/split-register-control.cpp +++ b/gnucash/register/ledger-core/split-register-control.cpp @@ -43,6 +43,7 @@ #include "split-register.h" #include "table-allgui.h" #include "engine-helpers.h" +#include //for gnc_error_dialog /* This static indicates the debugging module that this .o belongs to. */ @@ -90,6 +91,12 @@ gnc_split_register_balance_trans (SplitRegister *reg, Transaction *trans) multi_currency = FALSE; else multi_currency = TRUE; + if (multi_currency && + imbal_mon->value.denom > gnc_commodity_get_fraction(imbal_mon->commodity)) + { + gnc_error_dialog(gnc_ui_get_main_window(GTK_WIDGET(reg)), "%s", _("This transaction cannot be balanced: The imbalance is a fraction smaller than the commodity allows.")); + return FALSE; + } } /* We're done with the imbalance list, the real work will be done