Skip to content

Commit

Permalink
[FIX] fleet: always include current month in costs report
Browse files Browse the repository at this point in the history
When consulting the costs reports, if the beginning of the dates range
has a day greater than the day of today (e.g., start date: 2021/02/25,
today: 2021/07/10 => 25 > 10), the costs of the current month won't be
include in the report.

To reproduce the issue:
(DB without any demo data. Let X be the day of the month for today)
1. Create a vehicle V
2. Add a service S1 for V
    - The category of the service type does not matter
    - Cost: 500
    - Date: today
3. Add a second service S2 for V
    - Same service type
    - Cost: 250
    - Date: Last month with a day > X (so if today is 2021/07/26, date
could be 2021/06/27)
4. Fleet > Reporting > Costs

Error: The report does not include S1

When generating the dates range, the current date is used as the end of
the interval. Since the interval step is '1 month', it will lead to an
issue in the above case:
Suppose today is 2021/07/26, the interval starts on 2021/06/27. Then, if
we add one month to this date, we have 2021/07/27, which is after the
end of the interval (2021/07/26), so the date is ignored. As a result,
current month won't be included in the report.

Note: A similar issue can happen with the contracts

OPW-2477004

closes #74219

Signed-off-by: Kevin Baptiste <kba@odoo.com>
  • Loading branch information
adwid committed Jul 26, 2021
1 parent 8d362af commit 7ea6300
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addons/fleet/report/fleet_report.py
Expand Up @@ -43,7 +43,7 @@ def init(self):
CROSS JOIN generate_series((
SELECT
min(date)
FROM fleet_vehicle_log_services), CURRENT_DATE, '1 month') d
FROM fleet_vehicle_log_services), CURRENT_DATE + '1 month'::interval, '1 month') d
LEFT JOIN fleet_vehicle_log_services se ON se.vehicle_id = ve.id
AND date_trunc('month', se.date) = date_trunc('month', d)
WHERE
Expand Down Expand Up @@ -74,7 +74,7 @@ def init(self):
CROSS JOIN generate_series((
SELECT
min(acquisition_date)
FROM fleet_vehicle), CURRENT_DATE, '1 month') d
FROM fleet_vehicle), CURRENT_DATE + '1 month'::interval, '1 month') d
LEFT JOIN fleet_vehicle_log_contract co ON co.vehicle_id = ve.id
AND date_trunc('month', co.date) = date_trunc('month', d)
LEFT JOIN fleet_vehicle_log_contract cod ON cod.vehicle_id = ve.id
Expand Down

0 comments on commit 7ea6300

Please sign in to comment.