Skip to content

Commit

Permalink
Portugues tax report deals format was improved to match IRS fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
titov-vv committed Jun 2, 2024
1 parent 0274db2 commit 5ff63e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
27 changes: 16 additions & 11 deletions jal/data_export/tax_reports/portugal.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ def prepare_stocks_and_etf(self):
else:
rate = self.account_currency.quote(trade.close_operation().settlement(), self._currency_id)[1]
if trade.qty() >= Decimal('0'): # Long trade
income = round(trade.close_amount(no_settlement=ns) - trade.close_fee(), 2)
spending = round(trade.open_amount(no_settlement=ns) + trade.open_fee(), 2)
inflation = self.inflation(trade.open_operation().timestamp())
value_realization = round(trade.close_amount(no_settlement=ns), 2)
value_acquisition = round(trade.open_amount(no_settlement=ns), 2)
inflation = self.inflation(trade.open_operation().settlement())
if inflation != Decimal('1'):
spending = spending * inflation
note = f"Acquisition inflation coefficient {inflation:.2f} for year {datetime.fromtimestamp(trade.open_operation().timestamp(), tz=timezone.utc).strftime('%Y')}\n"
value_acquisition = value_acquisition * inflation
note = f"Acquisition inflation coefficient {inflation:.2f} for year {datetime.fromtimestamp(trade.open_operation().settlement(), tz=timezone.utc).strftime('%Y')}\n"
else: # Short trade
income = round(trade.open_amount(no_settlement=ns) - trade.open_fee(), 2)
spending = round(trade.close_amount(no_settlement=ns) + trade.close_fee(), 2)
value_realization = round(trade.open_amount(no_settlement=ns), 2)
value_acquisition = round(trade.close_amount(no_settlement=ns), 2)
for modifier in trade.modified_by():
note = note + modifier.description() + "\n"
profit = value_realization - value_acquisition - trade.close_fee() - trade.open_fee()
line = {
'report_template': "trade",
'symbol': trade.asset().symbol(self.account_currency.id()),
Expand All @@ -92,16 +93,20 @@ def prepare_stocks_and_etf(self):
'os_date': trade.open_operation().settlement(),
'o_price': trade.open_price(),
'o_fee': trade.open_fee(),
'o_amount': spending,
'o_fee_eur': trade.open_fee() * rate,
'o_amount': value_acquisition,
'o_amount_eur': value_acquisition * rate,
'c_type': "Sell" if trade.qty() >= Decimal('0') else "Buy",
'c_number': trade.close_operation().number(),
'c_date': trade.close_operation().timestamp(),
'cs_date': trade.close_operation().settlement(),
'c_price': trade.close_operation().price(),
'c_fee': trade.close_fee(),
'c_amount': income,
'profit': income - spending,
'profit_eur': round((income - spending) * rate, 2),
'c_fee_eur': trade.close_fee() * rate,
'c_amount': value_realization,
'c_amount_eur': value_realization * rate,
'profit': round(profit, 2),
'profit_eur': round(profit * rate, 2),
'rate': rate,
'note': note
}
Expand Down
18 changes: 10 additions & 8 deletions jal/data_export/templates/tax_prt_shares.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
{"name": "Qty.", "width": 8},
{"name": "Price, {parameters[currency]}", "width": 12},
{"name": "Fee, {parameters[currency]}", "width": 12},
{"name": "Fee, EUR", "width": 12},
{"name": "Value, {parameters[currency]}", "width": 12},
{"name": "Value, EUR", "width": 12},
{"name": "Profit/Loss, {parameters[currency]}", "width": 10},
{"name": "Profit/Loss, EUR", "width": 10},
{"name": "EUR/{parameters[currency]} rate", "width": 9},
Expand All @@ -25,24 +27,24 @@
"columns_numbered": true,
"trade": {
"rows": [
["symbol", "isin", "o_number", "o_type", "o_date", "os_date", "qty", "o_price", "o_fee", "o_amount", "profit", "profit_eur", "rate", "note"],
[null, null, "c_number", "c_type", "c_date", "cs_date", null, "c_price", "c_fee", "c_amount", null, null, null, null]
["symbol", "isin", "o_number", "o_type", "o_date", "os_date", "qty", "o_price", "o_fee", "o_fee_eur", "o_amount", "o_amount_eur", "profit", "profit_eur", "rate", "note"],
[null, null, "c_number", "c_type", "c_date", "cs_date", null, "c_price", "c_fee", "c_fee_eur", "c_amount", "c_amount_eur", null, null, null, null]
],
"formats": [
["T", "N:0", "T", "T", "D", "D", "T", "N:6", "N:6", "N:2", "N:2", "N:2", "N:4", "T"],
[null, null, "T", "T", "D", "D", null, "N:6", "N:6", "N:2", null, null, null, null]
["T", "N:0", "T", "T", "D", "D", "T", "N:6", "N:6", "N:2", "N:2", "N:2", "N:2", "N:2", "N:4", "T"],
[null, null, "T", "T", "D", "D", null, "N:6", "N:6", "N:2", "N:2", "N:2", null, null, null, null]
],
"span": [
[{"h": 0, "v": 1}, {"h": 0, "v": 1}, null, null, null, null, {"h": 0, "v": 1}, null, null, null, {"h": 0, "v": 1}, {"h": 0, "v": 1}, {"h": 0, "v": 1}, {"h": 0, "v": 1}],
[null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]
[{"h": 0, "v": 1}, {"h": 0, "v": 1}, null, null, null, null, {"h": 0, "v": 1}, null, null, null, null, null, {"h": 0, "v": 1}, {"h": 0, "v": 1}, {"h": 0, "v": 1}, {"h": 0, "v": 1}],
[null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]
]
},
"totals": {
"rows": [
[null, null, null, null, null, null, null, null, null, "TOTAL", "profit", "profit_eur", null, null]
[null, null, null, null, null, null, null, null, null, null, null, "TOTAL", "profit", "profit_eur", null, null]
],
"formats": [
[null, null, null, null, null, null, null, null, null, "F", "F", "F", null, null]
[null, null, null, null, null, null, null, null, null, null, null, "F", "F", "F", null, null]
]
},
"footers": []
Expand Down

0 comments on commit 5ff63e1

Please sign in to comment.