From dbd9942c21bcf349a2986a085b36f0350d11fb7b Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Thu, 21 Sep 2023 15:29:34 +0200 Subject: [PATCH] [FIX] fleet: manage recurring yearly costs in report Issue: ------ Contracts with a "Yearly" recurring cost are not applied every year in the report. Cause: ------ We use truncation to compare dates. The following condition: ```sql date_trunc('month', coy.date) = date_trunc('month', d) ``` can be read as: "When year and month are the same". The `date_trunc` function sets to "zero" the parts of the date we want to truncate. This is why the recurrence only appears for one year. Solution: --------- Use the date comparison provided with postgresql and use `date_part` function to check the month. opw-3468253 closes odoo/odoo#137060 X-original-commit: f2ed4a179bb10cbca1d095389deac75dd8ca054f Signed-off-by: Sofie Gvaladze (sgv) Signed-off-by: Thomas Lefebvre (thle) --- addons/fleet/report/fleet_report.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/fleet/report/fleet_report.py b/addons/fleet/report/fleet_report.py index 9ff4e9bef09..737445c895c 100644 --- a/addons/fleet/report/fleet_report.py +++ b/addons/fleet/report/fleet_report.py @@ -94,9 +94,8 @@ contract_costs AS ( AND date_trunc('month', com.expiration_date) >= date_trunc('month', d) AND com.cost_frequency = 'monthly' LEFT JOIN fleet_vehicle_log_contract coy ON coy.vehicle_id = ve.id - AND date_trunc('month', coy.date) = date_trunc('month', d) - AND date_trunc('month', coy.start_date) <= date_trunc('month', d) - AND date_trunc('month', coy.expiration_date) >= date_trunc('month', d) + AND d BETWEEN coy.start_date and coy.expiration_date + AND date_part('month', coy.date) = date_part('month', d) AND coy.cost_frequency = 'yearly' WHERE ve.active