Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction Cut and Paste problems #2019

Merged
merged 3 commits into from
Sep 21, 2024
Merged

Conversation

Bob-IT
Copy link
Contributor

@Bob-IT Bob-IT commented Sep 15, 2024

A couple of bug fixes...
The first commit I think is correct but am unsure on second one, it works but may be I am missing something.

Below is an image illustrating problem...
cutpaste

The last transaction was copied and pasted to the blank transaction and as you can see the transfer account is that of the current register. The transaction is still correct but could be confusing and hence the bug report.

To fix this, when the register loads an existing check is made to ensure the transaction and splits being edited are in the split list we are loading and as part of that I am recording the anchor split of the pending transaction. If the pending transaction is the blank transaction I use that to set the leading virtual cell in the register.

There is one situation when this would fail, if the copied transaction has two splits for the same account as it would always pick the same anchor split. I do not think this is a common occurrence so for most users not a problem. I did think of another way to fix this which involved passing the copied current cursor split to gnc_txn_to_float_txn and making sure it was the first in the floating split list but decided to do it register load.

…e target account

Move the clearing of the 'copied_item' to before the setting of the
'copied_leader_guid'. This change is required due to a recent change to
include resetting 'copied_leader_guid' in the 'clear_copied_item'
function.
@jralls
Copy link
Member

jralls commented Sep 15, 2024

Everything else aside these changes illustrate the poor quality of the splt register code.

clear_copied_item needs to be moved because it also clears copied_class and copied_leader_guid. That's easily improved by making them part of the struct so they can be referred to in code as copied_item->class and copied_item->leader_guid so that the need to call clear_copied_item before using them is evident.

The fact that you had to make the same change 3 times in the 576-line gnc_split_register_load shows that it's a function desperately in need of refactoring as does the fact that its use to paste a single transaction when it's documented to load the split register from a list.

I did think of another way to fix this which involved passing the copied current cursor split to gnc_txn_to_float_txn and making sure it was the first in the floating split list but decided to do it register load.

Why? the gnc_txn_to_float_txn seems cleaner in principal.

@jralls
Copy link
Member

jralls commented Sep 20, 2024

Tested it with a transaction with two splits to the register account, works fine. They're actually pretty common for stock sale transactions: One split for the actual sale (the "other" split being the account where the proceeds go) and a second capital gain/loss split (the other being the cap gains income account).

Move static copied_class and static copied_leader_guid to be part of
the copied_item structure. This makes it more evident that calling
clear_copied_item needs to be called before copied_item is used.
When transactions are copied and pasted to the blank transaction on a
register in basic view the wrong split values are displayed. This is
due to the blank split being used for the wrong side of the transaction.

To fix this, record the copied anchor split index and use that to
reference the blank split when the transaction is pasted.
@Bob-IT
Copy link
Contributor Author

Bob-IT commented Sep 21, 2024

OK, I have added a commit to add the copied_class and copied_leader_guid to copied_item. I always start from a position that someone more experienced has done it that way for a reason.

Also fixed the second bug a different way by adding the copied anchor split index to copied_item and using that index to reference the blank split when copying onto the blank transaction.

@code-gnucash-org code-gnucash-org merged commit e4d2443 into Gnucash:stable Sep 21, 2024
4 checks passed
@jralls
Copy link
Member

jralls commented Sep 21, 2024

Thanks, Bob. It looks good.

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