Skip to content

Add one-time backfill for dividend investment_amount_cents#1610

Open
nyomanjyotisa wants to merge 1 commit intomainfrom
backfill-dividend-investment-amounts
Open

Add one-time backfill for dividend investment_amount_cents#1610
nyomanjyotisa wants to merge 1 commit intomainfrom
backfill-dividend-investment-amounts

Conversation

@nyomanjyotisa
Copy link
Member

@nyomanjyotisa nyomanjyotisa commented Feb 12, 2026

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

image

Dividends Before

image

Dividends After

image

Case 2: User only has convertibles

Convertibles details

image

Dividends Before

image

Dividends After

image

Case 3: User has both shares and convertibles

Shares details

image

Convertibles details

image

Dividends Before

image

Dividends After

image

AI Disclosure

Claude Opus 4.6 for code generations. All codes self reviewed

# 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
Copy link
Member Author

Choose a reason for hiding this comment

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

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?
Copy link
Member Author

@nyomanjyotisa nyomanjyotisa Feb 12, 2026

Choose a reason for hiding this comment

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

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)
Copy link
Member Author

Choose a reason for hiding this comment

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

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)
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above, but for convertibles

@nyomanjyotisa nyomanjyotisa requested a review from ershad February 12, 2026 06:38
@nyomanjyotisa
Copy link
Member Author

@ershad _a Could you help to review this?

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.

2 participants