Skip to content

Commit

Permalink
The portfolio report was extended with sum of payments that were accu…
Browse files Browse the repository at this point in the history
…mulated during position was opened.
  • Loading branch information
titov-vv committed Feb 9, 2024
1 parent 947c01f commit 09640cf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
11 changes: 10 additions & 1 deletion jal/db/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,17 @@ def open_trades_list(self, asset, timestamp=None) -> list:
trades.append({"operation": operation, "price": price, "remaining_qty": qty})
return trades

# Returns amount that was paid for an asset that was hold on the account during time between start_ts and end_ts
# Asset payment is counted if its ex-date is between start and end or, if ex-date is missing, the timestamp of
# payment is between start and end timestamps
def asset_payments_amount(self, asset, start_ts, end_ts) -> Decimal:
return Decimal('0')
payments = jal.db.operations.Dividend.get_list(self._id, asset.id())
payments = [x for x in payments if (start_ts <= x.ex_date() <= end_ts) or (x.ex_date() == 0 and (start_ts <= x.timestamp() <= end_ts))]
if payments:
amount = sum([x.amount(currency_id=self._currency_id) for x in payments])
else:
amount = Decimal('0')
return amount

def _valid_data(self, data: dict, search: bool = False, create: bool = False) -> bool:
if data is None:
Expand Down
16 changes: 11 additions & 5 deletions jal/db/holdings_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, data=None, parent=None, group=''):
self._data = {
'currency_id': 0, 'currency': '', 'account_id': 0, 'account': '', 'asset_id': 0, 'tag': '',
'asset_is_currency': False, 'asset': '', 'asset_name': '', 'country_id': 0, 'country': '', 'expiry': 0,
'since': 0, 'qty': Decimal('0'), 'value_i': Decimal('0'),
'since': 0, 'qty': Decimal('0'), 'value_i': Decimal('0'), 'payments': Decimal('0'),
'quote': Decimal('0'), 'quote_ts': Decimal('0'), 'quote_a': Decimal('0')
}
else:
Expand All @@ -39,6 +39,7 @@ def _calculateGroupTotals(self, child_data):
self._data['asset'] = child_data['asset']
self._data['country'] = child_data['country']
self._data['tag'] = child_data['tag']
self._data['payments'] += child_data['payments']
self._data['value'] += child_data['value']
self._data['value_a'] += child_data['value_a']
self._data['profit'] += child_data['profit']
Expand Down Expand Up @@ -95,12 +96,13 @@ def __init__(self, parent_view):
{'name': self.tr("Share, %")},
{'name': self.tr("P/L, %")},
{'name': self.tr("P/L")},
{'name': self.tr("Paid")},
{'name': self.tr("Value")},
{'name': self.tr("Value, ")}]

def headerData(self, section, orientation, role=Qt.DisplayRole):
value = super().headerData(section, orientation, role)
if orientation == Qt.Horizontal and role == Qt.DisplayRole and section == 10:
if orientation == Qt.Horizontal and role == Qt.DisplayRole and section == 11:
value += self._currency_name
return value

Expand Down Expand Up @@ -172,12 +174,14 @@ def data_text(self, item, column):
if column == 8:
return localize_decimal(data['profit'], 2)
if column == 9:
return localize_decimal(data['value'], 2)
return localize_decimal(data['payments'], 2)
if column == 10:
return localize_decimal(data['value'], 2)
if column == 11:
return localize_decimal(data['value_a'], 2) if data['value_a'] else Setup.NULL_VALUE

def data_tooltip(self, data, column):
if 5 <= column <= 9:
if 5 <= column <= 10:
quote_date = datetime.utcfromtimestamp(int(data['quote_ts']))
quote_age = int((datetime.utcnow() - quote_date).total_seconds() / 86400)
if quote_age > 7:
Expand All @@ -201,7 +205,7 @@ def data_font(self, item, column):
else:
font.setItalic(True)
return font
if column >= 5 and column <= 9:
if column >= 5 and column <= 10:
quote_date = datetime.utcfromtimestamp(int(data['quote_ts']))
quote_age = int((datetime.utcnow()- quote_date).total_seconds() / 86400)
if quote_age > 7:
Expand Down Expand Up @@ -308,6 +312,7 @@ def prepareData(self):
"since": since,
"qty": asset_data['amount'],
"value_i": asset_data['value'],
"payments": payments_amount,
"quote": quote,
"quote_ts": quote_ts,
"quote_a": rate * quote
Expand All @@ -331,6 +336,7 @@ def prepareData(self):
"since": 0,
"qty": money,
"value_i": Decimal('0'),
"payments": Decimal('0'),
"quote": Decimal('1'),
"quote_ts": day_end(now_ts()),
"quote_a": rate
Expand Down
15 changes: 10 additions & 5 deletions jal/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1380,26 +1380,31 @@
</message>
<message>
<location filename="../db/holdings_model.py" line="98"/>
<source>Paid</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="99"/>
<source>Value</source>
<translation></translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="101"/>
<location filename="../db/holdings_model.py" line="102"/>
<source>Value, </source>
<translation></translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="184"/>
<location filename="../db/holdings_model.py" line="187"/>
<source>Last quote date: </source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="306"/>
<location filename="../db/holdings_model.py" line="309"/>
<source>N/A</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="329"/>
<location filename="../db/holdings_model.py" line="333"/>
<source>Money</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -1414,7 +1419,7 @@
<translation></translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="144"/>
<location filename="../db/holdings_model.py" line="145"/>
<source>Exp:</source>
<translation></translation>
</message>
Expand Down
15 changes: 10 additions & 5 deletions jal/languages/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1380,26 +1380,31 @@
</message>
<message>
<location filename="../db/holdings_model.py" line="98"/>
<source>Paid</source>
<translation>Выплачено</translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="99"/>
<source>Value</source>
<translation>Оценка</translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="101"/>
<location filename="../db/holdings_model.py" line="102"/>
<source>Value, </source>
<translation>Оценка, </translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="184"/>
<location filename="../db/holdings_model.py" line="187"/>
<source>Last quote date: </source>
<translation>Дата последней котировки: </translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="306"/>
<location filename="../db/holdings_model.py" line="309"/>
<source>N/A</source>
<translation>N/A</translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="329"/>
<location filename="../db/holdings_model.py" line="333"/>
<source>Money</source>
<translation>Деньги</translation>
</message>
Expand All @@ -1414,7 +1419,7 @@
<translation>Ценная бумага</translation>
</message>
<message>
<location filename="../db/holdings_model.py" line="144"/>
<location filename="../db/holdings_model.py" line="145"/>
<source>Exp:</source>
<translation>Эксп:</translation>
</message>
Expand Down

0 comments on commit 09640cf

Please sign in to comment.