Skip to content

Commit

Permalink
Bug 797006 - Balance is misleading in open subaccounts when different…
Browse files Browse the repository at this point in the history
… currencies are involved
  • Loading branch information
jean committed Apr 2, 2020
1 parent bedc963 commit 01cdcca
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 34 deletions.
22 changes: 21 additions & 1 deletion gnucash/gnome/gnc-plugin-page-register.c
Expand Up @@ -675,12 +675,23 @@ gnc_plugin_page_register_new_common (GNCLedgerDisplay *ledger)
return plugin_page;
}

static gpointer
gnc_plug_page_register_check_commodity(Account *account, void* usr_data)
{
// Check that account's commodity matches the commodity in usr_data
gnc_commodity* com0 = (gnc_commodity*) usr_data;
gnc_commodity* com1 = xaccAccountGetCommodity(account);
return gnc_commodity_equal(com1, com0) ? NULL : com1;
}

GncPluginPage *
gnc_plugin_page_register_new (Account *account, gboolean subaccounts)
{
GNCLedgerDisplay *ledger;
GncPluginPage *page;
GncPluginPageRegisterPrivate *priv;
gnc_commodity* com0;
gnc_commodity* com1;

/*################## Added for Reg2 #################*/
const GList *item;
Expand Down Expand Up @@ -708,9 +719,18 @@ gnc_plugin_page_register_new (Account *account, gboolean subaccounts)
}
}
/*################## Added for Reg2 #################*/
com0 = gnc_account_get_currency_or_parent(account);
com1 = gnc_account_foreach_descendant_until(account,gnc_plug_page_register_check_commodity,com0);
if(0 && com1 != NULL)
{
const gchar* com0_str = gnc_commodity_get_fullname(com0);
const gchar* com1_str = gnc_commodity_get_fullname(com1);
gnc_info_dialog(NULL,_("Cannot open sub-accounts because sub-accounts and parent account have different commodities or currencies\nFound:\n%s\n%s\n(There may be more mismatches)"),com0_str,com1_str);
return NULL;
}

if (subaccounts)
ledger = gnc_ledger_display_subaccounts (account);
ledger = gnc_ledger_display_subaccounts (account,com1 != NULL);
else
ledger = gnc_ledger_display_simple (account);

Expand Down
24 changes: 14 additions & 10 deletions gnucash/register/ledger-core/gnc-ledger-display.c
Expand Up @@ -88,7 +88,8 @@ gnc_ledger_display_internal (Account *lead_account, Query *q,
SplitRegisterType reg_type,
SplitRegisterStyle style,
gboolean use_double_line,
gboolean is_template);
gboolean is_template,
gboolean mismatched_commodities);

static void gnc_ledger_display_refresh_internal (GNCLedgerDisplay *ld,
GList *splits);
Expand Down Expand Up @@ -370,15 +371,15 @@ gnc_ledger_display_simple (Account *account)

ld = gnc_ledger_display_internal (account, NULL, LD_SINGLE, reg_type,
gnc_get_default_register_style(acc_type),
use_double_line, FALSE);
use_double_line, FALSE, FALSE);
LEAVE("%p", ld);
return ld;
}

/* Opens up a register window to display an account, and all of its
* children, in the same window */
GNCLedgerDisplay *
gnc_ledger_display_subaccounts (Account *account)
gnc_ledger_display_subaccounts (Account *account,gboolean mismatched_commodities)
{
SplitRegisterType reg_type;
GNCLedgerDisplay *ld;
Expand All @@ -389,7 +390,7 @@ gnc_ledger_display_subaccounts (Account *account)

ld = gnc_ledger_display_internal (account, NULL, LD_SUBACCOUNT,
reg_type, REG_STYLE_JOURNAL, FALSE,
FALSE);
FALSE,mismatched_commodities);
LEAVE("%p", ld);
return ld;
}
Expand Down Expand Up @@ -439,7 +440,7 @@ gnc_ledger_display_gl (void)
QOF_QUERY_AND);

ld = gnc_ledger_display_internal (NULL, query, LD_GL, GENERAL_JOURNAL,
REG_STYLE_JOURNAL, FALSE, FALSE);
REG_STYLE_JOURNAL, FALSE, FALSE, FALSE);
LEAVE("%p", ld);
return ld;
}
Expand Down Expand Up @@ -484,7 +485,8 @@ gnc_ledger_display_template_gl (char *id)
SEARCH_LEDGER,
REG_STYLE_JOURNAL,
FALSE,
isTemplateModeTrue);
isTemplateModeTrue,
FALSE);

sr = gnc_ledger_display_get_split_register (ld);
if ( acct )
Expand Down Expand Up @@ -526,7 +528,7 @@ gnc_ledger_display_set_watches (GNCLedgerDisplay *ld, GList *splits)
GNC_ID_ACCOUNT,
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY
| GNC_EVENT_ITEM_CHANGED);

for (node = splits; node; node = node->next)
{
Split *split = node->data;
Expand Down Expand Up @@ -697,7 +699,7 @@ gnc_ledger_display_query (Query *query, SplitRegisterType type,
ENTER("query=%p", query);

ld = gnc_ledger_display_internal (NULL, query, LD_GL, type, style,
FALSE, FALSE);
FALSE, FALSE, FALSE);
LEAVE("%p", ld);
return ld;
}
Expand All @@ -708,7 +710,8 @@ gnc_ledger_display_internal (Account *lead_account, Query *q,
SplitRegisterType reg_type,
SplitRegisterStyle style,
gboolean use_double_line,
gboolean is_template )
gboolean is_template,
gboolean mismatched_commodities)
{
GNCLedgerDisplay *ld;
gint limit;
Expand Down Expand Up @@ -808,8 +811,9 @@ gnc_ledger_display_internal (Account *lead_account, Query *q,
\******************************************************************/

ld->use_double_line_default = use_double_line;

ld->reg = gnc_split_register_new (reg_type, style, use_double_line,
is_template);
is_template,mismatched_commodities);

gnc_split_register_set_data (ld->reg, ld, gnc_ledger_display_parent);

Expand Down
2 changes: 1 addition & 1 deletion gnucash/register/ledger-core/gnc-ledger-display.h
Expand Up @@ -85,7 +85,7 @@ GNCLedgerDisplay * gnc_ledger_display_simple (Account *account);

/** opens up a register window to display the parent account and all of
* its children. */
GNCLedgerDisplay * gnc_ledger_display_subaccounts (Account *account);
GNCLedgerDisplay * gnc_ledger_display_subaccounts (Account *account, gboolean mismatched_commodities);

/** opens up a general ledger window */
GNCLedgerDisplay * gnc_ledger_display_gl (void);
Expand Down
26 changes: 21 additions & 5 deletions gnucash/register/ledger-core/split-register-layout.c
Expand Up @@ -291,8 +291,16 @@ gnc_split_register_set_cells (SplitRegister *reg, TableLayout *layout)
{
gnc_table_layout_set_cell (layout, curs, DEBT_CELL, 0, 5);
gnc_table_layout_set_cell (layout, curs, CRED_CELL, 0, 6);
gnc_table_layout_set_cell (layout, curs, RBALN_CELL, 0, 7);
gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 8);
if(!reg->mismatched_commodities)
{
gnc_table_layout_set_cell (layout, curs, RBALN_CELL, 0, 7);
gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 8);
}
else
{
// Don't display the balance if there are mismatched commodities
gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 7);
}
}

curs_last = curs;
Expand Down Expand Up @@ -328,8 +336,16 @@ gnc_split_register_set_cells (SplitRegister *reg, TableLayout *layout)
gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 7);
else
{
gnc_table_layout_set_cell (layout, curs, RBALN_CELL, 0, 7);
gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 8);
if(!reg->mismatched_commodities)
{
gnc_table_layout_set_cell (layout, curs, RBALN_CELL, 0, 7);
gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 8);
}
else
{
// Don't display the balance if there are mismatched commodities
gnc_table_layout_set_cell (layout, curs, RATE_CELL, 0, 7);
}
}

curs_last = curs;
Expand Down Expand Up @@ -577,7 +593,7 @@ gnc_split_register_layout_add_cursors (SplitRegister *reg,
case INCOME_LEDGER:
case GENERAL_JOURNAL:
case SEARCH_LEDGER:
if (reg->is_template)
if (reg->is_template || reg->mismatched_commodities)
num_cols = 8;
else
num_cols = 9;
Expand Down
23 changes: 10 additions & 13 deletions gnucash/register/ledger-core/split-register-model.c
Expand Up @@ -1352,7 +1352,6 @@ gnc_split_register_get_balance_entry (VirtualLocation virt_loc,
Account *account;

split = gnc_split_register_get_split (reg, virt_loc.vcell_loc);

if (split == xaccSplitLookup (&info->blank_split_guid,
gnc_get_current_book ()))
return NULL;
Expand All @@ -1372,7 +1371,7 @@ gnc_split_register_get_balance_entry (VirtualLocation virt_loc,
if (gnc_reverse_balance (account))
balance = gnc_numeric_neg (balance);

return xaccPrintAmount (balance, gnc_account_print_info (account, FALSE));
return xaccPrintAmount (balance, gnc_account_print_info (account, reg->mismatched_commodities));
}

static const char *
Expand Down Expand Up @@ -1655,7 +1654,7 @@ gnc_split_register_get_tdebcred_entry (VirtualLocation virt_loc,

total = gnc_numeric_abs (total);

return xaccPrintAmount (total, gnc_split_amount_print_info (split, FALSE));
return xaccPrintAmount (total, gnc_split_amount_print_info (split, reg->mismatched_commodities));
}

/* return TRUE if we have a RATE_CELL; return FALSE if we do not.
Expand Down Expand Up @@ -1811,7 +1810,7 @@ gnc_split_register_get_debcred_entry (VirtualLocation virt_loc,
GNC_HOW_RND_ROUND_HALF_UP);
}

return xaccPrintAmount (imbalance, gnc_account_print_info (acc, FALSE));
return xaccPrintAmount (imbalance, gnc_account_print_info (acc, reg->mismatched_commodities));
}

{
Expand Down Expand Up @@ -1874,22 +1873,20 @@ gnc_split_register_get_debcred_entry (VirtualLocation virt_loc,
* currency != the account commodity, then use the SplitAmount
* instead of the SplitValue.
*/
gboolean currency_match;
switch (reg->type)
{
case STOCK_REGISTER:
case CURRENCY_REGISTER:
case PORTFOLIO_LEDGER:
amount = xaccSplitGetValue (split);
print_info = gnc_commodity_print_info (currency, FALSE);
print_info = gnc_commodity_print_info (currency, reg->mismatched_commodities);
break;

default:
if (commodity && !gnc_commodity_equal (commodity, currency))
/* Convert this to the "local" value */
amount = xaccSplitConvertAmount(split, account);
else
amount = xaccSplitGetValue (split);
print_info = gnc_account_print_info (account, FALSE);
amount = xaccSplitGetValue (split);
print_info = gnc_account_print_info (account, reg->mismatched_commodities);
print_info.commodity = currency;
break;
}
}
Expand Down Expand Up @@ -1929,7 +1926,7 @@ gnc_split_register_get_rbaln_entry (VirtualLocation virt_loc,
if (split == xaccSplitLookup (&info->blank_split_guid,
gnc_get_current_book ()))
return NULL;

trans = xaccSplitGetParent (split);
if (!trans)
return NULL;
Expand Down Expand Up @@ -2421,7 +2418,7 @@ gnc_template_register_get_debcred_entry (VirtualLocation virt_loc,

amount2 = gnc_numeric_abs (*amount);
g_free (amount);
return xaccPrintAmount (amount2, gnc_default_print_info (FALSE));
return xaccPrintAmount (amount2, gnc_default_print_info (reg->mismatched_commodities));
}

static void
Expand Down
10 changes: 7 additions & 3 deletions gnucash/register/ledger-core/split-register.c
Expand Up @@ -2816,7 +2816,8 @@ gnc_split_register_init (SplitRegister *reg,
SplitRegisterStyle style,
gboolean use_double_line,
gboolean do_auto_complete,
gboolean is_template)
gboolean is_template,
gboolean mismatched_commodities)
{
TableLayout *layout;
TableModel *model;
Expand Down Expand Up @@ -2857,6 +2858,7 @@ gnc_split_register_init (SplitRegister *reg,
reg->use_double_line = use_double_line;
reg->do_auto_complete = do_auto_complete;
reg->is_template = is_template;
reg->mismatched_commodities = mismatched_commodities;
reg->use_tran_num_for_num_field =
(qof_book_use_split_action_for_num_field(gnc_get_current_book())
? FALSE : TRUE);
Expand Down Expand Up @@ -2914,7 +2916,8 @@ SplitRegister *
gnc_split_register_new (SplitRegisterType type,
SplitRegisterStyle style,
gboolean use_double_line,
gboolean is_template)
gboolean is_template,
gboolean mismatched_commodities)
{
SplitRegister * reg;
gboolean default_do_auto_complete = TRUE;
Expand All @@ -2929,7 +2932,8 @@ gnc_split_register_new (SplitRegisterType type,
style,
use_double_line,
default_do_auto_complete,
is_template);
is_template,
mismatched_commodities);

return reg;
}
Expand Down
5 changes: 4 additions & 1 deletion gnucash/register/ledger-core/split-register.h
Expand Up @@ -254,6 +254,8 @@ struct split_register

gboolean is_template;
gboolean do_auto_complete; /**< whether to use auto-completion */
gboolean mismatched_commodities; /**< indicates the register includes transactions in
mismatched commodities */

SplitList *unrecn_splits; /**< list of splits to unreconcile after transaction edit */

Expand Down Expand Up @@ -282,7 +284,8 @@ typedef GtkWidget *(*SRGetParentCallback) (gpointer user_data);
SplitRegister * gnc_split_register_new (SplitRegisterType type,
SplitRegisterStyle style,
gboolean use_double_line,
gboolean is_template);
gboolean is_template,
gboolean mismatched_commodities);

/** Destroys a split register.
*
Expand Down

0 comments on commit 01cdcca

Please sign in to comment.