Skip to content

Conversation

@0xlwu
Copy link
Contributor

@0xlwu 0xlwu commented Aug 17, 2021

I was introducing --commodity-column into my personal reports and realized that the textual output didn't correctly handle --transpose when both flags are set. While fixing that, I also realized that empty commodities were being silently filtered out (e.g https://github.com/simonmichael/hledger/blob/master/hledger/Hledger/Cli/Commands/Balance.hs#L717). This wasn't a regression per-se but obviously undesirable behavior.

There is some overlap with #1649 since handling transposition unfortunately involved some reworking of the compound call-site.

Perhaps the suite of flag interactions should be more formally considered?

@Xitian9
Copy link
Collaborator

Xitian9 commented Aug 18, 2021

I haven't done a full read-through of the code here, but I think we shouldn't worry about conflicts between PRs for merging this: I can easily rebase.

My bigger thought is that we seem to be jumping through a lot of hoops to work around the limitations of the table rendering code. If I understand correctly, the problem here is that we basically have two columns worth of row headers (account name, and commodity), while the rendering code can only handle one. So we are ad-doc throwing commodity columns in using purpose-designed functions.

Would it be reasonable to solve this problem with a transpose option in the rendering code? Perhaps to add transposeTable to TableOpts, which would flip the roles of the rows and columns in the rendering function?

@Xitian9
Copy link
Collaborator

Xitian9 commented Aug 18, 2021

Thinking about it: you have a working implementation here. Let's work on merging this with the basic method used here. If we come up with a simpler way later, we can do the refactoring then and make sure it still passes all these tests.

@0xlwu
Copy link
Contributor Author

0xlwu commented Aug 18, 2021

My bigger thought is that we seem to be jumping through a lot of hoops to work around the limitations of the table rendering code. If I understand correctly, the problem here is that we basically have two columns worth of row headers (account name, and commodity), while the rendering code can only handle one. So we are ad-doc throwing commodity columns in using purpose-designed functions.

Would it be reasonable to solve this problem with a transpose option in the rendering code? Perhaps to add transposeTable to TableOpts, which would flip the roles of the rows and columns in the rendering function?

That is certainly one way to approach it. Are you imagining a situation where renderTable first creates the full table of strings and then does transposition and alignment after (Cell becomes a single WideBuilder)?

Either way we would also need to implement the header-column independence for the budget report that we talked about #1626 (comment) (Which might indicate a compelling use case). Budget was also the most annoying piece of code to change so I'm open to improvements there...

Thinking about it: you have a working implementation here. Let's work on merging this with the basic method used here. If we come up with a simpler way later, we can do the refactoring then and make sure it still passes all these tests.

Sounds good to me. Would it be helpful if I split this into separate PRs for empty-commodity handling fixes and transpose-flag fixes?

@0xlwu 0xlwu force-pushed the commodity-column-2 branch from c986bd9 to 5fea31e Compare August 18, 2021 14:28
@Xitian9
Copy link
Collaborator

Xitian9 commented Aug 18, 2021

Sounds good to me. Would it be helpful if I split this into separate PRs for empty-commodity handling fixes and transpose-flag fixes?

That would keep the commit history cleaner, but it's not crucial.

This PR seems to include enabling --commodity-column for compound balance reports. Does this render #1649 completely redundant?

@0xlwu
Copy link
Contributor Author

0xlwu commented Aug 18, 2021

This PR seems to include enabling --commodity-column for compound balance reports. Does this render #1649 completely redundant?

I didn't touch the format specifier or any of the aggressive account name elisions so not completely covered. (The CSV and HTML output changes in the compound reports is handled by this and not 1649 though)

@Xitian9
Copy link
Collaborator

Xitian9 commented Aug 19, 2021

In that case, I'll mark #1649 as draft and wait until this one is merged before deciding what in there is still useful.

@Xitian9
Copy link
Collaborator

Xitian9 commented Aug 19, 2021

This build failure seems to be unrelated to the content of the PR.

@simonmichael
Copy link
Owner

This build failure seems to be unrelated to the content of the PR.

Pushed a fix that might help.

@simonmichael
Copy link
Owner

...to master; if this PR gets rebased its CI may work again.

@0xlwu 0xlwu force-pushed the commodity-column-2 branch from 5fea31e to 5290ece Compare August 19, 2021 05:30
0xlwu added 6 commits August 19, 2021 09:01
We can't filter out empty commodity strings since that is a legitimate
group. Simultaneously, we should only include the empty commodity if it
is explicitly used (part of a posting) and not generated as part of
`Amounts.amounts`
The textual output needs to be fully transposed instead of just the cell
values. The multi-period csv handling code already does the right thing
so just use those values.

The change in CompoundBalanceCommand.hs is just to match signatures
since commodity-column is not yet enabled there.
Budget formatting is quite complicated since we must determine widths
for each of the transposed columns
Also renames the file for consistent naming with the flag
@0xlwu 0xlwu force-pushed the commodity-column-2 branch from 5290ece to 47b7f2d Compare August 19, 2021 14:01
@simonmichael simonmichael merged commit d9b511c into simonmichael:master Aug 20, 2021
@simonmichael
Copy link
Owner

Thanks for the followup testing and fixes!

simonmichael pushed a commit that referenced this pull request Aug 20, 2021
We can't filter out empty commodity strings since that is a legitimate
group. Simultaneously, we should only include the empty commodity if it
is explicitly used (part of a posting) and not generated as part of
`Amounts.amounts`
simonmichael pushed a commit that referenced this pull request Aug 20, 2021
The textual output needs to be fully transposed instead of just the cell
values. The multi-period csv handling code already does the right thing
so just use those values.

The change in CompoundBalanceCommand.hs is just to match signatures
since commodity-column is not yet enabled there.
simonmichael pushed a commit that referenced this pull request Aug 20, 2021
Budget formatting is quite complicated since we must determine widths
for each of the transposed columns
simonmichael pushed a commit that referenced this pull request Aug 20, 2021
Also renames the file for consistent naming with the flag
simonmichael added a commit that referenced this pull request Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants