Fix avg_cost to return per-share cost basis

This commit is contained in:
Elvis De Abreu
2026-05-06 16:02:22 -05:00
parent dce2213a98
commit 38c438a614

View File

@@ -51,8 +51,8 @@ class Holding < ApplicationRecord
# - If locked (user-set), trust the value even if 0 (valid for airdrops)
# - Otherwise require positive since providers sometimes return 0 when unknown
if cost_basis.present?
if cost_basis_locked? || cost_basis.positive?
return Money.new(cost_basis, currency)
if (cost_basis_locked? || cost_basis.positive?) && qty.to_f > 0
return Money.new(cost_basis / qty, currency)
end
end