GnuCash
Contact   Instructions
Bug 796952 - Report formatting (justify) is broken
Summary: Report formatting (justify) is broken
Status: REOPENED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: Reports (show other bugs)
Version: 2.6.x
Hardware: PC Linux
: Normal normal
Target Milestone: ---
Assignee: reports
QA Contact: reports
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-21 13:35 EST by Matija N.
Modified: 2020-06-01 15:25 EDT (History)
6 users (show)

See Also:


Attachments
Account summary - broken formatting for columns (63.91 KB, image/png)
2018-11-21 13:35 EST, Matija N.
no flags Details
original (broken) HTML export snippet (1.17 KB, text/html)
2018-11-21 14:14 EST, Matija N.
no flags Details
manually corrected version of HTML snippet (1.17 KB, text/html)
2018-11-21 14:14 EST, Matija N.
no flags Details
Workaround for normal formatting in AccountSummary report. (2.39 KB, patch)
2019-03-09 22:26 EST, Matija N.
no flags Details

Description Matija N. 2018-11-21 13:35:36 EST
Created attachment 373068 [details]
Account summary - broken formatting for columns

For example, in Account Summary, I would expect the "Balance" column values to be in the same column (on the right end of the screen/paper)... However, depending on the account depth level, they are mismatched in strange way: the bigger the account depth, the more to the LEFT do "balance" column values move (if there was a shortage of space, with fixed spacings one would expect "balance" column values to move to the RIGHT). 

So it looks like gnucash tries to reduce amount of whitespace between columns the deeper the account depth (as it should), but it actually overcompensates and whitespace get reduced too much.


Screenshot in attachment should explain it much better than text...

(This is latest stable gnucash 1:2.6.15-1 from Debian Stretch)
Comment 1 Matija N. 2018-11-21 14:14:24 EST
Created attachment 373069 [details]
original (broken) HTML export snippet
Comment 2 Matija N. 2018-11-21 14:14:51 EST
Created attachment 373070 [details]
manually corrected version of HTML snippet
Comment 3 Matija N. 2018-11-21 14:18:47 EST
Looking at HTML produced by "Export HTML" button, it looks even stranger. It is like gnucash is creating several empty columns (proportional to "levels of Subaccounts" option), and then instead of keeping the "balance" in last column, it tries to change its column depending on the current subaccount depth.

Original (broken) behaviour and manually corrected HTML snippet are in attachment (the corrected version has "border=1" added just as illustration).

I've actually managed to kludge around the bug with following perl oneliner,which removes all "empty" columns, thus indirectly making their ordering irrelevant (as only columns with data will remain, and "balance" column will be always last of them) and thus producing usable HTML.

    perl -ne 'print unless m{<td.*?>(\h*&nbsp;\h*)+?</td>}' < report_2018_org.html > report_2018.html

But it should be fixed in gnucash properly.
Comment 4 Alexander Romeo 2018-11-27 21:18:36 EST
Hey I've notcied this bug as well and its been driving me crazy. I was wondering how you fixed this so I can apply the same fix in my version as well?
Comment 5 Matija N. 2019-03-09 22:26:03 EST
Created attachment 373207 [details]
Workaround for normal formatting in AccountSummary report.

The attached patch works around the issue for wrong indenting/formatting for Account Summary report on my Debian GNUcash 1:2.6.15-1.

However, it only cures the symptoms (and not nice way, either) instead of the real cause of the problem [1] so it does not help reports which are messed up too - finding that one is beyond my capabilities and time resources (I am also not familiar with Lisp/Scheme at all, so this was a lot of try-and-debug). So it might break in new gnucash versions.

But hopefully it might help someone else until the real bug is found and fixed.

The patch also fixes "Display/Account Balance" which wasn't working correctly in that report.


[1] which seems to be that erroneous empty columns are created in the first place by gnc:html-table-add-account-balances or something near it.
Comment 6 Christopher Lam 2019-03-10 05:17:59 EDT
Matija when I apply your patch, the report balances are now aligned. I think this is an acceptable bugfix for now.
Comment 7 Christopher Lam 2019-03-10 22:10:57 EDT
This will be fixed for 3.5, thank you for your patch!
Comment 8 Christopher Lam 2019-08-21 10:06:48 EDT
This bugfix is causing woes in another bug 797332 -- I have considered why the old indentation was broken.

It seems the original report designer made some assumptions on the account and amount indenting and I think were wrong. Here's what I think he (DM) was trying to achieve:

Assuming a conventional structure Asset:Bank:Current, or Savings, Asset:Broker:Cash or Stock, he wanted the amounts to align as follows. Therefore there was code to detect 'has-child-account' therefore indent same as child-account. I think this is the cause of numerous problems.

Asset             $2200 <--- grand total of all assets
 Bank      $1000
  Current   $200
  Savings   $800
 Broker    $1200
  Cash      $200
  Stock    $1000 (10 stock) 

My proposal is to strictly indent amounts according to account-level, i.e.

Asset                  $2200
 Bank            $1000
  Current   $200
  Savings   $800
 Broker          $1200
  Cash      $200
  Stock    $1000

I'd like to revert this change, and make changes as above, and this will fix bug 797332. This current bug will also be fixed, so that the account-summary *will* show the toplevel 'Asset' balance in the same column as the 'Balance' header, but the children-amounts will be indented to the left. Anyone objects?
Comment 9 Christopher Lam 2019-08-21 10:08:49 EDT
P.S. the simple change is easily achieved by modifying html-acct-table.scm as follows:

modified   gnucash/report/report-system/html-acct-table.scm
@@ -1304,6 +1304,7 @@
 		 ;; some reports, the output might look incorrect. but,
 		 ;; if you think long and hard about it, i think you'll
 		 ;; find the current treatment correct... i think. -DM-
+                #;
 		 (- 0 (if (if (not children-displayed?)
 			      #f
 			      (equal? bal-method 'immediate-bal))
Comment 10 Christopher Lam 2019-08-25 06:25:20 EDT
I'll take the absence response in this bug report that the interested parties have no particular views on this issue. I'll aim to reverse this fix and restore amount indenting for the account summary. After all most other reports indent amounts. I'll fix bug 797332 by enforcing indenting strictly according to account-depth.
Comment 11 Matija N. 2019-08-26 07:04:41 EDT
As original bug submitter, I'm more than happy with smarter fixes than my kludge.

However, the proposed patch - addding one line with "#;" at seemingly right place (which is line 1338 in my unpatched copy of gnucash 2.6.15) - does not seem to fix the identing here.

I'll try to upgrade my Debian next week to new stable which contains gnucash 3.4, so I'll have at least somewhat more recent version to try the fixes in my use case.
Comment 12 Christopher Lam 2019-08-26 08:11:48 EDT
Sure. Remember a screenshot = 1000 words. The aim is to align numbers correctly so that (1) equally deep accounts have equally aligned balances (2) the Balance header actually matches toplevel account balance.
Comment 13 Christopher Lam 2019-09-05 01:35:48 EDT
Comment 8 above will lead to a fundamental change in the indenting of amounts in several reports, and I'd like to watch any negative feedback. So, unless there are major objections by original submitter, or core devs, I'd like to push reversal soon.
Comment 14 John Ralls 2019-09-05 12:16:21 EDT
Comment 8 is about a replacement for 35ed4cf2 not simple reversion. Do you have the replacement committed to your Github repo?
Comment 15 Christopher Lam 2019-09-05 12:26:17 EDT
Sure, easily just done:

https://github.com/christopherlam/gnucash/tree/maint-796952-797332
Comment 16 Christopher Lam 2019-09-05 12:48:07 EDT
As another test for the old weird behaviour, try any old-style reports eg balance-sheet with account structure. Consider ONLY leaf accounts have amounts (i.e. Asset:Bank is a placeholder balance $0, but Asset:House is $100,000), this is the resulting weird balance-sheet. Why is Bank aligned as its children accounts, whereas FriendLoans isn't aligned with its child account Party, but Party aligned with its subaccounts?

Asset...................................................$0
Asset:Bank...............................$0
Asset:Bank:Current....................$1000
Asset:Bank:Savings....................$2000
Asset:FriendLoans........................$0
Asset:FriendLoans:Party...........$0
Asset:FriendLoans:Party:2012.....$40
Asset:FriendLoans:Party:2013.....$50
Asset:House.......................................$100,000
Asset:Jewellery.......................................$800

and with my proposal simply aligns according to acc-depth. The Asset top-level account is pushed to the right as it should be, thereby belonging squarely to the "Balance" header as it should be.

Asset.............................................................$0
Asset:Bank..............................................$0
Asset:Bank:Current.....................$1000
Asset:Bank:Savings.....................$2000
Asset:FriendLoans.......................................$0
Asset:FriendLoans:Party...................$0
Asset:FriendLoans:Party:2012.....$40
Asset:FriendLoans:Party:2013.....$50
Asset:House.......................................$100,000
Asset:Jewellery.......................................$800
Comment 17 John Ralls 2019-09-05 14:09:46 EDT
Looks like you need to adjust test-balsheet-pnl. Otherwise OK.
Comment 18 Matija N. 2019-09-05 18:20:43 EDT
Actually, what my patch did was show *all* balances aligned under "Balances" column, so this structure:

Asset.............................................$103,890
Asset:Bank..........................................$3,000
Asset:Bank:Current..................................$1,000
Asset:Bank:Savings..................................$2,000
Asset:FriendLoans......................................$90
Asset:FriendLoans:Party................................$90
Asset:FriendLoans:Party:2012...........................$40
Asset:FriendLoans:Party:2013...........................$50
Asset:House.......................................$100,000
Asset:Jewellery.......................................$800

actually looked like this after 35ed4cf2 (Account titles indented according to their depth, but all numbers right-aligned in same "Balance" column): 

Account title......................................Balance
Asset.............................................$103,890
....Bank............................................$3,000
........Current.....................................$1,000
........Savings.....................................$2,000
....FriendLoans........................................$90
........Party..........................................$90
............2012.......................................$40
............2013.......................................$50
....House.........................................$100,000
....Jewellery.........................................$800

Note that (especially with "parent account balances: subtotal") such output is very readable,  it is very easy to visually find fattest accounts even without reading any numbers (and look up to see where they belong to), and column names actually correspond to what is written in them (even in HTML table output). 

Now when I look at your explanation and examples, it looks to me that you try to accomplish something completely different - having multiple balance columns whose indentation differ depending on depth of the account (which might be useful in some other use cases, but not to mine). 

If that is the case, perhaps there could be the checkbox option to have "flat  balance" (eg. only one column named "Balance" in which all numbers are right-aligned nicely one under the other) which would have behavior  as in 35ed4cf2 if enabled, and your preferred behavior (different balance indentation for different account depths) if disabled?
Comment 19 Christopher Lam 2019-09-06 10:16:52 EDT
Matija N:

I understand the desire to modify reports to suit one's needs. I really do. I remember feeling angry at my helplessness to hack scheme to get some IMHO simple data out of this otherwise incredible software, and that has driven my efforts to learn scheme from basic principles so that I can create new reports out of it; now I am busy cleaning up the code.

For this issue, for the wish for an at-a-glance type report, I have built balsheet-pnl.scm (multicolumn balance-sheet and income-statement) which can give you the exact same information as above. Both with full account-names, or indented childmost account-name. I think this will suit your needs.

The main reason I would advocate to restore the previous indenting is to restore backward compatibility for other long-term users, especially bug 797332, and because most other old-school (i.e. created ~20yrs ago) reports behave similarly.

We could add an option to enforce single-column balances, but if the multicolumn balance sheet does the job (IMHO better), we'd prefer *not* to. Multicolumn balsheet gives you: balsheets at multiple-dates, better support for foreign currency conversion, optional indenting, links to net-worth charts, and the clicky link targets the exact split which sets the account-balance. As I mentioned, better than account-summary.scm.
Comment 20 Matija N. 2019-09-13 16:41:45 EDT
Thanks for recommendation! Unfortunately balsheet-pnl.scm does not seem to be in Debian Buster (recently released Debian Stable comes with gnucash 3.4). 

So I've installed virtual machine with Debian Sid containing gnucash 3.7+(2019-09-07), and indeed it looks like "Reports / Experimental / Balance Sheet (Multicolumn)"  might be reasonable replacement for "Account Summary" (after I turn off "Enable dual columns" and turn on "Disable amount indenting" in its options).

On quick look however, it is much less indented than Account Summary was (about 1 em instead of about 3 em), and  checking off "Include totals" does not seem to work.
I'll open new bugs/wishlists for that.
Comment 21 Matija N. 2019-09-13 17:22:23 EDT
(referenced in #797410 and #797411)

Note You need to log in before you can comment on or make changes to this bug.