diff options
| author | abd-msyukyu-odoo <abd@odoo.com> | 2021-04-27 14:43:13 +0000 |
|---|---|---|
| committer | abd-msyukyu-odoo <abd@odoo.com> | 2021-05-06 09:19:07 +0000 |
| commit | 665e9538005832b557f30f7a6663b25cf3e7c169 (patch) | |
| tree | 2e6c1dfe4548352ee7caa79aa17ab5110d3acf3d /addons/web | |
| parent | e0bafb0715a270b1032647474bde40ca680beff4 (diff) | |
[FIX] web: fix kanban view progressbars related to records in another group (groupby:week)
* IMPACTED VERSIONS
12.0+
* HOW TO REPRODUCE
locale : Locale is en_US (or other SUNDAY based)
view: CRM - My Pipeline - Kanban view
groupBy: date_deadline:week (Expected closing)
records: one record with a planned activity, on date_deadline = 2021-05-02 (SUNDAY)
one record with no planned activity, on date_deadline = 2021-05-09 (SUNDAY)
remark: don't keep any other record in MAY for better visibility
* PROBLEM
The progressbar of the week containing 2021-05-09 displays information about the record
from the week containing 2021-05-02
* CAUSE
1. PostgreSQL `date_trunc` function follows ISO8601 which essentially means that
the start of a WEEK is always MONDAY. There is no argument to change this.
2. _read_group_format_result
https://github.com/odoo/odoo/blob/27da86a138089c1838e4b94f8a6976995b9c1fff/odoo/models.py#L2210-L2219
- Computes a label for a group of records.
- Follows the locale for the label of the week, based on a date which is
always a MONDAY because of `date_trunc`.
3. read_progress_bar
https://github.com/odoo/odoo/blob/88957afca09662af7eaa19df1e40b3699e45e79e/addons/web/models/models.py#L167-L175
- Associates a group label to a record.
- Follows the locale for the label of the week, based on the date of a record
which can be any day of the week. If the record is related to a SUNDAY and
SUNDAY is the first day of the week, it would have been in a group with a
different label in (2.) than in (3.) prior to this change.
* FIX
In 3., before associating a label to a record, we truncate the date to the
ISO start of the period, so that the label is determined for a record in the
same conditions than in 2. The locale is still used to get language-dependent
outputs with babel, but the grouping will always follows ISO8601 (date_trunc).
* TEST
Added a test for this problem case
TASK-ID : 2517848
closes odoo/odoo#70453
X-original-commit: c08f6e3e9a084944ea711d33b2421f845c560d3f
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/models/models.py | 4 | ||||
| -rw-r--r-- | addons/web/tests/__init__.py | 1 | ||||
| -rw-r--r-- | addons/web/tests/test_read_progress_bar.py | 44 |
3 files changed, 47 insertions, 2 deletions
diff --git a/addons/web/models/models.py b/addons/web/models/models.py index 092dd9a1681..2852d12067c 100644 --- a/addons/web/models/models.py +++ b/addons/web/models/models.py @@ -7,7 +7,7 @@ import json from odoo import _, _lt, api, fields, models from odoo.osv.expression import AND, TRUE_DOMAIN, normalize_domain -from odoo.tools import lazy +from odoo.tools import date_utils, lazy from odoo.tools.misc import get_lang from odoo.exceptions import UserError from collections import defaultdict @@ -161,7 +161,7 @@ class Base(models.AbstractModel): # Again, imitating what _read_group_format_result and _read_group_prepare_data do if group_by_value and field_type in ['date', 'datetime']: locale = get_lang(self.env).code - group_by_value = fields.Datetime.to_datetime(group_by_value) + group_by_value = date_utils.start_of(fields.Datetime.to_datetime(group_by_value), group_by_modifier) group_by_value = pytz.timezone('UTC').localize(group_by_value) tz_info = None if field_type == 'datetime' and self._context.get('tz') in pytz.all_timezones: diff --git a/addons/web/tests/__init__.py b/addons/web/tests/__init__.py index 5008bb7fabe..daac593d42e 100644 --- a/addons/web/tests/__init__.py +++ b/addons/web/tests/__init__.py @@ -7,3 +7,4 @@ from . import test_menu from . import test_serving_base from . import test_click_everywhere from . import test_base_document_layout +from . import test_read_progress_bar diff --git a/addons/web/tests/test_read_progress_bar.py b/addons/web/tests/test_read_progress_bar.py new file mode 100644 index 00000000000..7c6721773bc --- /dev/null +++ b/addons/web/tests/test_read_progress_bar.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +from odoo.tests import common + + +class TestReadProgressBar(common.TransactionCase): + """Test for read_progress_bar""" + + def setUp(self): + super(TestReadProgressBar, self).setUp() + self.Model = self.env['res.partner'] + + def test_week_grouping(self): + """The labels associated to each record in read_progress_bar should match + the ones from read_group, even in edge cases like en_US locale on sundays + """ + context = {"lang": "en_US"} + groupby = "date:week" + self.Model.create({'date': '2021-05-02', 'name': "testWeekGrouping_first"}) # Sunday + self.Model.create({'date': '2021-05-09', 'name': "testWeekGrouping_second"}) # Sunday + progress_bar = { + 'field': 'name', + 'colors': { + "testWeekGrouping_first": 'success', + "testWeekGrouping_second": 'danger', + } + } + + groups = self.Model.with_context(context).read_group( + [('name', "like", "testWeekGrouping%")], fields=['date', 'name'], groupby=[groupby]) + progressbars = self.Model.with_context(context).read_progress_bar( + [('name', "like", "testWeekGrouping%")], group_by=groupby, progress_bar=progress_bar) + self.assertEqual(len(groups), 2) + self.assertEqual(len(progressbars), 2) + + # format the read_progress_bar result to get a dictionary under this format : {record_name: group_name} + # original format (after read_progress_bar) is : {group_name: {record_name: count}} + pg_groups = { + next(record_name for record_name, count in data.items() if count): group_name \ + for group_name, data in progressbars.items() + } + + self.assertEqual(groups[0][groupby], pg_groups["testWeekGrouping_first"]) + self.assertEqual(groups[1][groupby], pg_groups["testWeekGrouping_second"]) |
