From 94542c63778dbce2c8f57a6dd312044c0db03f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gw=C3=A9na=C3=ABl=20Rault?= Date: Wed, 21 May 2025 12:06:12 +0200 Subject: [PATCH] Historize date should be planning date if set manually --- lib/history.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/history.rb b/lib/history.rb index 5dc03b2c2..0be5332f8 100644 --- a/lib/history.rb +++ b/lib/history.rb @@ -21,13 +21,17 @@ def self.historize(hourly, planning_id) ActiveRecord::Base.connection.execute(" DELETE FROM history_stops WHERE - date_trunc('day', date) = date_trunc('day', now()) AND + date_trunc('day', date) = + date_trunc('day', COALESCE( + (SELECT date FROM plannings WHERE id = #{planning_id || 'NULL'}), + now() + )) AND (planning_id IS NULL OR planning_id = #{planning_id || 'NULL'}) ; INSERT INTO history_stops SELECT (SELECT max(version) FROM schema_migrations) AS schema_version, - #{hourly ? 'date_trunc(\'hour\', now())' : 'now()'} AS date, + #{hourly ? 'date_trunc(\'hour\', now())' : 'COALESCE(plannings.date, now())'} AS date, customers.reseller_id AS reseller_id, customers.id AS customer_id, vehicle_usages.id AS vehicle_usage_id,