Skip to content

Commit

Permalink
Duplicated methods were removed from TaxReport class.
Browse files Browse the repository at this point in the history
  • Loading branch information
titov-vv committed May 22, 2024
1 parent 2978a53 commit 704ac37
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
4 changes: 2 additions & 2 deletions jal/data_export/tax_reports/portugal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from decimal import Decimal
from datetime import datetime, timezone

from jal.constants import PredefinedAsset
from jal.db.operations import AssetPayment
from jal.data_export.taxes import TaxReport

Expand Down Expand Up @@ -60,7 +60,7 @@ def inflation(self, timestamp: int) -> Decimal:
def prepare_stocks_and_etf(self):
deals_report = []
ns = not self.use_settlement
trades = self.shares_trades_list()
trades = self.trades_list([PredefinedAsset.Stock, PredefinedAsset.ETF])
for trade in trades:
note = ''
if ns:
Expand Down
6 changes: 3 additions & 3 deletions jal/data_export/tax_reports/russia.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ def prepare_trades_report(self, trades_list):

# -----------------------------------------------------------------------------------------------------------------------
def prepare_stocks_and_etf(self):
trades = self.shares_trades_list()
trades = self.trades_list([PredefinedAsset.Stock, PredefinedAsset.ETF])
return self.prepare_trades_report(trades)

# -----------------------------------------------------------------------------------------------------------------------
def prepare_bonds(self):
country = self.account.country()
bonds_report = []
ns = not self.use_settlement
trades = self.bonds_trades_list()
trades = self.trades_list([PredefinedAsset.Bond])
for trade in trades:
if ns:
os_rate = self.account_currency.quote(trade.open_operation().timestamp(), self._currency_id)[1]
Expand Down Expand Up @@ -258,7 +258,7 @@ def prepare_bonds(self):

# -----------------------------------------------------------------------------------------------------------------------
def prepare_derivatives(self):
trades = self.derivatives_trades_list()
trades = self.trades_list([PredefinedAsset.Derivative])
return self.prepare_trades_report(trades)

# -----------------------------------------------------------------------------------------------------------------------
Expand Down
16 changes: 2 additions & 14 deletions jal/data_export/taxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,8 @@ def dividends_list(self) -> list:
return dividends

# Returns a list of closed stock/ETF trades that should be included into the report for given year
def shares_trades_list(self) -> list:
def trades_list(self, asset_type) -> list:
trades = self.account.closed_trades_list()
trades = [x for x in trades if x.asset().type() in [PredefinedAsset.Stock, PredefinedAsset.ETF]]
trades = [x for x in trades if self.year_begin <= x.close_operation().settlement() <= self.year_end]
return trades

def derivatives_trades_list(self) -> list:
trades = self.account.closed_trades_list()
trades = [x for x in trades if x.asset().type() == PredefinedAsset.Derivative]
trades = [x for x in trades if self.year_begin <= x.close_operation().settlement() <= self.year_end]
return trades

def bonds_trades_list(self) -> list:
trades = self.account.closed_trades_list()
trades = [x for x in trades if x.asset().type() == PredefinedAsset.Bond]
trades = [x for x in trades if x.asset().type() in asset_type]
trades = [x for x in trades if self.year_begin <= x.close_operation().settlement() <= self.year_end]
return trades

0 comments on commit 704ac37

Please sign in to comment.