Skip to content

refactor(activity): create paired deposit for funded buys#727

Open
kwaich wants to merge 2 commits intoafadil:mainfrom
kwaich:feat/include-cash-deposit
Open

refactor(activity): create paired deposit for funded buys#727
kwaich wants to merge 2 commits intoafadil:mainfrom
kwaich:feat/include-cash-deposit

Conversation

@kwaich
Copy link
Contributor

@kwaich kwaich commented Mar 15, 2026

Description

When a buy activity is marked as "includes cash deposit", automatically create a paired DEPOSIT
transaction for the same account, amount, and date. This ensures the portfolio cash balance
reflects the inflow before the buy executes, giving accurate performance and cash tracking.

Changes:

  • New mutation logic in use-activity-mutations.ts to create/update/delete the paired deposit in sync with the buy
  • Buy form updated to expose the "includes cash deposit" toggle and pass the flag through correctly
  • Form schema and config aligned to handle the includes_cash_deposit field
  • Tests added for mutations and form schema behaviour

Checklist

By submitting this PR, I agree to the
CLA.

@afadil
Copy link
Owner

afadil commented Mar 18, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65de6b42f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +171 to +173
pub fn includes_cash_deposit(&self) -> bool {
self.get_meta::<bool>(METADATA_INCLUDE_CASH_DEPOSIT)
.unwrap_or(false)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Treat string include_cash_deposit as enabled

The new includes_cash_deposit() helper only reads a JSON boolean (get_meta::<bool>), so records with metadata like "include_cash_deposit": "true" are evaluated as false. This is a real input shape the frontend now handles when loading BUY defaults, and it means prefunded buys from that data path will still debit cash and will not book the external contribution, causing incorrect cash balances and net contribution values until the activity is manually rewritten.

Useful? React with 👍 / 👎.

@afadil
Copy link
Owner

afadil commented Mar 18, 2026

Not sure about this one. This is what external TransferIn does.

If it's for UX convenience, I wouldn't impact the calculator and the backend; I would just make the frontend create two activities.

@Jonjon-prog
Copy link

Agree with Afadil on that.
Better to keep the 2 activities as the same time, like this you don't have any cash balance hide.

@kwaich
Copy link
Contributor Author

kwaich commented Mar 19, 2026

yeah that make sense and keeps it simple, thanks

@kwaich kwaich changed the title feat(activity): support prefunded buy with implicit cash deposit refactor(activity): create paired deposit for funded buys Mar 19, 2026
When a buy activity is marked as funded (includes_cash_deposit=true),
automatically create a paired DEPOSIT transaction for the same account,
amount, and date. This ensures the portfolio's cash balance reflects
the inflow before the buy is executed, giving accurate performance tracking.
@kwaich kwaich force-pushed the feat/include-cash-deposit branch from 5d795b4 to 2e96f1b Compare March 19, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants