From 5ff63e1a282aaa62960a68d1683d258c7d9196c4 Mon Sep 17 00:00:00 2001 From: Vlad <55182132+titov-vv@users.noreply.github.com> Date: Sun, 2 Jun 2024 14:17:00 +0100 Subject: [PATCH] Portugues tax report deals format was improved to match IRS fields. --- jal/data_export/tax_reports/portugal.py | 27 +++++++++++-------- jal/data_export/templates/tax_prt_shares.json | 18 +++++++------ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/jal/data_export/tax_reports/portugal.py b/jal/data_export/tax_reports/portugal.py index e92053a6..09b210f1 100644 --- a/jal/data_export/tax_reports/portugal.py +++ b/jal/data_export/tax_reports/portugal.py @@ -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()), @@ -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 } diff --git a/jal/data_export/templates/tax_prt_shares.json b/jal/data_export/templates/tax_prt_shares.json index fc3c3e00..fa77aa2c 100644 --- a/jal/data_export/templates/tax_prt_shares.json +++ b/jal/data_export/templates/tax_prt_shares.json @@ -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}, @@ -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": []