diff --git a/app/routes/investments.py b/app/routes/investments.py index 34a24fd..e41c609 100644 --- a/app/routes/investments.py +++ b/app/routes/investments.py @@ -37,6 +37,10 @@ class InvestmentForm(FlaskForm): ticker = StringField('Ticker Symbol', validators=[Optional(), Length(max=20)], description='e.g. AAPL, BTC-USD, VNM') asset_type = SelectField('Asset Type', choices=ASSET_TYPES, validators=[DataRequired()]) + shares = DecimalField('Shares / Units', validators=[Optional(), NumberRange(min=0)], + places=8, default=Decimal('0')) + avg_cost_basis = DecimalField('Avg Cost per Share', validators=[Optional(), NumberRange(min=0)], + places=4, default=Decimal('0')) notes = TextAreaField('Notes', validators=[Optional()]) submit = SubmitField('Save') @@ -157,9 +161,18 @@ def edit(id): inv.ticker = form.ticker.data.strip().upper() if form.ticker.data else None inv.asset_type = form.asset_type.data inv.notes = form.notes.data + # Manual override of shares/cost basis — only update if user provided values + if form.shares.data is not None: + inv.shares = form.shares.data + if form.avg_cost_basis.data is not None: + inv.avg_cost_basis = form.avg_cost_basis.data db.session.commit() flash('Investment updated.', 'success') return redirect(url_for('investments.detail', id=inv.id)) + # Pre-populate shares/cost for edit form + if request.method == 'GET': + form.shares.data = inv.shares + form.avg_cost_basis.data = inv.avg_cost_basis return render_template('investments/form.html', form=form, title='Edit Investment', inv=inv) diff --git a/app/templates/investments/form.html b/app/templates/investments/form.html index a026b8a..04d4d72 100644 --- a/app/templates/investments/form.html +++ b/app/templates/investments/form.html @@ -32,6 +32,34 @@ + + {% if inv %} +
+
+ Manual Override — Shares & Cost Basis +
+
+
+ {{ form.shares.label(class="form-label fw-medium", style="font-size:13px;") }} + {{ form.shares(class="form-control", placeholder="e.g. 10.5", id="sharesOverride") }} + Current: {{ inv.shares | shares }} +
+
+ {{ form.avg_cost_basis.label(class="form-label fw-medium", style="font-size:13px;") }} +
+ {{ current_user.currency_symbol }} + {{ form.avg_cost_basis(class="form-control", placeholder="e.g. 150.25") }} +
+ Current: {{ inv.avg_cost_basis | currency }} +
+
+
+ + Leave at current values to keep unchanged. These override the transaction log calculation. +
+
+ {% endif %} +
{{ form.notes.label(class="form-label fw-medium", style="font-size:13px;") }} {{ form.notes(class="form-control", rows=2, placeholder="Optional notes") }}