Add one-time backfill for dividend investment_amount_cents#1610
Open
nyomanjyotisa wants to merge 1 commit intomainfrom
Open
Add one-time backfill for dividend investment_amount_cents#1610nyomanjyotisa wants to merge 1 commit intomainfrom
nyomanjyotisa wants to merge 1 commit intomainfrom
Conversation
nyomanjyotisa
commented
Feb 12, 2026
| # Onetime::BackfillDividendInvestmentAmounts.perform(dry_run: true) # Preview only | ||
| # Onetime::BackfillDividendInvestmentAmounts.perform(dry_run: false) # Actually update | ||
| class Onetime::BackfillDividendInvestmentAmounts | ||
| SKIPPED_DIVIDEND_ROUND_IDS = [9, 12].freeze |
Member
Author
There was a problem hiding this comment.
Skip dividend round 9 and 12 since the investment amount not exist in the database, we need the original CSV for these, and will be handled in different PR
| end | ||
|
|
||
| def calculate_investment_amount(dividend, company_investor, issued_at) | ||
| if dividend.number_of_shares.present? |
Member
Author
There was a problem hiding this comment.
If number_of_shares exist means the dividend come from shares, since convertibles has no number_of_shares
| def calculate_investment_amount(dividend, company_investor, issued_at) | ||
| if dividend.number_of_shares.present? | ||
| company_investor.share_holdings | ||
| .where("issued_at <= ?", issued_at) |
Member
Author
There was a problem hiding this comment.
Sum total_amount_in_cents from the share_holdings only if the shares issued before the dividend issued, so that the new issued shared not added to the investment amount for old issued dividend
| else | ||
| company_investor.convertible_securities | ||
| .where("issued_at <= ?", issued_at) | ||
| .sum(:principal_value_in_cents) |
Member
Author
There was a problem hiding this comment.
Same as above, but for convertibles
Member
Author
|
@ershad _a Could you help to review this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: #1596
Description
Add one-time backfill for dividend investment_amount_cents for all dividend rounds except dividend rounds 9 and 12, since those dividend rounds need the original CSV to backfill
Before/After
Case 1: User only has shares
Shares details
Dividends Before
Dividends After
Case 2: User only has convertibles
Convertibles details
Dividends Before
Dividends After
Case 3: User has both shares and convertibles
Shares details
Convertibles details
Dividends Before
Dividends After
AI Disclosure
Claude Opus 4.6 for code generations. All codes self reviewed