Skip to content

Commit

Permalink
Portugues tax report was extended with list of interest payments.
Browse files Browse the repository at this point in the history
  • Loading branch information
titov-vv committed May 30, 2024
1 parent fa5e49a commit 0274db2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
44 changes: 41 additions & 3 deletions jal/data_export/tax_reports/portugal.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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
34 changes: 34 additions & 0 deletions jal/data_export/templates/tax_prt_interests.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit 0274db2

Please sign in to comment.