05/31 Update investment edit
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,34 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% if inv %}
|
||||
<div class="mb-3 p-3" style="background:#f0fdf4;border-radius:8px;border:1px solid #bbf7d0;">
|
||||
<div style="font-size:12px;font-weight:600;color:#166534;margin-bottom:10px;">
|
||||
<i class="bi bi-pencil-square me-1"></i>Manual Override — Shares & Cost Basis
|
||||
</div>
|
||||
<div class="row g-3">
|
||||
<div class="col-6">
|
||||
{{ form.shares.label(class="form-label fw-medium", style="font-size:13px;") }}
|
||||
{{ form.shares(class="form-control", placeholder="e.g. 10.5", id="sharesOverride") }}
|
||||
<small class="text-muted" style="font-size:11px;">Current: {{ inv.shares | shares }}</small>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
{{ form.avg_cost_basis.label(class="form-label fw-medium", style="font-size:13px;") }}
|
||||
<div class="input-group">
|
||||
<span class="input-group-text" style="font-size:12px;">{{ current_user.currency_symbol }}</span>
|
||||
{{ form.avg_cost_basis(class="form-control", placeholder="e.g. 150.25") }}
|
||||
</div>
|
||||
<small class="text-muted" style="font-size:11px;">Current: {{ inv.avg_cost_basis | currency }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div style="font-size:11px;color:#166534;margin-top:8px;">
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
Leave at current values to keep unchanged. These override the transaction log calculation.
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="mb-4">
|
||||
{{ form.notes.label(class="form-label fw-medium", style="font-size:13px;") }}
|
||||
{{ form.notes(class="form-control", rows=2, placeholder="Optional notes") }}
|
||||
|
||||
Reference in New Issue
Block a user