Merge lp:~camptocamp/hr-timesheet/7.0-port-hr_timesheet_holidays into lp:~hr-core-editors/hr-timesheet/7.0

Proposed by Yannick Vaucher @ Camptocamp
Status: Merged
Merged at revision: 64
Proposed branch: lp:~camptocamp/hr-timesheet/7.0-port-hr_timesheet_holidays
Merge into: lp:~hr-core-editors/hr-timesheet/7.0
Diff against target: 807 lines (+303/-307)
9 files modified
hr_timesheet_holidays/__init__.py (+16/-24)
hr_timesheet_holidays/__openerp__.py (+61/-46)
hr_timesheet_holidays/company.py (+21/-35)
hr_timesheet_holidays/company_view.xml (+15/-15)
hr_timesheet_holidays/hr_holidays.py (+21/-34)
hr_timesheet_holidays/hr_holidays_view.xml (+31/-33)
hr_timesheet_holidays/wizard/__init__.py (+16/-24)
hr_timesheet_holidays/wizard/holidays_import.py (+88/-61)
hr_timesheet_holidays/wizard/holidays_import_view.xml (+34/-35)
To merge this branch: bzr merge lp:~camptocamp/hr-timesheet/7.0-port-hr_timesheet_holidays
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp code review, no test Approve
Joël Grand-Guillaume @ camptocamp code review, no tests Approve
Stefan Rijnhart (Opener) code review Approve
Maxime Chambreuil (http://www.savoirfairelinux.com) Needs Fixing
Nicolas Bessi - Camptocamp credentials Pending
Review via email: mp+162124@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

please fix to use full paths in import of openerp submodules such as osv (spotted at least on line 219 and 516).

review: Needs Fixing (code review, no test)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

is the code you use tested with regards to timezone issues?

review: Needs Information (code review, no test)
Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) wrote :

l58/79: you renoved the original author

review: Needs Fixing
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

You are right I will fix that

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

About author on l58/79, it seems it was miscopied as the main creator of this module was JB Aubort. So it seems more correct to set him on __openerp__.py.

Let's have Nicolas check about this.

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Updated with DEFAULT_SERVER_DATE_FORMAT for time formatting

Plus timezone conversion from UTC to user's timezone.

This will need some patch in addons to make it work.

Here is the patch for addons:
https://code.launchpad.net/~camptocamp/openobject-addons/7.0-fix-hr_timesheet_sheet-timezone-20130723

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Patch was accepted in OCB addons.

Ready for review !

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks! What happens when you run this branch on standard OpenERP branches? Maybe add a disclaimer about this in the module description.

Otherwise approved. I noticed that some column names changed in hr_holiday_rel but this should be alright as it concerns a transient model.

review: Approve (code review)
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

LGTM, Thanks !

review: Approve (code review, no tests)
53. By Yannick Vaucher @ Camptocamp

[IMP] __openerp__.py

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

@stefan Thanks for the review. I added the disclaimer and reStructured __openerp__.py

Please merge it

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

@Maxime can you update your review Status ? Thanks

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) :
review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hr_timesheet_holidays/__init__.py' (properties changed: +x to -x)
2--- hr_timesheet_holidays/__init__.py 2011-08-12 12:53:16 +0000
3+++ hr_timesheet_holidays/__init__.py 2013-12-06 15:47:24 +0000
4@@ -1,29 +1,21 @@
5+# -*- coding: utf-8 -*-
6 ##############################################################################
7 #
8-# Copyright (c) 2008 Camtocamp SA
9-# @author JB Aubort
10-# $Id: $
11-#
12-# WARNING: This program as such is intended to be used by professional
13-# programmers who take the whole responsability of assessing all potential
14-# consequences resulting from its eventual inadequacies and bugs
15-# End users who are looking for a ready-to-use solution with commercial
16-# garantees and support are strongly adviced to contract a Free Software
17-# Service Company
18-#
19-# This program is Free Software; you can redistribute it and/or
20-# modify it under the terms of the GNU General Public License
21-# as published by the Free Software Foundation; either version 2
22-# of the License, or (at your option) any later version.
23-#
24-# This program is distributed in the hope that it will be useful,
25-# but WITHOUT ANY WARRANTY; without even the implied warranty of
26-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27-# GNU General Public License for more details.
28-#
29-# You should have received a copy of the GNU General Public License
30-# along with this program; if not, write to the Free Software
31-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32+# Author: JB Aubort
33+# Copyright 2008 Camptocamp SA
34+#
35+# This program is free software: you can redistribute it and/or modify
36+# it under the terms of the GNU Affero General Public License as
37+# published by the Free Software Foundation, either version 3 of the
38+# License, or (at your option) any later version.
39+#
40+# This program is distributed in the hope that it will be useful,
41+# but WITHOUT ANY WARRANTY; without even the implied warranty of
42+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43+# GNU Affero General Public License for more details.
44+#
45+# You should have received a copy of the GNU Affero General Public License
46+# along with this program. If not, see <http://www.gnu.org/licenses/>.
47 #
48 ##############################################################################
49 import hr_holidays
50
51=== modified file 'hr_timesheet_holidays/__openerp__.py' (properties changed: +x to -x)
52--- hr_timesheet_holidays/__openerp__.py 2012-12-13 12:20:12 +0000
53+++ hr_timesheet_holidays/__openerp__.py 2013-12-06 15:47:24 +0000
54@@ -1,59 +1,74 @@
55 # -*- coding: utf-8 -*-
56 ##############################################################################
57 #
58-# @author Bessi Nicolas
59-# WARNING: This program as such is intended to be used by professional
60-# programmers who take the whole responsability of assessing all potential
61-# consequences resulting from its eventual inadequacies and bugs
62-# End users who are looking for a ready-to-use solution with commercial
63-# garantees and support are strongly adviced to contract a Free Software
64-# Service Company
65-#
66-# This program is Free Software; you can redistribute it and/or
67-# modify it under the terms of the GNU General Public License
68-# as published by the Free Software Foundation; either version 2
69-# of the License, or (at your option) any later version.
70-#
71-# This program is distributed in the hope that it will be useful,
72-# but WITHOUT ANY WARRANTY; without even the implied warranty of
73-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74-# GNU General Public License for more details.
75-#
76-# You should have received a copy of the GNU General Public License
77-# along with this program; if not, write to the Free Software
78-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
79+# Author: JB Aubort
80+# Copyright 2008 Camptocamp SA
81+#
82+# This program is free software: you can redistribute it and/or modify
83+# it under the terms of the GNU Affero General Public License as
84+# published by the Free Software Foundation, either version 3 of the
85+# License, or (at your option) any later version.
86+#
87+# This program is distributed in the hope that it will be useful,
88+# but WITHOUT ANY WARRANTY; without even the implied warranty of
89+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90+# GNU Affero General Public License for more details.
91+#
92+# You should have received a copy of the GNU Affero General Public License
93+# along with this program. If not, see <http://www.gnu.org/licenses/>.
94 #
95 ##############################################################################
96
97-{
98- "name" : "Import holidays in timesheets",
99- "version" : "1.0",
100- "author" : "Camptocamp",
101- "category" : "Generic Modules/Human Resources",
102- "description":
103-"""
104-Wizard to import holidays in the current timesheet.
105+{'name' : 'Import holidays in timesheets',
106+ 'version' : '1.0',
107+ 'category' : 'Generic Modules/Human Resources',
108+ 'description': """
109+Wizard to import holidays in the current timesheet
110+==================================================
111+
112 This module adds a relation between the Leave Types and the Analytic Accounts.
113-The Timesheet lines are created on the Analytic Account defined on the Leave Type.
114+The Timesheet lines are created on the Analytic Account defined on the Leave
115+Type.
116
117 The hours to input per day is configurable at company level.
118-
119+
120 Limitations:
121- - Consider that the work days are Monday to Friday
122- - The wizard creates the attendances each day with Sign-ins at 00:00 and Sign-outs at (00:00 + configured timesheet hours per day).
123+
124+- Consider that the work days are Monday to Friday
125+- The wizard creates the attendances each day with Sign-ins at 00:00 and
126+ Sign-outs at (00:00 + configured timesheet hours per day).
127+
128+.. warning::
129+ If you are using official addons instead of OCB addons.
130+ In order to avoid timezone issues, please ensure the
131+ following fix is installed on your system `Fix for Bug #1179893`_
132+
133+.. _Fix for Bug #1179893: https://code.launchpad.net/~camptocamp/openobject-addons/7.0-fix-hr_timesheet_sheet-timezone-20130723/+merge/176459
134+
135+Contributors
136+------------
137+
138+* Jean-Baptiste Aubort <jean-baptiste.aubort@camptocamp.com>
139+* Guewen Baconnier <guewen.baconnier@camptocamp.com>
140+* Yannick Vaucher <yannick.vaucher@camptocamp.com>
141
142 """,
143- "website": "http://www.camptocamp.com",
144- "depends" : ["hr",
145- "account",
146- "hr_holidays",
147- "hr_timesheet_sheet"],
148- "init_xml" : [],
149- "update_xml" : [
150- 'hr_holidays_view.xml',
151- 'wizard/holidays_import_view.xml',
152- 'company_view.xml',
153- ],
154- "active": False,
155- 'installable': False
156+ 'author' : 'Camptocamp',
157+ 'website': 'http://www.camptocamp.com',
158+ 'depends' : [
159+ 'hr',
160+ 'account',
161+ 'hr_holidays',
162+ 'hr_timesheet_sheet'
163+ ],
164+ 'data' : [
165+ 'hr_holidays_view.xml',
166+ 'wizard/holidays_import_view.xml',
167+ 'company_view.xml',
168+ ],
169+ 'installable': True,
170+ 'auto_install': False,
171+ 'application': False,
172 }
173+
174+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
175
176=== modified file 'hr_timesheet_holidays/company.py'
177--- hr_timesheet_holidays/company.py 2011-08-12 12:53:16 +0000
178+++ hr_timesheet_holidays/company.py 2013-12-06 15:47:24 +0000
179@@ -1,47 +1,33 @@
180 # -*- coding: utf-8 -*-
181 ##############################################################################
182 #
183-# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com)
184-# All Right Reserved
185-#
186-# Author : Guewen Baconnier (Camptocamp)
187-#
188-# WARNING: This program as such is intended to be used by professional
189-# programmers who take the whole responsability of assessing all potential
190-# consequences resulting from its eventual inadequacies and bugs
191-# End users who are looking for a ready-to-use solution with commercial
192-# garantees and support are strongly adviced to contract a Free Software
193-# Service Company
194-#
195-# This program is Free Software; you can redistribute it and/or
196-# modify it under the terms of the GNU General Public License
197-# as published by the Free Software Foundation; either version 2
198-# of the License, or (at your option) any later version.
199-#
200-# This program is distributed in the hope that it will be useful,
201-# but WITHOUT ANY WARRANTY; without even the implied warranty of
202-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
203-# GNU General Public License for more details.
204-#
205-# You should have received a copy of the GNU General Public License
206-# along with this program; if not, write to the Free Software
207-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
208+# Author: Guewen Baconnier (Camptocamp)
209+# Copyright 2011 Camptocamp SA
210+#
211+# This program is free software: you can redistribute it and/or modify
212+# it under the terms of the GNU Affero General Public License as
213+# published by the Free Software Foundation, either version 3 of the
214+# License, or (at your option) any later version.
215+#
216+# This program is distributed in the hope that it will be useful,
217+# but WITHOUT ANY WARRANTY; without even the implied warranty of
218+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
219+# GNU Affero General Public License for more details.
220+#
221+# You should have received a copy of the GNU Affero General Public License
222+# along with this program. If not, see <http://www.gnu.org/licenses/>.
223 #
224 ##############################################################################
225-
226-from osv import osv, fields
227-
228-
229-class res_company(osv.osv):
230-
231+from openerp.osv import orm, fields
232+
233+class ResCompany(orm.Model):
234 _inherit = 'res.company'
235-
236 _columns = {
237 'timesheet_hours_per_day': fields.float('Timesheet Hours Per Day', digits=(2,2))
238- }
239+ }
240
241 _defaults = {
242 'timesheet_hours_per_day': 8.0
243- }
244+ }
245
246-res_company()
247+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
248
249=== modified file 'hr_timesheet_holidays/company_view.xml'
250--- hr_timesheet_holidays/company_view.xml 2011-08-12 12:53:16 +0000
251+++ hr_timesheet_holidays/company_view.xml 2013-12-06 15:47:24 +0000
252@@ -1,18 +1,18 @@
253 <?xml version="1.0" encoding="utf-8"?>
254 <openerp>
255- <data>
256- <record model="ir.ui.view" id="view_company_inherit_form">
257- <field name="name">res.company.form.inherit</field>
258- <field name="inherit_id" ref="base.view_company_form"/>
259- <field name="model">res.company</field>
260- <field name="type">form</field>
261- <field name="priority">18</field>
262- <field name="arch" type="xml">
263- <field name="timesheet_max_difference" position="after">
264- <field name="timesheet_hours_per_day" widget="float_time"/>
265- </field>
266- </field>
267- </record>
268-
269- </data>
270+ <data>
271+
272+ <record model="ir.ui.view" id="view_company_inherit_form">
273+ <field name="name">res.company.form.inherit</field>
274+ <field name="inherit_id" ref="base.view_company_form"/>
275+ <field name="model">res.company</field>
276+ <field name="priority">18</field>
277+ <field name="arch" type="xml">
278+ <field name="timesheet_max_difference" position="after">
279+ <field name="timesheet_hours_per_day" widget="float_time"/>
280+ </field>
281+ </field>
282+ </record>
283+
284+ </data>
285 </openerp>
286
287=== modified file 'hr_timesheet_holidays/hr_holidays.py' (properties changed: +x to -x)
288--- hr_timesheet_holidays/hr_holidays.py 2011-08-12 12:53:16 +0000
289+++ hr_timesheet_holidays/hr_holidays.py 2013-12-06 15:47:24 +0000
290@@ -1,43 +1,30 @@
291 # -*- coding: utf-8 -*-
292 ##############################################################################
293 #
294-# Copyright (c) 2008 Camtocamp SA
295-# @author JB Aubort
296-# $Id: $
297-#
298-# WARNING: This program as such is intended to be used by professional
299-# programmers who take the whole responsability of assessing all potential
300-# consequences resulting from its eventual inadequacies and bugs
301-# End users who are looking for a ready-to-use solution with commercial
302-# garantees and support are strongly adviced to contract a Free Software
303-# Service Company
304-#
305-# This program is Free Software; you can redistribute it and/or
306-# modify it under the terms of the GNU General Public License
307-# as published by the Free Software Foundation; either version 2
308-# of the License, or (at your option) any later version.
309-#
310-# This program is distributed in the hope that it will be useful,
311-# but WITHOUT ANY WARRANTY; without even the implied warranty of
312-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
313-# GNU General Public License for more details.
314-#
315-# You should have received a copy of the GNU General Public License
316-# along with this program; if not, write to the Free Software
317-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
318+# Author: JB Aubort
319+# Copyright 2008 Camptocamp SA
320+#
321+# This program is free software: you can redistribute it and/or modify
322+# it under the terms of the GNU Affero General Public License as
323+# published by the Free Software Foundation, either version 3 of the
324+# License, or (at your option) any later version.
325+#
326+# This program is distributed in the hope that it will be useful,
327+# but WITHOUT ANY WARRANTY; without even the implied warranty of
328+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
329+# GNU Affero General Public License for more details.
330+#
331+# You should have received a copy of the GNU Affero General Public License
332+# along with this program. If not, see <http://www.gnu.org/licenses/>.
333 #
334 ##############################################################################
335-from osv import osv, fields
336-
337-
338-class hr_holidays_status(osv.osv):
339+from openerp.osv import orm, fields
340+
341+class HrHolidaysStatus(orm.Model):
342 """Add analytic account to holiday status"""
343-
344 _inherit = 'hr.holidays.status'
345-
346 _columns = {
347- 'analytic_account_id': fields.many2one("account.analytic.account",
348- "Analytic Account"),
349- }
350+ 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account'),
351+ }
352
353-hr_holidays_status()
354+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
355
356=== modified file 'hr_timesheet_holidays/hr_holidays_view.xml'
357--- hr_timesheet_holidays/hr_holidays_view.xml 2012-06-06 13:14:12 +0000
358+++ hr_timesheet_holidays/hr_holidays_view.xml 2013-12-06 15:47:24 +0000
359@@ -1,33 +1,31 @@
360-<?xml version="1.0"?>
361-<terp>
362- <data>
363-
364- <!-- add analytic account on holidays status -->
365- <record model="ir.ui.view" id="edit_holiday_status_form1">
366- <field name="name">hr.holidays.status.form</field>
367- <field name="model">hr.holidays.status</field>
368- <field name="inherit_id" ref="hr_holidays.edit_holiday_status_form"/>
369- <field name="priority" eval="20"/>
370- <field name="type">form</field>
371- <field name="arch" type="xml">
372- <field name="active" position="after">
373- <field name="analytic_account_id" />
374- </field>
375- </field>
376- </record>
377-
378- <record model="ir.ui.view" id="view_holiday_status_tree1">
379- <field name="name">hr.holidays.status.tree</field>
380- <field name="model">hr.holidays.status</field>
381- <field name="inherit_id" ref="hr_holidays.view_holiday_status_tree"/>
382- <field name="priority" eval="20"/>
383- <field name="type">tree</field>
384- <field name="arch" type="xml">
385- <field name="remaining_leaves" position="after">
386- <field name="analytic_account_id" />
387- </field>
388- </field>
389- </record>
390- </data>
391-</terp>
392-
393+<?xml version="1.0" encoding="utf-8"?>
394+<openerp>
395+ <data>
396+
397+ <!-- add analytic account on holidays status -->
398+ <record model="ir.ui.view" id="edit_holiday_status_form1">
399+ <field name="name">hr.holidays.status.form</field>
400+ <field name="model">hr.holidays.status</field>
401+ <field name="inherit_id" ref="hr_holidays.edit_holiday_status_form"/>
402+ <field name="priority" eval="20"/>
403+ <field name="arch" type="xml">
404+ <field name="active" position="after">
405+ <field name="analytic_account_id" />
406+ </field>
407+ </field>
408+ </record>
409+
410+ <record model="ir.ui.view" id="view_holiday_status_tree1">
411+ <field name="name">hr.holidays.status.tree</field>
412+ <field name="model">hr.holidays.status</field>
413+ <field name="inherit_id" ref="hr_holidays.view_holiday_status_normal_tree"/>
414+ <field name="priority" eval="20"/>
415+ <field name="arch" type="xml">
416+ <field name="limit" position="after">
417+ <field name="analytic_account_id" />
418+ </field>
419+ </field>
420+ </record>
421+
422+ </data>
423+</openerp>
424
425=== modified file 'hr_timesheet_holidays/wizard/__init__.py' (properties changed: +x to -x)
426--- hr_timesheet_holidays/wizard/__init__.py 2011-08-12 12:53:16 +0000
427+++ hr_timesheet_holidays/wizard/__init__.py 2013-12-06 15:47:24 +0000
428@@ -1,29 +1,21 @@
429+# -*- coding: utf-8 -*-
430 ##############################################################################
431 #
432-# Copyright (c) 2008 Camtocamp SA
433-# @author JB Aubort
434-# $Id: $
435-#
436-# WARNING: This program as such is intended to be used by professional
437-# programmers who take the whole responsability of assessing all potential
438-# consequences resulting from its eventual inadequacies and bugs
439-# End users who are looking for a ready-to-use solution with commercial
440-# garantees and support are strongly adviced to contract a Free Software
441-# Service Company
442-#
443-# This program is Free Software; you can redistribute it and/or
444-# modify it under the terms of the GNU General Public License
445-# as published by the Free Software Foundation; either version 2
446-# of the License, or (at your option) any later version.
447-#
448-# This program is distributed in the hope that it will be useful,
449-# but WITHOUT ANY WARRANTY; without even the implied warranty of
450-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
451-# GNU General Public License for more details.
452-#
453-# You should have received a copy of the GNU General Public License
454-# along with this program; if not, write to the Free Software
455-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
456+# Author: JB Aubort
457+# Copyright 2008 Camptocamp SA
458+#
459+# This program is free software: you can redistribute it and/or modify
460+# it under the terms of the GNU Affero General Public License as
461+# published by the Free Software Foundation, either version 3 of the
462+# License, or (at your option) any later version.
463+#
464+# This program is distributed in the hope that it will be useful,
465+# but WITHOUT ANY WARRANTY; without even the implied warranty of
466+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
467+# GNU Affero General Public License for more details.
468+#
469+# You should have received a copy of the GNU Affero General Public License
470+# along with this program. If not, see <http://www.gnu.org/licenses/>.
471 #
472 ##############################################################################
473 import holidays_import
474
475=== modified file 'hr_timesheet_holidays/wizard/holidays_import.py'
476--- hr_timesheet_holidays/wizard/holidays_import.py 2011-11-07 13:54:53 +0000
477+++ hr_timesheet_holidays/wizard/holidays_import.py 2013-12-06 15:47:24 +0000
478@@ -1,49 +1,58 @@
479 # -*- coding: utf-8 -*-
480 ##############################################################################
481 #
482-# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com)
483-# All Right Reserved
484-#
485-# Author : JB Aubort (Camptocamp)
486-# Author : Guewen Baconnier (Camptocamp)
487-#
488-# WARNING: This program as such is intended to be used by professional
489-# programmers who take the whole responsability of assessing all potential
490-# consequences resulting from its eventual inadequacies and bugs
491-# End users who are looking for a ready-to-use solution with commercial
492-# garantees and support are strongly adviced to contract a Free Software
493-# Service Company
494-#
495-# This program is Free Software; you can redistribute it and/or
496-# modify it under the terms of the GNU General Public License
497-# as published by the Free Software Foundation; either version 2
498-# of the License, or (at your option) any later version.
499-#
500-# This program is distributed in the hope that it will be useful,
501-# but WITHOUT ANY WARRANTY; without even the implied warranty of
502-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
503-# GNU General Public License for more details.
504-#
505-# You should have received a copy of the GNU General Public License
506-# along with this program; if not, write to the Free Software
507-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
508+# Author: JB Aubort (Camptocamp)
509+# Author: Guewen Baconnier (Camptocamp)
510+# Copyright 2011 Camptocamp SA
511+#
512+# This program is free software: you can redistribute it and/or modify
513+# it under the terms of the GNU Affero General Public License as
514+# published by the Free Software Foundation, either version 3 of the
515+# License, or (at your option) any later version.
516+#
517+# This program is distributed in the hope that it will be useful,
518+# but WITHOUT ANY WARRANTY; without even the implied warranty of
519+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
520+# GNU Affero General Public License for more details.
521+#
522+# You should have received a copy of the GNU Affero General Public License
523+# along with this program. If not, see <http://www.gnu.org/licenses/>.
524 #
525 ##############################################################################
526-
527-from osv import fields, osv
528-from tools.translate import _
529 from datetime import datetime, timedelta
530+from pytz import timezone
531+import pytz
532
533+from openerp.osv import orm, fields, osv
534+from openerp.tools.translate import _
535+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
536
537 def get_number_days_between_dates(date_from, date_to):
538- datetime_from = datetime.strptime(date_from, '%Y-%m-%d %H:%M:%S')
539- datetime_to = datetime.strptime(date_to, '%Y-%m-%d %H:%M:%S')
540+ datetime_from = datetime.strptime(date_from, DEFAULT_SERVER_DATETIME_FORMAT)
541+ datetime_to = datetime.strptime(date_to, DEFAULT_SERVER_DATETIME_FORMAT)
542 difference = datetime_to - datetime_from
543 # return result and add a day
544 return difference.days + 1
545
546-
547-class HolidaysImport(osv.osv_memory):
548+def get_start_of_day(date_str):
549+ dt_start = datetime.strptime(date_str, DEFAULT_SERVER_DATE_FORMAT)
550+ return dt_start.replace(hour=0, minute=0, second=0)
551+
552+def get_end_of_day(date_str):
553+ dt_end = datetime.strptime(date_str, DEFAULT_SERVER_DATE_FORMAT)
554+ return dt_end.replace(hour=23, minute=59, second=59)
555+
556+def get_utc_datetime(date, local_tz):
557+ local_dt = local_tz.localize(date)
558+ return local_dt.astimezone(pytz.utc)
559+
560+def get_utc_start_of_day(date_str, local_tz):
561+ return get_utc_datetime(get_start_of_day(date_str), local_tz)
562+
563+def get_utc_end_of_day(date_str, local_tz):
564+ return get_utc_datetime(get_end_of_day(date_str), local_tz)
565+
566+class HolidaysImport(orm.TransientModel):
567 _name = 'hr.timesheet.holidays.import'
568 _description = 'Wizard to import holidays in a timesheet'
569
570@@ -54,18 +63,26 @@
571
572 timesheet_id = context['active_id']
573 timesheet = timesheet_obj.browse(cr, uid, timesheet_id, context=context)
574- date_from = timesheet.date_from + ' 00:00:00'
575- date_to = timesheet.date_to + ' 23:59:59'
576+
577+ local_tz = timezone(context.get('tz'))
578+ date_from = get_start_of_day(timesheet.date_from)
579+ date_from_str = date_from.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
580+ date_utc_from = get_utc_datetime(date_from, local_tz).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
581+
582+ date_to = get_end_of_day(timesheet.date_to)
583+ date_to_str = date_to.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
584+ date_utc_to = get_utc_datetime(date_to, local_tz).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
585+
586 cr.execute("select id, date_from, date_to, name from hr_holidays where\
587 (\
588 ((date_from <= %s and date_to >= %s and date_to <= %s) or\
589 (date_from >= %s and date_from <= %s and date_to >= %s) or\
590 (date_from >= %s and date_from <= %s and date_to >= %s and date_to <= %s) or\
591 (date_from <= %s and date_to >= %s)) and user_id = %s and state = 'validate'\
592- )", (date_from, date_from, date_to,
593- date_from, date_to, date_to,
594- date_from, date_to, date_from, date_to,
595- date_from, date_to, uid))
596+ )", (date_utc_from, date_utc_from, date_utc_to,
597+ date_utc_from, date_utc_to, date_utc_to,
598+ date_utc_from, date_utc_to, date_utc_from, date_utc_to,
599+ date_utc_from, date_utc_to, uid))
600 holidays = cr.fetchall()
601 if not holidays:
602 raise osv.except_osv(_('Information'), _('No holidays for the current timesheet.'))
603@@ -74,15 +91,15 @@
604 valid = True
605 h_id = holiday[0]
606 h_date_from = holiday[1] < timesheet.date_from \
607- and date_from or holiday[1]
608+ and date_from_str or holiday[1]
609 h_date_to = holiday[2] > timesheet.date_to \
610- and date_to or holiday[2]
611+ and date_to_str or holiday[2]
612 h_name = holiday[3]
613
614 nb_days = get_number_days_between_dates(h_date_from, h_date_to)
615 for day in range(nb_days):
616- str_datetime_current = (datetime.strptime(h_date_from, '%Y-%m-%d %H:%M:%S')
617- + timedelta(days=day)).strftime('%Y-%m-%d')
618+ str_datetime_current = (datetime.strptime(h_date_from, DEFAULT_SERVER_DATETIME_FORMAT)
619+ + timedelta(days=day)).strftime(DEFAULT_SERVER_DATE_FORMAT)
620 line_ids = line_obj.search(cr, uid,
621 [('date', '=', str_datetime_current),
622 ('name', '=', h_name),
623@@ -97,14 +114,17 @@
624 return res
625
626 _columns = {
627- 'holidays_ids': fields.many2many('hr.holidays', 'hr_holidays_rel', 'wid', 'hid', 'Holidays', domain="[('state', '=', 'validate'),('user_id','=',uid)]"),
628- }
629+ 'holidays_ids': fields.many2many('hr.holidays', 'hr_holidays_rel', 'id', 'holiday_id', 'Holidays', domain="[('state', '=', 'validate'),('user_id','=',uid)]"),
630+ }
631
632 _defaults = {
633 'holidays_ids': _get_default_holidays,
634- }
635-
636- def import_holidays(self, cr, uid, ids, context):
637+ }
638+
639+ def import_holidays(self, cr, uid, ids, context=None):
640+ if context is None:
641+ context = {}
642+
643 timesheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
644 employee_obj = self.pool.get('hr.employee')
645 al_ts_obj = self.pool.get('hr.analytic.timesheet')
646@@ -130,6 +150,7 @@
647 if not wizard.holidays_ids:
648 raise osv.except_osv(_('Information'), _('No holidays to import.'))
649
650+ local_tz = timezone(context.get('tz'))
651 errors = []
652 for holiday in wizard.holidays_ids:
653 if not holiday.holiday_status_id.analytic_account_id.id:
654@@ -138,16 +159,22 @@
655 anl_account = anl_account_obj.browse(cr, uid, analytic_account_id, context)
656
657 if holiday.date_from < timesheet.date_from:
658- holiday.date_from = timesheet.date_from + ' 00:00:00'
659+ dt_ts_from = get_utc_start_of_day(timesheet.date_from, local_tz)
660+ holiday.date_from = dt_ts_from.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
661 if holiday.date_to > timesheet.date_to:
662- holiday.date_to = timesheet.date_to + ' 23:59:59'
663+ dt_ts_to = get_utc_end_of_day(timesheet.date_to, local_tz)
664+ holiday.date_to = dt_ts_to.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
665
666 nb_days = get_number_days_between_dates(holiday.date_from, holiday.date_to)
667 for day in range(nb_days):
668- dt_current = (datetime.strptime(holiday.date_from, '%Y-%m-%d %H:%M:%S')
669+ dt_current = (datetime.strptime(holiday.date_from, DEFAULT_SERVER_DATETIME_FORMAT)
670 + timedelta(days=day))
671- str_dt_current = dt_current.strftime('%Y-%m-%d')
672+ # datetime as date at midnight
673+ str_dt_current = dt_current.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
674+ dt_utc_current = get_utc_datetime(dt_current.replace(hour=0, minute=0, second=0), local_tz)
675+ str_dt_utc_current = dt_utc_current.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
676
677+ # Test if is week day in local tz
678 day_of_the_week = dt_current.isoweekday()
679
680 # skip the non work days
681@@ -175,7 +202,7 @@
682 'to_invoice': anl_account.to_invoice.id,
683 'sheet_id': timesheet.id,
684 'journal_id': journal_id,
685- }
686+ }
687
688 on_change_values = al_ts_obj.\
689 on_change_unit_amount(cr, uid, False, product_id,
690@@ -190,27 +217,26 @@
691
692 # Create attendances
693 existing_attendances = \
694- attendance_obj.search(cr, uid, [('name', '=', str_dt_current),
695+ attendance_obj.search(cr, uid, [('name', '=', str_dt_utc_current),
696 ('employee_id', '=', employee_id)])
697
698 if not existing_attendances:
699 # get hours and minutes (tuple) from a float time
700 hours = divmod(hours_per_day * 60, 60)
701-
702- date_end = dt_current.replace(hour=hours[0],minute=hours[1])
703- str_date_end = date_end.strftime('%Y-%m-%d %H:%M:%S')
704+ date_end = dt_utc_current + timedelta(hours=int(hours[0]), minutes=int(hours[1]))
705+ str_date_end = date_end.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
706 start = {
707- 'name': str_dt_current,
708+ 'name': str_dt_utc_current,
709 'action': 'sign_in',
710 'employee_id': employee_id,
711 'sheet_id': timesheet.id,
712- }
713+ }
714 end = {
715 'name': str_date_end,
716 'action': 'sign_out',
717 'employee_id': employee_id,
718 'sheet_id': timesheet.id,
719- }
720+ }
721 attendance_obj.create(cr, uid, start, context)
722 attendance_obj.create(cr, uid, end, context)
723 else:
724@@ -221,4 +247,5 @@
725
726 return {'type': 'ir.actions.act_window_close'}
727
728-HolidaysImport()
729+
730+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
731
732=== modified file 'hr_timesheet_holidays/wizard/holidays_import_view.xml'
733--- hr_timesheet_holidays/wizard/holidays_import_view.xml 2011-08-12 12:53:16 +0000
734+++ hr_timesheet_holidays/wizard/holidays_import_view.xml 2013-12-06 15:47:24 +0000
735@@ -1,38 +1,37 @@
736 <?xml version="1.0" encoding="utf-8"?>
737 <openerp>
738- <data>
739-
740- <record id="view_hr_timesheet_holidays_import" model="ir.ui.view">
741- <field name="name">hr.timesheet.holidays.import</field>
742- <field name="model">hr.timesheet.holidays.import</field>
743- <field name="type">form</field>
744- <field name="arch" type="xml">
745- <form string="Select holidays to import">
746- <field name="holidays_ids" nolabel="1" />
747- <group colspan="4" col="6">
748- <button icon="gtk-cancel" special="cancel" string="Cancel"/>
749- <button icon="gtk-ok" string="Import" name="import_holidays" type="object"/>
750- </group>
751- </form>
752- </field>
753- </record>
754-
755- <record id="action_hr_timesheet_holidays_import" model="ir.actions.act_window">
756- <field name="name">Import Holidays in Timesheet</field>
757- <field name="res_model">hr.timesheet.holidays.import</field>
758- <field name="view_type">form</field>
759- <field name="view_mode">form</field>
760- <field name="view_id" ref="view_hr_timesheet_holidays_import"/>
761- <field name="target">new</field>
762- </record>
763-
764- <record id="ir_action_hr_timesheet_holidays_import_wizard" model="ir.values">
765- <field name="key2">client_action_multi</field>
766- <field name="model">hr_timesheet_sheet.sheet</field>
767- <field name="name">Import Holidays</field>
768- <field eval="'ir.actions.act_window,%d'%action_hr_timesheet_holidays_import" name="value"/>
769- <field eval="True" name="object"/>
770- </record>
771-
772-</data>
773+ <data>
774+
775+ <record id="view_hr_timesheet_holidays_import" model="ir.ui.view">
776+ <field name="name">hr.timesheet.holidays.import</field>
777+ <field name="model">hr.timesheet.holidays.import</field>
778+ <field name="arch" type="xml">
779+ <form string="Select holidays to import">
780+ <field name="holidays_ids" nolabel="1" />
781+ <group colspan="4" col="6">
782+ <button icon="gtk-cancel" special="cancel" string="Cancel"/>
783+ <button icon="gtk-ok" string="Import" name="import_holidays" type="object"/>
784+ </group>
785+ </form>
786+ </field>
787+ </record>
788+
789+ <record id="action_hr_timesheet_holidays_import" model="ir.actions.act_window">
790+ <field name="name">Import Holidays in Timesheet</field>
791+ <field name="res_model">hr.timesheet.holidays.import</field>
792+ <field name="view_type">form</field>
793+ <field name="view_mode">form</field>
794+ <field name="view_id" ref="view_hr_timesheet_holidays_import"/>
795+ <field name="target">new</field>
796+ </record>
797+
798+ <record id="ir_action_hr_timesheet_holidays_import_wizard" model="ir.values">
799+ <field name="key2">client_action_multi</field>
800+ <field name="model">hr_timesheet_sheet.sheet</field>
801+ <field name="name">Import Holidays</field>
802+ <field eval="'ir.actions.act_window,%d'%action_hr_timesheet_holidays_import" name="value"/>
803+ <field eval="True" name="object"/>
804+ </record>
805+
806+ </data>
807 </openerp>

Subscribers

People subscribed via source and target branches