Budget Treeview - reshuffle totals logic

The rearranged switch statements case on row_type rather than
account type. This gives better isolation of the account types
vs row_types in the conditions inside each case.
This commit is contained in:
Geert Janssens 2020-02-05 16:02:44 +01:00
parent b0b6f2c6eb
commit 4f624087e1

View File

@ -1188,74 +1188,71 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
for (i = 0; i < num_top_accounts; ++i)
{
GNCAccountType acctype;
account = gnc_account_nth_child (priv->rootAcct, i);
currency = gnc_account_get_currency_or_parent (account);
acctype = xaccAccountGetType (account);
if (gnc_using_unreversed_budgets(gnc_account_get_book(account)))
{ /* using book with unreversed-budgets feature. This will be
the default in 4.x after budget scrubbing*/
neg = gnc_reverse_balance (account);
switch (xaccAccountGetType (account))
switch (row_type)
{
case ACCT_TYPE_ASSET:
if (row_type != TOTALS_TYPE_ASSET_LIAB_EQ &&
row_type != TOTALS_TYPE_REMAINDER)
continue;
if (row_type == TOTALS_TYPE_REMAINDER)
case TOTALS_TYPE_ASSET_LIAB_EQ:
if ((acctype == ACCT_TYPE_LIABILITY) ||
(acctype == ACCT_TYPE_EQUITY))
neg = !neg;
else if (acctype != ACCT_TYPE_ASSET)
continue;
break;
case TOTALS_TYPE_EXPENSES:
if (acctype != ACCT_TYPE_EXPENSE)
continue;
break;
case TOTALS_TYPE_INCOME:
if (acctype != ACCT_TYPE_INCOME)
continue;
neg = !neg;
break;
case ACCT_TYPE_LIABILITY:
case ACCT_TYPE_EQUITY:
if (row_type != TOTALS_TYPE_ASSET_LIAB_EQ &&
row_type != TOTALS_TYPE_REMAINDER)
continue;
if (row_type == TOTALS_TYPE_ASSET_LIAB_EQ)
neg = !neg;
break;
case ACCT_TYPE_INCOME:
if (row_type != TOTALS_TYPE_INCOME &&
row_type != TOTALS_TYPE_REMAINDER)
continue;
neg = !neg;
break;
case ACCT_TYPE_EXPENSE:
if ((row_type != TOTALS_TYPE_EXPENSES) &&
(row_type != TOTALS_TYPE_REMAINDER))
continue;
if (row_type == TOTALS_TYPE_REMAINDER)
neg = !neg;
break;
default:
continue; /* skip other types... */
break;
case TOTALS_TYPE_REMAINDER:
if ((acctype == ACCT_TYPE_ASSET) ||
(acctype == ACCT_TYPE_INCOME) ||
(acctype == ACCT_TYPE_EXPENSE))
neg = !neg;
break;
default:
continue; /* don't count if unexpected total row type is passed in... */
}
}
else
{ /* this section is for backward compatibility, to be
removed when unreversed-budgets are mandatory */
switch (xaccAccountGetType (account))
neg = FALSE;
switch (row_type)
{
case ACCT_TYPE_ASSET:
case ACCT_TYPE_LIABILITY:
case ACCT_TYPE_EQUITY:
if (row_type != TOTALS_TYPE_ASSET_LIAB_EQ &&
row_type != TOTALS_TYPE_REMAINDER)
continue;
neg = (row_type != TOTALS_TYPE_ASSET_LIAB_EQ);
break;
case ACCT_TYPE_INCOME:
if (row_type != TOTALS_TYPE_INCOME &&
row_type != TOTALS_TYPE_REMAINDER)
continue;
neg = FALSE;
break;
case ACCT_TYPE_EXPENSE:
if ((row_type != TOTALS_TYPE_EXPENSES) &&
(row_type != TOTALS_TYPE_REMAINDER))
continue;
neg = (row_type == TOTALS_TYPE_REMAINDER);
break;
default:
continue; /* skip other types... */
case TOTALS_TYPE_ASSET_LIAB_EQ:
if ((acctype != ACCT_TYPE_ASSET) &&
(acctype != ACCT_TYPE_LIABILITY) &&
(acctype != ACCT_TYPE_EQUITY))
continue;
break;
case TOTALS_TYPE_EXPENSES:
if (acctype != ACCT_TYPE_EXPENSE)
continue;
break;
case TOTALS_TYPE_INCOME:
if (acctype != ACCT_TYPE_INCOME)
continue;
break;
case TOTALS_TYPE_REMAINDER:
neg = (acctype != ACCT_TYPE_INCOME);
break;
default:
continue; /* don't count if unexpected total row type is passed in... */
}
}
// find the total for this account