[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) <sgv@odoo.com>
Signed-off-by: Thomas Lefebvre (thle) <thle@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2023-09-29 10:41:50 +00:00
parent 44078cd674
commit dbd9942c21
+2 -3
View File
@@ -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