openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #01524
lp:~camptocamp/hr-timesheet/7.0-timesheet-add-department-by-default into lp:hr-timesheet/7.0
Matthieu Dietrich @ camptocamp has proposed merging lp:~camptocamp/hr-timesheet/7.0-timesheet-add-department-by-default into lp:hr-timesheet/7.0.
Requested reviews:
HR Core Editors (hr-core-editors)
For more details, see:
https://code.launchpad.net/~camptocamp/hr-timesheet/7.0-timesheet-add-department-by-default/+merge/195965
Adding "department_id" by default (based on the uid).
--
https://code.launchpad.net/~camptocamp/hr-timesheet/7.0-timesheet-add-department-by-default/+merge/195965
Your team OpenERP Community Reviewer/Maintainer is subscribed to branch lp:hr-timesheet/7.0.
=== modified file 'hr_timesheet_improvement/hr_attendance.py'
--- hr_timesheet_improvement/hr_attendance.py 2013-09-20 15:26:45 +0000
+++ hr_timesheet_improvement/hr_attendance.py 2013-11-20 14:11:28 +0000
@@ -21,8 +21,10 @@
##############################################################################
import time
-from openerp.osv import orm
+from openerp.osv import orm, osv
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
+from openerp.tools.translate import _
+
class HrAttendance(orm.Model):
@@ -54,6 +56,15 @@
Previous (if exists) must be of opposite action.
Next (if exists) must be of opposite action.
"""
+ return True
+
+ _constraints = [(_altern_si_so, 'Error ! Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])]
+
+ _defaults = {
+ 'name': _default_date,
+ }
+
+ def check_alter_si_so(self, cr, uid, ids, context=None):
sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
for att in self.browse(cr, uid, ids, context=context):
sheet_id = sheet_obj.search(
@@ -65,8 +76,7 @@
limit=1,
context=context)
sheet_id = sheet_id and sheet_id[0] or False
-
- # search and browse for first previous and first next records
+ # search and browse for first previous and first next records
prev_att_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id),
('sheet_id', '=', sheet_id),
('name', '<', att.name),
@@ -79,20 +89,15 @@
('action', 'in', ('sign_in', 'sign_out'))],
limit=1, order='name ASC',
context=context)
+
+
prev_atts = self.browse(cr, uid, prev_att_ids, context=context)
next_atts = self.browse(cr, uid, next_add_ids, context=context)
- # check for alternance, return False if at least one condition is not satisfied
+ # check for alternance, return False if at least one condition is not satisfied
if prev_atts and prev_atts[0].action == att.action: # previous exists and is same action
- return False
+ raise osv.except_osv(_('UserError'),_('%s and %s are both a %s')%(prev_atts[0].name,att.name,att.action))
if next_atts and next_atts[0].action == att.action: # next exists and is same action
- return False
- if (not prev_atts) and (not next_atts) and att.action != 'sign_in': # first attendance must be sign_in
- return False
+ raise osv.except_osv(_('UserError'),_('%s and %s are both a %s')%(next_atts[0].name,att.name,att.action))
+ if (not prev_atts) and att.action != 'sign_in': # first attendance must be sign_in
+ raise osv.except_osv(_('UserError'),_('%s does not have a previous Sign in, please Sign in before Sign out')%(att.name))
return True
-
- _constraints = [(_altern_si_so, 'Error ! Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])]
-
- _defaults = {
- 'name': _default_date,
- }
-
=== modified file 'hr_timesheet_improvement/hr_timesheet.py'
--- hr_timesheet_improvement/hr_timesheet.py 2013-09-20 15:26:45 +0000
+++ hr_timesheet_improvement/hr_timesheet.py 2013-11-20 14:11:28 +0000
@@ -49,3 +49,40 @@
}
),
}
+
+ def _check_sheet_state(self, cr, uid, ids, context=None):
+ ## Deactivate contraint to allow modification of timesheet by project manager
+ return True
+
+ _constraints = [
+ (_check_sheet_state, 'You cannot modify an entry in a Confirmed/Done timesheet !', ['state']),
+ ]
+
+ def _get_department(self, cr, uid, ids, context=None):
+ employee_obj = self.pool.get('hr.employee')
+ department_id = False
+ employee_ids = employee_obj.search(cr, uid, [('user_id','=', uid)])
+ if employee_ids:
+ department_id = employee_obj.browse(cr, uid, employee_ids[0], context=context).department_id.id
+ return department_id
+
+ _defaults = {
+ 'department_id': _get_department,
+ }
+
+
+class HrTimesheetsheet(orm.Model):
+ """
+ Set order by line date and analytic account name instead of id
+ We create related stored values as _order cannot be used on inherited columns
+ """
+ _inherit = "hr_timesheet_sheet.sheet"
+
+ def button_confirm(self, cr, uid, ids, context=None):
+ attendances_obj = self.pool.get('hr.attendance')
+ for sheet in self.browse(cr, uid, ids, context=context):
+ ids_attendances = attendances_obj.search(cr,uid,[('sheet_id', '=', sheet.id)])
+ attendances_obj.check_alter_si_so(cr,uid,ids_attendances,context=context)
+ return super(HrTimesheetsheet,self).button_confirm(cr, uid, ids, context=context)
+
+
Follow ups