Permalink
Browse files

[ADD] patch

  • Loading branch information...
GabbasovDinar committed Jun 21, 2018
1 parent 5394949 commit 983860c6bcea5afaaa3fb32365140151ad3b9a1a
@@ -0,0 +1,75 @@
From d83720172376a7cabe097c4a5ed202dc9c90ca83 Mon Sep 17 00:00:00 2001
From: GabbasovDinar <gabbasov@it-projects.info>
Date: Thu, 21 Jun 2018 13:38:32 +0500
Subject: [PATCH] [IMP] support grouping by weeks starting with Sunday
---
openerp/models.py | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/openerp/models.py b/openerp/models.py
index ef1d925..d7a6dcc 100644
--- a/openerp/models.py
+++ b/openerp/models.py
@@ -1947,6 +1947,7 @@ class BaseModel(object):
# Cfr: http://babel.pocoo.org/docs/dates/#date-fields
'day': 'dd MMM yyyy', # yyyy = normal year
'week': "'W'w YYYY", # w YYYY = ISO week-year
+ 'week_sunday': "'W'w'(s)' YYYY", # w YYYY = ISO week-year
'month': 'MMMM yyyy',
'quarter': 'QQQ yyyy',
'year': 'yyyy',
@@ -1954,13 +1955,27 @@ class BaseModel(object):
time_intervals = {
'day': dateutil.relativedelta.relativedelta(days=1),
'week': datetime.timedelta(days=7),
+ 'week_sunday': datetime.timedelta(days=7),
'month': dateutil.relativedelta.relativedelta(months=1),
'quarter': dateutil.relativedelta.relativedelta(months=3),
'year': dateutil.relativedelta.relativedelta(years=1)
}
if tz_convert:
qualified_field = "timezone('%s', timezone('UTC',%s))" % (self._context.get('tz', 'UTC'), qualified_field)
- qualified_field = "date_trunc('%s', %s)" % (gb_function or 'month', qualified_field)
+
+ if gb_function == 'week_sunday':
+ # postgres's date_trunc supports only weeks starting with Monday
+ # So, make this hack to support weeks starting with Sunday
+
+ if field_type == 'date':
+ # interger must be used to don't convert DATE to TIMESTAMP
+ interval_day = "integer '1'"
+ else:
+ interval_day = "interval '1 day'"
+ qualified_field = "date_trunc('week', %s + %s)" % (qualified_field, interval_day)
+ else:
+ qualified_field = "date_trunc('%s', %s)" % (gb_function or 'month', qualified_field)
+
if field_type == 'boolean':
qualified_field = "coalesce(%s,false)" % qualified_field
return {
@@ -1995,6 +2010,10 @@ class BaseModel(object):
a given value. This is mostly relevant for date/datetime.
"""
if groupby['type'] in ('date', 'datetime') and value:
+ if ':week_sunday' in groupby['groupby']:
+ # postgres's date_trunc supports only weeks starting with Monday
+ # So, make this hack to support weeks starting with Sunday
+ value -= dateutil.relativedelta.relativedelta(days=1)
dt_format = DEFAULT_SERVER_DATETIME_FORMAT if groupby['type'] == 'datetime' else DEFAULT_SERVER_DATE_FORMAT
domain_dt_begin = value
domain_dt_end = value + groupby['interval']
@@ -2017,6 +2036,10 @@ class BaseModel(object):
for k,v in data.iteritems():
gb = groupby_dict.get(k)
if gb and gb['type'] in ('date', 'datetime') and v:
+ if ':week_sunday' in gb['groupby']:
+ # postgres's date_trunc supports only weeks starting with Monday
+ # So, make this hack to support weeks starting with Sunday
+ v -= dateutil.relativedelta.relativedelta(days=1)
data[k] = babel.dates.format_date(v, format=gb['display_format'], locale=context.get('lang', 'en_US'))
data['__domain'] = domain_group + domain
--
1.9.1
@@ -6,6 +6,11 @@ Installation
============
* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way
* To use the module, you need to be sure that your odoo instance support longpolling, i.e. Instant Messaging works. Read more about how to use the `longpolling <https://odoo-development.readthedocs.io/en/latest/admin/longpolling.html>`_
* You need to install a patch to use the new group (the beginning of the week is Sunday). The use of the patch is optional and needed only to use Sunday grouping (otherwise only Monday works). More `here. <https://github.com/odoo/odoo/pull/25086>`__ To apply the patch execute::
cd /path/to/odoo/source
patch -p1 < /path/to/0001-IMP-support-grouping-by-weeks-starting-with-Sunday.patch
Usage
=====
@@ -37,8 +42,3 @@ Forced completion of the task
Uninstallation
==============
* Open the``Project timelog`` module by going to Apps and click on the ``Uninstall`` button.
Note
====
* To use the module, you need to be sure that your odoo instance support longpolling, i.e. Instant Messaging works. Read more about how to use the `longpolling <https://odoo-development.readthedocs.io/en/latest/admin/longpolling.html>`_

0 comments on commit 983860c

Please sign in to comment.