Forms ===== The ``transactions`` app ships two forms: the main transaction create / edit ``TransactionForm`` and the secondary ``PostClosedOrClosingTransactionForm`` shown when closing a transaction implicitly closes parent transactions or stakings. TransactionForm --------------- ``ModelForm`` for :class:`~richy.transactions.models.Transaction`. Constructed with the current ``user``: the ``item`` queryset is limited to that user's items, the ``parents`` queryset to that user's transactions (newest first), and most fields receive either a validator (``currency`` must be 3 alpha chars, ``price`` and ``fee`` must be ``>= 0``) or help text. Two extras layered on top of the model: * An ``attachments`` field (:class:`~richy.core.fields.MultipleFileField`) that lets the user attach / remove files alongside the transaction record. ``save()`` materializes each uploaded file as an :class:`~richy.transactions.models.Attachment` row. * The ``target`` field accepts either a plain numeric price or a percentage with a trailing ``%``; ``clean_target()`` enforces that regex. The form-level :meth:`~TransactionForm.clean` performs the cross-field validation: * Coin transactions must have an ``exchange`` selected. * A transaction marked ``is_deposit`` cannot also be ``is_closing``. * Only negative-amount transactions can be ``is_closing``. * Marking ``is_closed`` or ``is_closing`` requires a ``closed_on`` date. * Sell (negative-amount) transactions must have at least one ``parents`` entry. .. autoclass:: richy.transactions.forms.TransactionForm :show-inheritance: .. automethod:: richy.transactions.forms.TransactionForm.clean .. automethod:: richy.transactions.forms.TransactionForm.clean_target .. automethod:: richy.transactions.forms.TransactionForm.save PostClosedOrClosingTransactionForm ---------------------------------- Secondary follow-up form rendered by :class:`~richy.transactions.views.PostClosedOrClosingTransactionUpdateFormView` after a user closes a transaction whose chain of parent transactions and / or related stakings can be closed in the same gesture. It carries two optional fields: * ``parents`` -- the parent transactions to mark as closed. * ``stakings`` -- the related staking records to mark as sold. Both querysets are passed in from the view. .. autoclass:: richy.transactions.forms.PostClosedOrClosingTransactionForm :show-inheritance: