Skip to content

fix(storage): count OPENING quantity in asset total_quantity - #260

Merged
asiniscalchi merged 2 commits into
mainfrom
fix/opening-quantity-in-total
Aug 28, 2026
Merged

fix(storage): count OPENING quantity in asset total_quantity#260
asiniscalchi merged 2 commits into
mainfrom
fix/opening-quantity-in-total

Conversation

@a-mandala

Copy link
Copy Markdown
Collaborator

Problem

Importing existing holdings uses OPENING transactions. The total_quantity subquery in assets.rs computed SUM(CASE transaction_type WHEN 'BUY' THEN quantity ELSE -quantity END), so OPENING rows were subtracted, the sum went negative, and map_asset_row filtered it to None. The Assets page showed no owned quantity.

Fix

Count only SELL as a reduction: BUY and OPENING both increase the position.

Tests

  • New: opening_transaction_counts_toward_asset_total_quantity (RED before fix, GREEN after)
  • Full suite: 276 passed; cargo fmt + clippy clean

The total_quantity subquery treated every non-BUY transaction as a
reduction, so OPENING positions (used to import existing holdings)
were subtracted and the sum went negative. map_asset_row filters
non-positive quantities to None, hiding holdings on the assets page.

Count only SELL as a reduction: BUY and OPENING both increase the
position.
@asiniscalchi
asiniscalchi merged commit 4d1ef37 into main Aug 28, 2026
4 checks passed
@asiniscalchi
asiniscalchi deleted the fix/opening-quantity-in-total branch August 28, 2026 14:38
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