SFTtech / abrechnung

Payment tracking and money splitting for groups 💸
https://abrechnung.readthedocs.io
GNU Affero General Public License v3.0
122 stars 15 forks source link

Export transactions as CSV #197

Closed ymeiron closed 5 months ago

ymeiron commented 5 months ago

This addresses #77, adding a button on the transactions page to download all transactions in the group as CSV. Apologies if that's the wrong place for the feature, I couldn't think of anything better.

The columns are: ID, Date, Payer, Name, Tags, Value; then follow n columns (one for each account in the group); the description comes last. The Tags column is either empty, contains just the tag if it's a single tag, or all tags separated by a comma and inside double quotes if there are multiple tags. CSV, being a "flat" format, cannot really contain the full information about a transaction, because it may contain an arbitrary number of positions. Therefore, only the calculated debit of each account appears.

For transfers, the value of the transaction appears as zero, the payer column shows the amount of the transfer, and the payee column shows the same amount in the negative. In both purchase and transfer, the value column is supposed to equal the some of all account debits.

Finally, the sorting is hardcoded, since I thought it's desirable for the CSV to be independent of what is currently displayed on the transaction page.

mikonse commented 5 months ago

Hi, thanks a lot for the PR.

I've merged it in #198 but made a couple changes to your implementation to keep it in line with the general code structure of the project. One larger change I've made is that there is no real distinction between transfers and purchases as the balance computation works the same for both, therefore the csv export should not differentiate between them.

Also there is no need to reeimplement the actual transaction balance computation as there already are utilities / core logic which do this, we just need to reuse it. See the type TransactionBalanceEffect and the redux selector selectTransactionBalanceEffects if you're interested.

ymeiron commented 5 months ago

Great! Thanks for the hard work, looking forward to 1.0.

I figured the transaction balance computation could be used from somewhere else in the codebase, but haven't figured out where it was exactly.