Models#
The transactions app contains the portfolio ledger: buy / sell /
deposit transactions, dividend-transaction records that bridge raw
dividends into per-transaction amounts, and per-transaction
attachments.
Exchange#
A trading venue – “Binance”, “Kraken”, “Coinbase”, etc. Referenced
from Transaction (and from
richy.staking.models.Staking) so positions can be filtered
by exchange.
Transaction#
The core portfolio record. A Transaction is a single
buy / sell / deposit move on an Item. It
tracks price, amount, fee, date, exchange, currency, and three flags
(is_closing, is_closed, is_deposit) that classify it
inside the parent / child chain the application uses to compute
profits, market values and dividends.
The parents self-referential many-to-many is the backbone of
transaction chaining: a closing sale links back to the buys it
closes; dividend-transactions link back to the deposits that earned
them.
- class richy.transactions.models.Transaction(*args, **kwargs)[source]#
Bases:
UserRelatedModelTransaction model.
- Transaction.get_market_value()[source]#
Calculates current market price of assets gained (bought) in this transaction (applies only for positive (buy) transactions).
- Transaction.get_value()[source]#
Calculates market price of assets bought or sold. The price is negative for sell transactions.
Three cached properties expose derived values:
is_positive–Truewhenamount > 0(a buy / deposit).target_as_absolute_value– the user-enteredtargetresolved to an absolute price (handles both"123"and"5%"inputs).target_as_percents– the user-enteredtargetresolved to a percentage change from the transaction price.
Dividend transactions#
ShareDividendTransaction and EtfDividendTransaction bridge
raw richy.shares.models.Dividend /
richy.etfs.models.Dividend records into per-user,
per-deposit payouts: each row says “this user, this dividend, this
many shares, this much money, paid against these transactions”.
They share an abstract base.
BaseDividendTransaction#
- class richy.transactions.models.BaseDividendTransaction(*args, **kwargs)[source]#
Bases:
UserRelatedModel
EtfDividendTransaction#
- class richy.transactions.models.EtfDividendTransaction(id, user, shares, amount, dividend)[source]#
Bases:
BaseDividendTransaction
Attachments#
Per-transaction file attachments. Files live under
MEDIA_ROOT/transactions/<transaction_pk>/; deleting the
Transaction row – or the Attachment row directly – removes
the file from disk via AttachmentMixin.delete.
AttachmentMixin#
Shared mixin used by Attachment here and by
richy.staking.models.Attachment – ensures the on-disk file
is removed when the model row is deleted.
Attachment#
- class richy.transactions.models.Attachment(id, transaction, file)[source]#
Bases:
Model,AttachmentMixin
Managers and querysets#
TransactionManager and TransactionQuerySet extend
UserRelatedManager /
UserRelatedQuerySet (see
Models) with one additional filter:
positive_balance – restricts to transactions whose item currently has a positive aggregate balance (
SUM(amount) > 0). Used to skip already-exhausted positions on the portfolio overview.
- class richy.transactions.models.TransactionQuerySet(model=None, query=None, using=None, hints=None)[source]#
Bases:
UserRelatedQuerySet
- class richy.transactions.models.TransactionManager(*args, **kwargs)[source]#
Bases:
UserRelatedManagerORM manager for Transaction model.