From bab0e1d5fb8c2325285983786b5e732777cbc7aa Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 26 Feb 2022 17:38:58 +0100 Subject: [PATCH] Fixed battery charge cycle undo handling (fixes #1800) --- changelog/67_UNRELEASED_xxxx-xx-xx.md | 1 + migrations/0172.sql | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 migrations/0172.sql diff --git a/changelog/67_UNRELEASED_xxxx-xx-xx.md b/changelog/67_UNRELEASED_xxxx-xx-xx.md index 1dadf7f9..7d7d684c 100644 --- a/changelog/67_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/67_UNRELEASED_xxxx-xx-xx.md @@ -40,6 +40,7 @@ - Fixed that the batteries overview page was broken when there was any battery Userfields with enabled "Show as column in tables" option - Fixed that grocycode label printer printing didn't work from the battery edit page (master data) (thanks @andreheuer) +- Fixed that undoing a battery charge cycle had no effect on "Last charged" and "Next planned charge cycle" of the corresponding battery ### Equipment diff --git a/migrations/0172.sql b/migrations/0172.sql new file mode 100644 index 00000000..87bfeb72 --- /dev/null +++ b/migrations/0172.sql @@ -0,0 +1,17 @@ +DROP VIEW batteries_current; +CREATE VIEW batteries_current +AS +SELECT + b.id, -- Dummy, LessQL needs an id column + b.id AS battery_id, + MAX(l.tracked_time) AS last_tracked_time, + CASE WHEN b.charge_interval_days = 0 + THEN '2999-12-31 23:59:59' + ELSE datetime(MAX(l.tracked_time), '+' || CAST(b.charge_interval_days AS TEXT) || ' day') + END AS next_estimated_charge_time +FROM batteries b +LEFT JOIN battery_charge_cycles l + ON b.id = l.battery_id + AND l.undone = 0 +WHERE b.active = 1 +GROUP BY b.id, b.charge_interval_days;