pytr-org / pytr

Use TradeRepublic in terminal and mass download all documents
https://pypi.org/project/pytr/
MIT License
422 stars 74 forks source link

Refactor parsing and formatting #122

Closed pinzutu closed 1 month ago

pinzutu commented 1 month ago

Refactors the parsing of all_events.json and the formatting into all_transactions.csv to capture all pp events generated by tr events, especially taxes, fees, and savebacks.

In detail: 1. Removes card_failed_transaction type due to it not being relevant for PP

  1. Adds INCOMING_TRANSFER_DELEGATION and events from #116 (INTEREST_PAYOUT, card_successful_oct, TAX_REFUND, benefits_saveback_execution) to event.py
  2. Introduces enums and dataclasses in event.py to a. structure and facilitate type matching b. differentiate between pp_types and types that require further csv formatting
  3. Introduces tax and fee parsers in event.py
  4. Introduces event_formatter.py to generate multiple csv lines from certain events (saveback, taxed income, transactions with fees). Fees and taxes are added as csv columns to avoid stand-alone transactions.
  5. Adds a cli option argument to dl_docs and export_transactions to chronologically sort the exported csv transactions Additionally:
    • Changes DIVIDENDS to DIVIDEND in .po messages to respect PP's nomenclature

The all_events.json available to me parses into an accurate all_transactions.csv; however, I highly encourage everyone to test the pr on their own event logs. I did not observe breaking changes when testing with the docker image of python 3.8

pinzutu commented 1 month ago

Apologies for the small post-review change: I had the late realization that PP transactions have embedded taxes and fees fields. I therefore added taxes and fees columns to the csv file, which voids the need to generate stand-alone tax and fee events and trims event_formatter.py in the process.

Katzmann1983 commented 1 month ago

Sorry, I was first too euphoric and then tested it a little bit more. Before your last commit, taxes and fees were positive and thus gave a wrong total sum. Also I realized, that card_failed_transaction are not handled at all. These only need to be added, if and only if the transaction is of type card_failed_transaction and of status= "executed".

pinzutu commented 1 month ago

Notwithstanding PP's indifference to the sign of fees and taxes, sticking to the negative sign convention for both makes more sense indeed. I also wrongly believed card_failed_transaction events to always be failed transactions; these now conditionally map to REMOVALs again.