Friday, February 24, 2023
2 changes · master
Resolved issues and error corrections
Weekly filters now start on the correct day for the user's language and country settings, such as Sunday for U.S. English and Monday for Belgian French. This makes weekly views align with dashboard reporting and avoids confusing date ranges in business workflows like accounting bills.
Original PR description
Steps to reproduce: - Make sure language preference is 'en_US' - In accounting, in the dashboard click on bills - Filter 'due_date' by week Issue: The start day is Monday and should be, for 'en_US',…
Steps to reproduce:
- Make sure language preference is 'en_US'
- In accounting, in the dashboard click on bills
- Filter 'due_date' by week
Issue:
The start day is Monday and should be, for 'en_US', Sunday as it is the case in the dashboard view in accounting (see appendix)
Cause:
The query uses the `date_trunc('week', date)` which in postgress retrieves the first day of the week as Monday.
Solution:
Create an offset in the query depending on the first day of the locale variable.
Note:
the `web/tests/test_read_progress_bar.py` has been modified: since the default language is 'en_US' there will be an offset of one day.
To make it less confusing, I used only two anglo-saxons countries so the day offset is not the variable tested.
(for this matter, pleaser refer to `test_read_group/tests/test_read_group_process_groupby.py`)
Appendix:
Language (english-US)
VIEW (per week) | DASHBOARD
___________________________________________________________________
W23 -> 06/05 | 05/29 -> 06/04
W24 06/06 -> 06/12 | 06/05 -> 06/11
W25 06/13 -> | 06/12 -> 06/18
(Monday - Sunday) (Sunday - Saturday)
Language (french-BE)
VIEW (per week) | DASHBOARD
___________________________________________________________________
W22 -> 06/05 | 05/30 -> 06/05
W23 06/06 -> 06/12 | 06/06 -> 06/12
W24 06/13 -> | 06/13 -> 06/19
(Monday - Sunday) (Monday - Sunday)
```
First day of the week as in Babel:
>>> import babel
>>> locale = babel.Locale('en', 'US')
>>> locale.first_week_day
6
>>> locale.days['format']['wide'][locale.first_week_day]
'Sunday'
>>> locale = babel.Locale('fr', 'BE')
>>> locale.first_week_day
0
>>> locale.days['format']['wide'][locale.first_week_day]
'lundi'
```
opw-2747066Reports and views that group information by week now use the correct first day of the week for the user's locale. This makes weekly figures align with local business expectations and reduces confusion when comparing date-based results.
Original PR description
Companion of https://github.com/odoo/odoo/pull/93053