From e328055359259bb9ea676dec3d7e0c2155ebe061 Mon Sep 17 00:00:00 2001
From: "qdp-launchpad@tinyerp.com" <>
Date: Wed, 17 Mar 2010 18:09:26 +0100
Subject: [PATCH] [IMP] hr_holidays: improvements
bzr revid: qdp-launchpad@tinyerp.com-20100317170926-zyw5frdscx3kpi1p
---
addons/hr_holidays/__terp__.py | 3 +-
addons/hr_holidays/hr.py | 131 ++++++------------
addons/hr_holidays/hr_holidays_report.xml | 71 ++++++++++
addons/hr_holidays/hr_holidays_wizard.xml | 7 +-
addons/hr_holidays/hr_view.xml | 99 +++++--------
addons/hr_holidays/report/__init__.py | 6 +-
.../hr_holidays/report/available_holidays.py | 33 +++++
.../report/holidays_summary_report.py | 1 -
.../hr_holidays/security/ir.model.access.csv | 8 +-
9 files changed, 187 insertions(+), 172 deletions(-)
create mode 100644 addons/hr_holidays/report/available_holidays.py
diff --git a/addons/hr_holidays/__terp__.py b/addons/hr_holidays/__terp__.py
index f44fe590015..26dc78675cc 100644
--- a/addons/hr_holidays/__terp__.py
+++ b/addons/hr_holidays/__terp__.py
@@ -53,9 +53,8 @@
'security/ir.model.access.csv',
'hr_workflow.xml',
'hr_view.xml',
- 'hr_holidays_report.xml',
'hr_holidays_wizard.xml',
- 'report/hr_holidays_report_view.xml',
+ 'hr_holidays_report.xml',
#'process/hr_holidays_process.xml'
],
'demo_xml': [],
diff --git a/addons/hr_holidays/hr.py b/addons/hr_holidays/hr.py
index b6c0313e13f..12cb02f659f 100755
--- a/addons/hr_holidays/hr.py
+++ b/addons/hr_holidays/hr.py
@@ -37,17 +37,13 @@ class hr_holidays_status(osv.osv):
for record in self.browse(cr, uid, ids, context):
res[record.id] = {}
max_leaves = leaves_taken = 0
- obj_ids = self.pool.get('hr.holidays.per.user').search(cr, uid, [('user_id','=',uid),('employee_id','=',employee_id),('holiday_status','=',record.id)])
- if obj_ids:
- br_ob=self.pool.get('hr.holidays.per.user').browse(cr, uid, obj_ids)[0]
- max_leaves=br_ob.max_leaves
if not return_false:
cr.execute("""SELECT type, sum(number_of_days) FROM hr_holidays WHERE employee_id = %s AND state='validate' AND holiday_status_id = %s GROUP BY type""", (str(employee_id), str(record.id)))
for line in cr.fetchall():
if line[0] =='remove':
- leaves_taken = -line[1]
+ leaves_taken = -line[1]
if line[0] =='add':
- max_leaves = line[1]
+ max_leaves = line[1]
res[record.id]['max_leaves'] = max_leaves
res[record.id]['leaves_taken'] = leaves_taken
res[record.id]['remaining_leaves'] = max_leaves - leaves_taken
@@ -66,18 +62,19 @@ class hr_holidays_status(osv.osv):
employee_id = employee_ids[0]
else:
return_false = True
- res = self.get_days(cr, uid, ids, employee_id, return_false, context=context)
+ if employee_id:
+ res = self.get_days(cr, uid, ids, employee_id, return_false, context=context)
return res
_columns = {
'name' : fields.char('Name', size=64, required=True, translate=True),
- 'section_id': fields.many2one('crm.case.section', 'CRM Section', help='If you link this type of leave with a section in the CRM, it will synchronize each leave asked with a case in this section, to display it in the company shared calendar for example.'),
+ 'categ_id': fields.many2one('crm.case.categ', 'Meeting Category', domain="[('object_id.model', '=', 'crm.meeting')]", help='If you link this type of leave with a category in the CRM, it will synchronize each leave asked with a case in this category, to display it in the company shared calendar for example.'),
'color_name' : fields.selection([('red', 'Red'), ('lightgreen', 'Light Green'), ('lightblue','Light Blue'), ('lightyellow', 'Light Yellow'), ('magenta', 'Magenta'),('lightcyan', 'Light Cyan'),('black', 'Black'),('lightpink', 'Light Pink'),('brown', 'Brown'),('violet', 'Violet'),('lightcoral', 'Light Coral'),('lightsalmon', 'Light Salmon'),('lavender', 'Lavender'),('wheat', 'Wheat'),('ivory', 'Ivory')],'Color of the status', required=True, help='This color will be used in the leaves summary located in Reporting\Print Summary of Leaves'),
'limit' : fields.boolean('Allow to override Limit', help='If you thick this checkbox, the system will allow, for this section, the employees to take more leaves than the available ones.'),
- 'active' : fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the leave type without removing it."),
+ 'active' : fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the leave type without removing it."),
'max_leaves' : fields.function(_user_left_days, method=True, string='Maximum Leaves Allowed', help='This value is given by the sum of all holidays requests with a positive value.', multi='user_left_days'),
'leaves_taken' : fields.function(_user_left_days, method=True, string='Leaves Already Taken', help='This value is given by the sum of all holidays requests with a negative value.', multi='user_left_days'),
- 'remaining_leaves' : fields.function(_user_left_days, method=True, string='Remaining Leaves', multi='user_left_days'),
+ 'remaining_leaves' : fields.function(_user_left_days, method=True, string='Remaining Leaves', help='Maximum Leaves Allowed - Leaves Already Taken', multi='user_left_days'),
}
_defaults = {
@@ -86,48 +83,6 @@ class hr_holidays_status(osv.osv):
}
hr_holidays_status()
-class hr_holidays_per_user(osv.osv):
- _name = "hr.holidays.per.user"
- _description = "Holidays Per User"
- _rec_name = "user_id"
-
- def _get_remaining_leaves(self, cr, uid, ids, field_name, arg=None, context={}):
- obj_holiday = self.pool.get('hr.holidays')
- result = {}
- for holiday_user in self.browse(cr, uid, ids):
- days = 0.0
- ids_request = obj_holiday.search(cr, uid, [('employee_id', '=', holiday_user.employee_id.id),('state', '=', 'validate'),('holiday_status_id', '=', holiday_user.holiday_status.id)])
- if ids_request:
- holidays = obj_holiday.browse(cr, uid, ids_request)
- for holiday in holidays:
- days -= holiday.number_of_days
- days = holiday_user.max_leaves - days
- result[holiday_user.id] = days
- return result
-
- _columns = {
- 'employee_id': fields.many2one('hr.employee', "Employee's Name",required=True),
- 'user_id' : fields.many2one('res.users','User'),
- 'holiday_status' : fields.many2one("hr.holidays.status", "Holiday's Status", required=True),
- 'max_leaves' : fields.float('Maximum Leaves Allowed',required=True),
- 'leaves_taken' : fields.float('Leaves Already Taken',readonly=True),
- 'active' : fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the holidays per user without removing it."),
- 'notes' : fields.text('Notes'),
- 'remaining_leaves': fields.function(_get_remaining_leaves, method=True, string='Remaining Leaves', type='float'),
- 'holiday_ids': fields.one2many('hr.holidays', 'holiday_user_id', 'Holidays')
- }
- _defaults = {
- 'active' : lambda *a: True,
- }
-
- def create(self, cr, uid, vals, *args, **kwargs):
- if vals['employee_id']:
- obj_emp=self.pool.get('hr.employee').browse(cr,uid,vals['employee_id'])
- vals.update({'user_id': obj_emp.user_id.id})
- return super(osv.osv,self).create(cr, uid, vals, *args, **kwargs)
-
-hr_holidays_per_user()
-
class hr_holidays(osv.osv):
_name = "hr.holidays"
_description = "Holidays"
@@ -152,13 +107,12 @@ class hr_holidays(osv.osv):
'notes' : fields.text('Notes',readonly=True, states={'draft':[('readonly',False)]}),
'number_of_days': fields.float('Number of Days', readonly=True, states={'draft':[('readonly',False)]}),
'number_of_days_temp': fields.float('Number of Days', readonly=True, states={'draft':[('readonly',False)]}),
- 'case_id': fields.many2one('crm.case', 'Case'),
+ 'case_id': fields.many2one('crm.meeting', 'Case'),
'type': fields.selection([('remove','Leave Request'),('add','Allocation Request')], 'Request Type', required=True, readonly=True, states={'draft':[('readonly',False)]}, help="Choose 'Leave Request' if someone wants to take an off-day. \nChoose 'Allocation Request' if you want to increase the number of leaves available for someone"),
'allocation_type': fields.selection([('employee','Employee Request'),('company','Company Allocation')], 'Allocation Type', required=True, readonly=True, states={'draft':[('readonly',False)]}, help='This field is only for informative purposes, to depict if the leave request/allocation comes from an employee or from the company'),
'parent_id': fields.many2one('hr.holidays', 'Parent'),
'linked_request_ids': fields.one2many('hr.holidays', 'parent_id', 'Linked Requests',),
- 'holiday_user_id' : fields.many2one('hr.holidays.per.user', 'User'),
- 'department_id':fields.many2one('hr.department','Department'),
+ 'department_id':fields.many2one('hr.department','Department', readonly=True, states={'draft':[('readonly',False)]} ),
}
_defaults = {
@@ -170,6 +124,14 @@ class hr_holidays(osv.osv):
}
_order = 'date_from desc'
+ def create(self, cr, uid, vals, context={}):
+ if context:
+ if context.has_key('type'):
+ vals['type'] = context['type']
+ if context.has_key('allocation_type'):
+ vals['allocation_type'] = context['allocation_type']
+ return super(osv.osv,self).create(cr, uid, vals, context)
+
def onchange_date_from(self, cr, uid, ids, date_to, date_from):
result = {}
if date_to and date_from:
@@ -188,16 +150,14 @@ class hr_holidays(osv.osv):
def _update_user_holidays(self, cr, uid, ids):
for record in self.browse(cr, uid, ids):
if record.state=='validate':
- holiday_id=self.pool.get('hr.holidays.per.user').search(cr, uid, [('employee_id','=', record.employee_id.id),('holiday_status','=',record.holiday_status_id.id)])
- if holiday_id:
- obj_holidays_per_user=self.pool.get('hr.holidays.per.user').browse(cr, uid,holiday_id[0])
- self.pool.get('hr.holidays.per.user').write(cr,uid,obj_holidays_per_user.id,{'leaves_taken':obj_holidays_per_user.leaves_taken - record.number_of_days})
if record.case_id:
- if record.case_id.state <> 'draft':
- raise osv.except_osv(_('Warning !'),
- _('You can not cancel this holiday request. first You have to make its case in draft state.'))
- else:
- self.pool.get('crm.case').unlink(cr,uid,[record.case_id.id])
+ self.pool.get('crm.meeting').unlink(cr,uid,[record.case_id.id])
+ if record.linked_request_ids:
+ list_ids = []
+ for id in record.linked_request_ids:
+ list_ids.append(id.id)
+ self.holidays_cancel(cr,uid,list_ids)
+ self.unlink(cr,uid,list_ids)
def _check_date(self, cr, uid, ids):
if ids:
@@ -209,26 +169,11 @@ class hr_holidays(osv.osv):
_constraints = [(_check_date, 'Start date should not be larger than end date! ', ['number_of_days'])]
- def create(self, cr, uid, vals, *args, **kwargs):
- id_holiday = super(hr_holidays, self).create(cr, uid, vals, *args, **kwargs)
- self._create_holiday(cr, uid, [id_holiday])
- return id_holiday
def unlink(self, cr, uid, ids, context={}):
self._update_user_holidays(cr, uid, ids)
return super(hr_holidays, self).unlink(cr, uid, ids, context)
- def _create_holiday(self, cr, uid, ids):
- holidays_user_obj = self.pool.get('hr.holidays.per.user')
- holidays_data = self.browse(cr, uid, ids[0])
- list_holiday = []
- ids_user_hdays = holidays_user_obj.search(cr, uid, [('employee_id', '=', holidays_data.employee_id.id),('holiday_status', '=', holidays_data.holiday_status_id.id)])
- for hdays in holidays_user_obj.browse(cr, uid, ids_user_hdays):
- for req in hdays.holiday_ids:
- list_holiday.append(req.id)
- list_holiday.append(ids[0])
- holidays_user_obj.write(cr, uid, ids_user_hdays, {'holiday_ids': [(6, 0, list_holiday)]})
- return True
def onchange_date_to(self, cr, uid, ids, date_from, date_to):
result = {}
@@ -249,7 +194,7 @@ class hr_holidays(osv.osv):
warning = {}
if status:
brows_obj = self.pool.get('hr.holidays.status').browse(cr, uid, [status])[0]
- if brows_obj.section_id and not brows_obj.section_id.allow_unlink:
+ if brows_obj.categ_id and brows_obj.categ_id.section_id and not brows_obj.categ_id.section_id.allow_unlink:
warning = {
'title': "Warning for ",
'message': "You won\'t be able to cancel this leave request because the CRM Section of the leave type disallows."
@@ -283,6 +228,7 @@ class hr_holidays(osv.osv):
def holidays_confirm(self, cr, uid, ids, *args):
for record in self.browse(cr, uid, ids):
+ user_id = False
leave_asked = record.number_of_days_temp
if record.type == 'remove':
if record.employee_id and not record.holiday_status_id.limit:
@@ -300,14 +246,14 @@ class hr_holidays(osv.osv):
'number_of_days': nb,
'user_id': user_id
})
- vals= {
- 'name':record.name,
- 'date_from':record.date_from,
- 'date_to':record.date_to,
- 'calendar_id':record.employee_id.calendar_id.id,
- 'company_id':record.employee_id.company_id.id,
- 'resource_id':record.employee_id.resource_id.id
- }
+ #vals= {
+ # 'name':record.name,
+ # 'date_from':record.date_from,
+ # 'date_to':record.date_to,
+ # 'calendar_id':record.employee_id.calendar_id.id,
+ # 'company_id':record.employee_id.company_id.id,
+ # 'resource_id':record.employee_id.resource_id.id
+ # }
#self.pool.get('resource.calendar.leaves').create(cr,uid,vals)
return True
@@ -365,14 +311,17 @@ class hr_holidays(osv.osv):
employee_ids = self.pool.get('hr.employee').search(cr, uid, [])
for employee in employee_ids:
vals['employee_id'] = employee
+ user_id = self.pool.get('hr.employee').search(cr, uid, [('user_id','=',uid)])
+ if user_id:
+ vals['user_id'] = user_id[0]
holiday_ids.append(self.create(cr, uid, vals, context={}))
self.holidays_confirm(cr, uid, holiday_ids)
self.holidays_validate(cr, uid, holiday_ids)
- if record.holiday_status_id.section_id and record.date_from and record.date_to and record.employee_id:
+ if record.holiday_status_id.categ_id and record.date_from and record.date_to and record.employee_id:
vals={}
vals['name']=record.name
- vals['section_id']=record.holiday_status_id.section_id.id
+ vals['categ_id']=record.holiday_status_id.categ_id.id
epoch_c = time.mktime(time.strptime(record.date_to,'%Y-%m-%d %H:%M:%S'))
epoch_d = time.mktime(time.strptime(record.date_from,'%Y-%m-%d %H:%M:%S'))
diff_day = (epoch_c - epoch_d)/(3600*24)
@@ -380,7 +329,7 @@ class hr_holidays(osv.osv):
vals['note'] = record.notes
vals['user_id'] = record.user_id.id
vals['date'] = record.date_from
- case_id = self.pool.get('crm.case').create(cr,uid,vals)
+ case_id = self.pool.get('crm.meeting').create(cr,uid,vals)
self.write(cr, uid, ids, {'case_id':case_id})
return True
hr_holidays()
diff --git a/addons/hr_holidays/hr_holidays_report.xml b/addons/hr_holidays/hr_holidays_report.xml
index 23d1e1a75bf..66669bd2f51 100644
--- a/addons/hr_holidays/hr_holidays_report.xml
+++ b/addons/hr_holidays/hr_holidays_report.xml
@@ -9,6 +9,77 @@
auto="False"
menu="False"/>
+
+
+
+
+
+
+ hr.holidays.report.tree
+ hr.holidays.report
+ tree
+
+
+
+
+
+
+
+
+
+
+ hr.holidays.report.form
+ hr.holidays.report
+ form
+
+
+
+
+
+
+
+
+
+ hr.holiday.report.graph
+ hr.holidays.report
+ graph
+
+
+
+
+
+
+
+
+
+
+ Available Holidays
+ hr.holidays.report
+ form
+ tree,graph
+
+
+
+
+
+
+ tree
+
+
+
+
+
+
+
+ graph
+
+
+
+
+
+
+
+
diff --git a/addons/hr_holidays/hr_holidays_wizard.xml b/addons/hr_holidays/hr_holidays_wizard.xml
index fb505d65497..fc433a181e7 100644
--- a/addons/hr_holidays/hr_holidays_wizard.xml
+++ b/addons/hr_holidays/hr_holidays_wizard.xml
@@ -11,10 +11,11 @@
name="Holidays"
parent="hr.menu_hr_reporting"
sequence="3" />
-
-
@@ -24,7 +25,7 @@
-
diff --git a/addons/hr_holidays/hr_view.xml b/addons/hr_holidays/hr_view.xml
index 146e06d25a3..d46898bd6bb 100644
--- a/addons/hr_holidays/hr_view.xml
+++ b/addons/hr_holidays/hr_view.xml
@@ -1,13 +1,6 @@
-
-
-
hr.holidays.filter
hr.holidays
@@ -38,7 +31,6 @@
-
Leave Request
hr.holidays
@@ -73,7 +65,6 @@
-
Allocation Request
hr.holidays
@@ -104,18 +95,17 @@
-
-
+
- Company Allocation
+ Leaves Management
hr.holidays
form
-
-
+
-
diff --git a/addons/hr_holidays/report/__init__.py b/addons/hr_holidays/report/__init__.py
index bb1f6229bc0..00783721fe3 100644
--- a/addons/hr_holidays/report/__init__.py
+++ b/addons/hr_holidays/report/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
-#
+#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL ().
#
@@ -15,11 +15,11 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
+# along with this program. If not, see .
#
##############################################################################
import holidays_summary_report
-import hr_holidays_report
+import available_holidays
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/hr_holidays/report/available_holidays.py b/addons/hr_holidays/report/available_holidays.py
new file mode 100644
index 00000000000..259aea0dec9
--- /dev/null
+++ b/addons/hr_holidays/report/available_holidays.py
@@ -0,0 +1,33 @@
+from osv import fields,osv
+import tools
+
+class hr_holidays_report(osv.osv):
+ _name = "hr.holidays.report"
+ _auto = False
+ _columns = {
+ 'employee_id': fields.many2one ('hr.employee', 'Employee', readonly=True),
+ 'holiday_status_id': fields.many2one('hr.holidays.status', 'Leave Type', readonly=True),
+ # 'max_leave': fields.float('Allocated Leaves', readonly=True),
+# 'taken_leaves': fields.float('Taken Leaves', readonly=True),
+ 'remaining_leave': fields.float('Remaining Leaves',readonly=True),
+ }
+ def init(self, cr):
+ tools.drop_view_if_exists(cr, 'hr_holidays_report')
+ cr.execute("""
+ create or replace view hr_holidays_report as (
+ select
+ min(h.id) as id,
+ h.employee_id as employee_id,
+ h.holiday_status_id as holiday_status_id,
+ sum(number_of_days) as remaining_leave
+ from
+ hr_holidays h
+ left join hr_holidays_status s on (s.id = h.holiday_status_id)
+ where h.state = 'validate'
+ and h.employee_id is not null
+ and s.active <> 'f'
+ group by h.holiday_status_id, h.employee_id
+ )""")
+hr_holidays_report()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/hr_holidays/report/holidays_summary_report.py b/addons/hr_holidays/report/holidays_summary_report.py
index e0cb697b3b9..c61e8f733b4 100644
--- a/addons/hr_holidays/report/holidays_summary_report.py
+++ b/addons/hr_holidays/report/holidays_summary_report.py
@@ -44,7 +44,6 @@ def strToDate(dt):
def emp_create_xml(self,cr,uid,dept,holiday_type,row_id,empid,name,som,eom):
display={}
-
if dept==0:
count=0
p_id=pooler.get_pool(cr.dbname).get('hr.holidays').search(cr,uid,[('employee_id','in',[empid,False]), ('type', '=', 'remove')])
diff --git a/addons/hr_holidays/security/ir.model.access.csv b/addons/hr_holidays/security/ir.model.access.csv
index 236b6a8fb89..a7426724594 100644
--- a/addons/hr_holidays/security/ir.model.access.csv
+++ b/addons/hr_holidays/security/ir.model.access.csv
@@ -1,5 +1,5 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
-"access_hr_holydays_status_user","hr.holidays.status user","model_hr_holidays_status","hr.group_hr_user",1,1,1,1
-"access_hr_holidays_user","hr holidays user","model_hr_holidays","hr.group_hr_user",1,1,1,1
-"access_hr_holidays_per_user","hr.holidays.per.user","model_hr_holidays_per_user","hr.group_hr_user",1,1,1,1
-"access_hr_holidays_report","hr.holidays.report","model_hr_holidays_report","hr.group_hr_user",1,1,1,1
+"access_hr_holydays_status_user","hr.holidays.status user","model_hr_holidays_status","hr.group_hr_user",1,0,0,0
+"access_hr_holidays_user","hr holidays user","model_hr_holidays","hr.group_hr_user",1,1,1,0
+"access_hr_holydays_status_manager","hr.holidays.status manager","model_hr_holidays_status","hr.group_hr_manager",1,1,1,1
+"access_hr_holidays_manager","hr holidays manager","model_hr_holidays","hr.group_hr_manager",1,1,1,1