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.

class richy.transactions.models.Exchange(*args, **kwargs)[source]#

Bases: Model

Exchange model.

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: UserRelatedModel

Transaction model.

Transaction.get_market_value()[source]#

Calculates current market price of assets gained (bought) in this transaction (applies only for positive (buy) transactions).

Raises:

Exception – In case of negative transaction.

Returns:

Market price based on last known item price

Return type:

int or float

Transaction.get_value()[source]#

Calculates market price of assets bought or sold. The price is negative for sell transactions.

Returns:

Price of whole transaction.

Return type:

int or float

Transaction.get_user_item()[source]#
Transaction.delete(*args, **kwargs)[source]#

Removes whole attachments dir.

Three cached properties expose derived values:

  • is_positiveTrue when amount > 0 (a buy / deposit).

  • target_as_absolute_value – the user-entered target resolved to an absolute price (handles both "123" and "5%" inputs).

  • target_as_percents – the user-entered target resolved 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

ShareDividendTransaction#

class richy.transactions.models.ShareDividendTransaction(id, user, shares, amount, dividend)[source]#

Bases: BaseDividendTransaction

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.

class richy.transactions.models.AttachmentMixin[source]#

Bases: object

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: UserRelatedManager

ORM manager for Transaction model.