Add bulk Log Charged action to dashboard toolbar
Select multiple batteries, pick a date, and optionally increment charge cycles for all of them in one shot. Reuses the existing bulk-action form and POST /battery/bulk-action route; no new routes or migrations needed.
This commit is contained in:
@@ -470,6 +470,24 @@ def create_app(config_object="config"):
|
||||
db.commit()
|
||||
label = field_name.replace("_", " ").title()
|
||||
flash(f"Set {label} on {n} batter{'y' if n == 1 else 'ies'}.", "success")
|
||||
elif action == "log_charged":
|
||||
date_val = request.form.get("charged_date", "").strip()
|
||||
if not date_val:
|
||||
flash("Date is required.", "error")
|
||||
return redirect(url_for("dashboard"))
|
||||
increment = 1 if request.form.get("increment_cycles") else 0
|
||||
for b in batteries:
|
||||
db.add(ChargeLog(battery_id=b.id, charged_date=date_val,
|
||||
increment_cycles=increment, notes=None))
|
||||
if increment:
|
||||
b.charge_cycles = (b.charge_cycles or 0) + 1
|
||||
db.commit()
|
||||
flash(
|
||||
f"Logged charge date {date_val} for "
|
||||
f"{n} batter{'y' if n == 1 else 'ies'}"
|
||||
+ (" (+cycles)." if increment else "."),
|
||||
"success",
|
||||
)
|
||||
else:
|
||||
flash("Unknown action.", "error")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user