Skip to content

Commit

Permalink
[gnc-budget-view.c] much simpler negation rule: always negate.
Browse files Browse the repository at this point in the history
previously negation was dependent on the row type and account
type. this change will modify the rule to *always* negate the total
amount prior to rendering.

this is because budget amounts are now natural numbers, i.e. budget
income usually negative, budget expense usually positive. the total of
budget amounts in a period (asset+liability+income+expense+equity)
should be zero.

the compulsory negation will ensure the budget equation is now much
more intuitive, i.e. an income *adds* to the budget, and an
expense *deducts* from budget; the "remaining to budget" is thus
positive if there is unallocated budget.
  • Loading branch information
christopherlam committed May 24, 2023
1 parent b0292d7 commit 66f4b4c
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions gnucash/gnome/gnc-budget-view.c
Expand Up @@ -1219,9 +1219,6 @@ bgv_get_total_for_account (Account *account, GncBudget *budget, gnc_commodity *n
}
}

if (gnc_reverse_balance (account))
total = gnc_numeric_neg (total);

return total;
}

Expand Down Expand Up @@ -1317,7 +1314,6 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
gint period_num;
gnc_numeric value; // used to assist in adding and subtracting
gchar amtbuff[100]; //FIXME: overkill, where's the #define?
gboolean neg;
GNCPriceDB *pdb;
gnc_commodity *total_currency, *currency;
gnc_numeric total = gnc_numeric_zero ();
Expand All @@ -1342,16 +1338,13 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
currency = gnc_account_get_currency_or_parent (account);
acctype = xaccAccountTypeGetFundamental (xaccAccountGetType (account));

neg = gnc_reverse_balance (account);

switch (row_type)
{
case TOTALS_TYPE_ASSET_LIAB_EQ:
if ((acctype != ACCT_TYPE_ASSET) &&
(acctype != ACCT_TYPE_LIABILITY) &&
(acctype != ACCT_TYPE_EQUITY))
continue;
neg = !neg;
break;
case TOTALS_TYPE_EXPENSES:
if (acctype != ACCT_TYPE_EXPENSE)
Expand All @@ -1360,10 +1353,8 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
case TOTALS_TYPE_INCOME:
if (acctype != ACCT_TYPE_INCOME)
continue;
neg = !neg;
break;
case TOTALS_TYPE_REMAINDER:
neg = !neg;
break;
default:
continue; /* don't count if unexpected total row type is passed in... */
Expand All @@ -1383,12 +1374,14 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
gnc_budget_get_period_start_date (priv->budget, period_num));
}

if (neg)
value = gnc_numeric_neg (value);

total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
}

/* because we want income to be positive, expense and transfer to
be negative. i.e. income adds to the budget, expense and
transfer deducts from budget */
total = gnc_numeric_neg (total);

xaccSPrintAmount (amtbuff, total,
gnc_commodity_print_info (total_currency,
period_num < 0 ? TRUE : FALSE));
Expand Down

0 comments on commit 66f4b4c

Please sign in to comment.