Merge lp:~camptocamp/hr-timesheet/7.0-add-hr_timesheet_improvement into lp:~hr-core-editors/hr-timesheet/7.0

Proposed by Yannick Vaucher @ Camptocamp
Status: Merged
Merged at revision: 43
Proposed branch: lp:~camptocamp/hr-timesheet/7.0-add-hr_timesheet_improvement
Merge into: lp:~hr-core-editors/hr-timesheet/7.0
Diff against target: 263 lines (+238/-0)
5 files modified
hr_timesheet_improvement/__init__.py (+22/-0)
hr_timesheet_improvement/__openerp__.py (+50/-0)
hr_timesheet_improvement/hr_attendance.py (+98/-0)
hr_timesheet_improvement/hr_timesheet.py (+51/-0)
hr_timesheet_improvement/hr_timesheet_view.xml (+17/-0)
To merge this branch: bzr merge lp:~camptocamp/hr-timesheet/7.0-add-hr_timesheet_improvement
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp code, test Approve
Guewen Baconnier @ Camptocamp lgtm Approve
Alexandre Fayolle - camptocamp code review, no test Approve
Review via email: mp+163527@code.launchpad.net

Description of the change

- Add a module to sort timesheet lines by date and account name instead of the dummy id sorting.

- Change default date for manually entering attendances to last date instead of now.

- Redefines constraint on attendances to check only the sheet the attendance belongs to.

To post a comment you must log in.
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

I would like confirmation that:

* in 7.0 the requirement to redeclare the constraint function in the _constraints attributes is lifted
* the code works if several check ins/outs are added simultaneously

review: Needs Information (code review, no test)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

In the related fields, as you did not put invalidations, we would have problems when:

 - the date of an analytic line is changed directly from the analytic line
 - the name of an account is changed directly from the account

As a result, the date_aal and name_account in hr.analytic.timesheet would be desynchronized and the sort would be wrong.

l.118: use the constant openerp.tools.DEFAULT_SERVER_DATETIME_FORMAT

l129-131: a poor docstring, he lost his method. Or was it intended? you are cruel with him

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

Thanks for the changes.
Seems fine now

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

Just did 2 little fixes in the meantime

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

Change description in __openerp__.py (Added redefinition of constraint is missing)

Authors add V. Renaville :)

review: Needs Fixing
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) :
review: Approve (code, test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'hr_timesheet_improvement'
2=== added file 'hr_timesheet_improvement/__init__.py'
3--- hr_timesheet_improvement/__init__.py 1970-01-01 00:00:00 +0000
4+++ hr_timesheet_improvement/__init__.py 2013-06-19 06:20:34 +0000
5@@ -0,0 +1,22 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# Author : Yannick Vaucher (Camptocamp)
10+# Copyright 2013 Camptocamp SA
11+#
12+# This program is free software: you can redistribute it and/or modify
13+# it under the terms of the GNU Affero General Public License as
14+# published by the Free Software Foundation, either version 3 of the
15+# License, or (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU Affero General Public License for more details.
21+#
22+# You should have received a copy of the GNU Affero General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+##############################################################################
26+import hr_timesheet
27+import hr_attendance
28
29=== added file 'hr_timesheet_improvement/__openerp__.py'
30--- hr_timesheet_improvement/__openerp__.py 1970-01-01 00:00:00 +0000
31+++ hr_timesheet_improvement/__openerp__.py 2013-06-19 06:20:34 +0000
32@@ -0,0 +1,50 @@
33+# -*- coding: utf-8 -*-
34+##############################################################################
35+#
36+# Authors: Yannick Vaucher (Camptocamp)
37+# Vincent Renaville (Camptocamp)
38+# Copyright 2013 Camptocamp SA
39+#
40+# This program is free software: you can redistribute it and/or modify
41+# it under the terms of the GNU Affero General Public License as
42+# published by the Free Software Foundation, either version 3 of the
43+# License, or (at your option) any later version.
44+#
45+# This program is distributed in the hope that it will be useful,
46+# but WITHOUT ANY WARRANTY; without even the implied warranty of
47+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48+# GNU Affero General Public License for more details.
49+#
50+# You should have received a copy of the GNU Affero General Public License
51+# along with this program. If not, see <http://www.gnu.org/licenses/>.
52+#
53+##############################################################################
54+{'name' : 'Timesheet improvements',
55+ 'version' : '0.1',
56+ 'author' : 'Camptocamp',
57+ 'maintainer': 'Camptocamp',
58+ 'category': 'Human Resources',
59+ 'depends' : ['hr_timesheet_sheet'],
60+ 'description': """
61+ Modifies timesheet behavior:
62+ - Ensure a DESC order on timesheet lines
63+ - Set default date for manually entering attendance to max attendance date
64+ - Redefine constraint on timesheets to check alternation of 'sign in' and
65+ 'sign out' only on current timesheet instead of doing it on all timesheets
66+ of the employee
67+ """,
68+ 'website': 'http://www.camptocamp.com',
69+ 'data': ['hr_timesheet_view.xml'],
70+ 'js' : [],
71+ 'css': [],
72+ 'qweb': [],
73+ 'demo': [],
74+ 'test': [],
75+ 'installable': True,
76+ 'images' : [],
77+ 'auto_install': False,
78+ 'license': 'AGPL-3',
79+ 'application': True,
80+}
81+
82+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
83
84=== added file 'hr_timesheet_improvement/hr_attendance.py'
85--- hr_timesheet_improvement/hr_attendance.py 1970-01-01 00:00:00 +0000
86+++ hr_timesheet_improvement/hr_attendance.py 2013-06-19 06:20:34 +0000
87@@ -0,0 +1,98 @@
88+# -*- coding: utf-8 -*-
89+##############################################################################
90+#
91+# Authors: Yannick Vaucher (Camptocamp)
92+# Vincent Renaville (Camptocamp)
93+# Copyright 2013 Camptocamp SA
94+#
95+# This program is free software: you can redistribute it and/or modify
96+# it under the terms of the GNU Affero General Public License as
97+# published by the Free Software Foundation, either version 3 of the
98+# License, or (at your option) any later version.
99+#
100+# This program is distributed in the hope that it will be useful,
101+# but WITHOUT ANY WARRANTY; without even the implied warranty of
102+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103+# GNU Affero General Public License for more details.
104+#
105+# You should have received a copy of the GNU Affero General Public License
106+# along with this program. If not, see <http://www.gnu.org/licenses/>.
107+#
108+##############################################################################
109+import time
110+
111+from openerp.osv import orm
112+from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
113+
114+
115+class HrAttendance(orm.Model):
116+ """
117+ Alter the default date for manual setting
118+ """
119+ _inherit = "hr.attendance"
120+
121+ def _default_date(self, cr, uid, context=None):
122+ sheet_id = context.get('sheet_id')
123+ if not sheet_id:
124+ return time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
125+
126+ ts_obj = self.pool.get('hr_timesheet_sheet.sheet')
127+ timesheet = ts_obj.browse(cr, uid, sheet_id, context=context)
128+
129+ dates = [a.name for a in timesheet.attendances_ids]
130+
131+ if not dates:
132+ return timesheet.date_from
133+
134+ return max(dates)
135+ """
136+ Check sign in signout in the same timesheet only
137+ """
138+
139+ def _altern_si_so(self, cr, uid, ids, context=None):
140+ """ Alternance sign_in/sign_out check.
141+ Previous (if exists) must be of opposite action.
142+ Next (if exists) must be of opposite action.
143+ """
144+ sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
145+ for att in self.browse(cr, uid, ids, context=context):
146+ sheet_id = sheet_obj.search(
147+ cr, uid, [
148+ ('employee_id', '=', att.employee_id.id),
149+ ('date_from', '<=', att.name),
150+ ('date_to', '>=', att.name),
151+ ],
152+ limit=1,
153+ context=context)
154+ sheet_id = sheet_id and sheet_id[0] or False
155+
156+ # search and browse for first previous and first next records
157+ prev_att_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id),
158+ ('sheet_id', '=', sheet_id),
159+ ('name', '<', att.name),
160+ ('action', 'in', ('sign_in', 'sign_out'))],
161+ limit=1, order='name DESC',
162+ context=context)
163+ next_add_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id),
164+ ('sheet_id', '=', sheet_id),
165+ ('name', '>', att.name),
166+ ('action', 'in', ('sign_in', 'sign_out'))],
167+ limit=1, order='name ASC',
168+ context=context)
169+ prev_atts = self.browse(cr, uid, prev_att_ids, context=context)
170+ next_atts = self.browse(cr, uid, next_add_ids, context=context)
171+ # check for alternance, return False if at least one condition is not satisfied
172+ if prev_atts and prev_atts[0].action == att.action: # previous exists and is same action
173+ return False
174+ if next_atts and next_atts[0].action == att.action: # next exists and is same action
175+ return False
176+ if (not prev_atts) and (not next_atts) and att.action != 'sign_in': # first attendance must be sign_in
177+ return False
178+ return True
179+
180+ _constraints = [(_altern_si_so, 'Error ! Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])]
181+
182+ _defaults = {
183+ 'name': _default_date,
184+ }
185+
186
187=== added file 'hr_timesheet_improvement/hr_timesheet.py'
188--- hr_timesheet_improvement/hr_timesheet.py 1970-01-01 00:00:00 +0000
189+++ hr_timesheet_improvement/hr_timesheet.py 2013-06-19 06:20:34 +0000
190@@ -0,0 +1,51 @@
191+# -*- coding: utf-8 -*-
192+##############################################################################
193+#
194+# Author : Yannick Vaucher (Camptocamp)
195+# Copyright 2013 Camptocamp SA
196+#
197+# This program is free software: you can redistribute it and/or modify
198+# it under the terms of the GNU Affero General Public License as
199+# published by the Free Software Foundation, either version 3 of the
200+# License, or (at your option) any later version.
201+#
202+# This program is distributed in the hope that it will be useful,
203+# but WITHOUT ANY WARRANTY; without even the implied warranty of
204+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
205+# GNU Affero General Public License for more details.
206+#
207+# You should have received a copy of the GNU Affero General Public License
208+# along with this program. If not, see <http://www.gnu.org/licenses/>.
209+#
210+##############################################################################
211+from openerp.osv import orm, fields
212+
213+class HrAnalyticTimesheet(orm.Model):
214+ """
215+ Set order by line date and analytic account name instead of id
216+ We create related stored values as _order cannot be used on inherited columns
217+ """
218+ _inherit = "hr.analytic.timesheet"
219+ _order = "date_aal DESC, account_name ASC"
220+
221+ def _get_account_analytic_line(self, cr, uid, ids, context=None):
222+ ts_line_ids = self.pool.get('hr.analytic.timesheet').search(cr, uid, [('line_id', 'in', ids)])
223+ return ts_line_ids
224+
225+ def _get_account_analytic_account(self, cr, uid, ids, context=None):
226+ ts_line_ids = self.pool.get('hr.analytic.timesheet').search(cr, uid, [('account_id', 'in', ids)])
227+ return ts_line_ids
228+
229+ _columns = {
230+ 'date_aal': fields.related('line_id', 'date', string="Analytic Line Date", type='date',
231+ store={
232+ 'account.analytic.line': (_get_account_analytic_line, ['date'], 10),
233+ 'hr.analytic.timesheet': (lambda self,cr,uid,ids,context=None: ids, None, 10),
234+ }),
235+ 'account_name': fields.related('account_id', 'name', string="Analytic Account Name", type='char', size=256,
236+ store={
237+ 'account.analytic.account': (_get_account_analytic_account, ['name'], 10),
238+ 'hr.analytic.timesheet': (lambda self,cr,uid,ids,context=None: ids, None, 10),
239+ }
240+ ),
241+ }
242
243=== added file 'hr_timesheet_improvement/hr_timesheet_view.xml'
244--- hr_timesheet_improvement/hr_timesheet_view.xml 1970-01-01 00:00:00 +0000
245+++ hr_timesheet_improvement/hr_timesheet_view.xml 2013-06-19 06:20:34 +0000
246@@ -0,0 +1,17 @@
247+<?xml version="1.0" encoding="utf-8"?>
248+<openerp>
249+ <data>
250+
251+ <record id="hr_timesheet_sheet_form_pass_active_id" model="ir.ui.view">
252+ <field name="name">hr.timesheet.sheet.form</field>
253+ <field name="model">hr_timesheet_sheet.sheet</field>
254+ <field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form" />
255+ <field name="arch" type="xml">
256+ <field name="attendances_ids" position="attributes">
257+ <attribute name="context">{'employee_id': employee_id, 'user_id':user_id, 'sheet_id':active_id}</attribute>
258+ </field>
259+ </field>
260+ </record>
261+
262+ </data>
263+</openerp>

Subscribers

People subscribed via source and target branches