From 0274db24a98ff034fa93e81ee1c272c1103be34d Mon Sep 17 00:00:00 2001 From: Vlad <55182132+titov-vv@users.noreply.github.com> Date: Thu, 30 May 2024 17:15:17 +0100 Subject: [PATCH] Portugues tax report was extended with list of interest payments. --- jal/data_export/tax_reports/portugal.py | 44 +++++++++++++++++-- .../templates/tax_prt_interests.json | 34 ++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 jal/data_export/templates/tax_prt_interests.json diff --git a/jal/data_export/tax_reports/portugal.py b/jal/data_export/tax_reports/portugal.py index ccebdbcb..e92053a6 100644 --- a/jal/data_export/tax_reports/portugal.py +++ b/jal/data_export/tax_reports/portugal.py @@ -1,8 +1,9 @@ from decimal import Decimal from datetime import datetime, timezone -from jal.constants import PredefinedAsset -from jal.db.operations import AssetPayment +from jal.constants import PredefinedAsset, PredefinedCategory +from jal.db.operations import AssetPayment, CorporateAction from jal.data_export.taxes import TaxReport +from jal.db.category import JalCategory class TaxesPortugal(TaxReport): @@ -14,7 +15,8 @@ def __init__(self): self._processed_trade_qty = {} # It will handle {trade_id: qty} records to keep track of already processed qty self.reports = { "Dividends": (self.prepare_dividends, "tax_prt_dividends.json"), - "Shares": (self.prepare_stocks_and_etf, "tax_prt_shares.json") + "Shares": (self.prepare_stocks_and_etf, "tax_prt_shares.json"), + "Interest": (self.prepare_broker_interest, "tax_prt_interests.json") } def prepare_dividends(self): @@ -106,3 +108,39 @@ def prepare_stocks_and_etf(self): deals_report.append(line) self.insert_totals(deals_report, ["income_eur", "spending_eur", "profit_eur", "profit"]) return deals_report + +# ---------------------------------------------------------------------------------------------------------------------- + def prepare_broker_interest(self): + interests_report = [] + interest_operations = JalCategory(PredefinedCategory.Interest).get_operations(self.year_begin, self.year_end) + interest_operations = [x for x in interest_operations if x.account_id() == self.account.id()] + for operation in interest_operations: + rate = self.account_currency.quote(operation.timestamp(), self._currency_id)[1] + interests = [x for x in operation.lines() if x['category_id'] == PredefinedCategory.Interest] + for interest in interests: + amount = Decimal(interest['amount']) + line = { + 'report_template': "interest", + 'payment_date': operation.timestamp(), + 'rate': rate, + 'amount': amount, + 'amount_eur': round(amount * rate, 2), + 'note': interest['note'] + } + interests_report.append(line) + # Process cash payments out of corporate actions + payments = CorporateAction.get_payments(self.account) + payments = [x for x in payments if self.year_begin <= x['timestamp'] <= self.year_end] + for payment in payments: + rate = self.account_currency.quote(payment['timestamp'], self._currency_id)[1] + line = { + 'report_template': "interest", + 'payment_date': payment['timestamp'], + 'rate': rate, + 'amount': payment['amount'], + 'amount_eur': round(payment['amount'] * rate, 2), + 'note': payment['note'] + } + interests_report.append(line) + self.insert_totals(interests_report, ["amount", "amount_eur"]) + return interests_report diff --git a/jal/data_export/templates/tax_prt_interests.json b/jal/data_export/templates/tax_prt_interests.json new file mode 100644 index 00000000..e84dfe89 --- /dev/null +++ b/jal/data_export/templates/tax_prt_interests.json @@ -0,0 +1,34 @@ +{ + "page": "Interest", + "title": "Interests report", + "headers": [ + "Period: {parameters[period]}", + "Account owner: ", + "Account: {parameters[account]}" + ], + "columns": [ + {"name": "Description", "width": 50}, + {"name": "Payment date", "width": 10}, + {"name": "EUR/{parameters[currency]} rate for payment date", "width": 10}, + {"name": "СAmount, {parameters[currency]}", "width": 10}, + {"name": "Amount, EUR", "width": 10} + ], + "columns_numbered": true, + "interest": { + "rows": [ + ["note", "payment_date", "rate", "amount", "amount_eur"] + ], + "formats": [ + ["T", "D", "N:4", "N:2", "N:2"] + ] + }, + "totals": { + "rows": [ + [null, null, "ИТОГО", "amount", "amount_eur"] + ], + "formats": [ + [null, null, "F", "F", "F"] + ] + }, + "footers": [] +} \ No newline at end of file