Merge lp:~openerp-dev/openobject-addons/7.0-opw-602404-jam into lp:openobject-addons/7.0

Proposed by Jigar A.
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-opw-602404-jam
Merge into: lp:openobject-addons/7.0
Diff against target: 62 lines (+24/-3)
1 file modified
project_timesheet/project_timesheet.py (+24/-3)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-opw-602404-jam
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+199885@code.launchpad.net

This proposal supersedes a proposal from 2013-12-21.

Description of the change

Fixed The Incorrect Date on Timesheets Bog [Ticket#602404]

Test Case Steps: (IMP: Time Zone used PST, -8 from UTC)
1. Go to Projects, then Tasks
2. Click any task and hit the Edit button
3. Under Work Summary, click the Add An Item link
4. Enter a work summary, a time
5. For date, put a time that is later in the day, such as 8 PM. Check that the date i.e., 12/20/13
6. Hit the Save button.
7. Go to Human Resources, then My Timesheet
8. Hit the Edit button, then enter in a new line item in the Details tab (this refreshes the list to grab the entry you just made from the project task).
9. Hit Save.
10. Go to the Summary tab.
11. The item you entered into the task will show up for next day (i.e., 12/21/13).

This is issue is cause of datetime to date conversion, the Fix try to preserver the date in user timezone instaed fo coveretd to UTC, every time when we go to Datetime to date / date to datetime, we have to be careful about date.

Kindly review the fix.
--
PS: Earlier we have fixed similler issue for date to datetime.[Bug #1153107]

To post a comment you must log in.
9709. By Jigar A.

[FIX] datetime to date when creating the project task timehseet line

9710. By Jigar A.

[MERGE] Parent Sync

Unmerged revisions

9710. By Jigar A.

[MERGE] Parent Sync

9709. By Jigar A.

[FIX] datetime to date when creating the project task timehseet line

9708. By Jigar A.

[FIX] Ticket 602404 : Incorrect Date on Timesheets with timezones

9707. By Jigar A.

[MERGE] Sync lp:openobject-addons/7.0

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'project_timesheet/project_timesheet.py'
2--- project_timesheet/project_timesheet.py 2013-06-07 11:38:29 +0000
3+++ project_timesheet/project_timesheet.py 2014-01-07 21:24:36 +0000
4@@ -20,11 +20,12 @@
5 ##############################################################################
6 import time
7 import datetime
8-
9+import pytz
10 from openerp.osv import fields, osv
11 from openerp import pooler
12 from openerp import tools
13 from openerp.tools.translate import _
14+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP
15
16 class project_project(osv.osv):
17 _inherit = 'project.project'
18@@ -105,6 +106,26 @@
19 res['product_uom_id'] = emp.product_id.uom_id.id
20 return res
21
22+ def datetime_to_date(self, cr, uid, userdate, context=None):
23+ """ Convert datetime values expressed in UTC timezone to
24+ server-side UTC date while keeping date in user time zone only.
25+ Preserves the date from datetime, Time has to be ingonred here.
26+ :param str userdate: datetime string in in utc timezone
27+ :return: UTC date string for server-side use
28+ """
29+ user_date = datetime.datetime.strptime(userdate, DEFAULT_SERVER_DATETIME_FORMAT)
30+ if context and context.get('tz'):
31+ tz_name = context['tz']
32+ else:
33+ tz_name = self.pool.get('res.users').read(cr, SUPERUSER_ID, uid, ['tz'])['tz']
34+ if tz_name:
35+ utc = pytz.timezone('UTC')
36+ context_tz = pytz.timezone(tz_name)
37+ local_timestamp = user_date.replace(tzinfo=utc)
38+ local_timestamp = local_timestamp.astimezone(context_tz)
39+ return local_timestamp.strftime(DEFAULT_SERVER_DATE_FORMAT)
40+ return user_date.strftime(DEFAULT_SERVER_DATE_FORMAT)
41+
42 def create(self, cr, uid, vals, *args, **kwargs):
43 timesheet_obj = self.pool.get('hr.analytic.timesheet')
44 task_obj = self.pool.get('project.task')
45@@ -118,7 +139,7 @@
46 vals_line['name'] = '%s: %s' % (tools.ustr(task_obj.name), tools.ustr(vals['name'] or '/'))
47 vals_line['user_id'] = vals['user_id']
48 vals_line['product_id'] = result['product_id']
49- vals_line['date'] = vals['date'][:10]
50+ vals_line['date'] = self.datetime_to_date(cr, uid, vals['date'],context=context)
51
52 # Calculate quantity based on employee's product's uom
53 vals_line['unit_amount'] = vals['hours']
54@@ -176,7 +197,7 @@
55 if 'user_id' in vals:
56 vals_line['user_id'] = vals['user_id']
57 if 'date' in vals:
58- vals_line['date'] = vals['date'][:10]
59+ vals_line['date'] = self.datetime_to_date(cr, uid, vals['date'],context=context)
60 if 'hours' in vals:
61 vals_line['unit_amount'] = vals['hours']
62 prod_id = vals_line.get('product_id', line_id.product_id.id) # False may be set