Merge lp:~openerp-dev/openobject-addons/saas-3-hr-leave-count-correct-mba into lp:~openerp/openobject-addons/saas-3

Proposed by Mahendra Barad(OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/saas-3-hr-leave-count-correct-mba
Merge into: lp:~openerp/openobject-addons/saas-3
Diff against target: 146 lines (+64/-36)
1 file modified
hr_holidays/hr_holidays.py (+64/-36)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/saas-3-hr-leave-count-correct-mba
Reviewer Review Type Date Requested Status
Thibault Delavallée (OpenERP) Pending
Review via email: mp+210543@code.launchpad.net

Description of the change

Hello,

   I have fix the problem of leaves counts not correct in hr_holidays.
   for more details you can see : https://pad.openerp.com/p/openerp-project.task-0687EIYQ81

 Thanks,
Mahendra

To post a comment you must log in.
9297. By Mahendra Barad(OpenERP)

[Merge]with saas-3

9298. By Darshan Kalola(OpenERP)

[MERGE]sync with lp:~openerp/openobject-addons/saas-3.

Unmerged revisions

9298. By Darshan Kalola(OpenERP)

[MERGE]sync with lp:~openerp/openobject-addons/saas-3.

9297. By Mahendra Barad(OpenERP)

[Merge]with saas-3

9296. By Mahendra Barad(OpenERP)

[FIX]legal leave count for different employee

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hr_holidays/hr_holidays.py'
2--- hr_holidays/hr_holidays.py 2014-02-25 21:31:21 +0000
3+++ hr_holidays/hr_holidays.py 2014-05-08 05:37:33 +0000
4@@ -36,40 +36,8 @@
5 _name = "hr.holidays.status"
6 _description = "Leave Type"
7
8- def get_days(self, cr, uid, ids, employee_id, context=None):
9- result = dict((id, dict(max_leaves=0, leaves_taken=0, remaining_leaves=0,
10- virtual_remaining_leaves=0)) for id in ids)
11- holiday_ids = self.pool['hr.holidays'].search(cr, uid, [('employee_id', '=', employee_id),
12- ('state', 'in', ['confirm', 'validate1', 'validate']),
13- ('holiday_status_id', 'in', ids)
14- ], context=context)
15- for holiday in self.pool['hr.holidays'].browse(cr, uid, holiday_ids, context=context):
16- status_dict = result[holiday.holiday_status_id.id]
17- if holiday.type == 'add':
18- status_dict['virtual_remaining_leaves'] += holiday.number_of_days
19- if holiday.state == 'validate':
20- status_dict['max_leaves'] += holiday.number_of_days
21- status_dict['remaining_leaves'] += holiday.number_of_days
22- elif holiday.type == 'remove': # number of days is negative
23- status_dict['virtual_remaining_leaves'] += holiday.number_of_days
24- if holiday.state == 'validate':
25- status_dict['leaves_taken'] -= holiday.number_of_days
26- status_dict['remaining_leaves'] += holiday.number_of_days
27- return result
28-
29 def _user_left_days(self, cr, uid, ids, name, args, context=None):
30- employee_id = False
31- if context and 'employee_id' in context:
32- employee_id = context['employee_id']
33- else:
34- employee_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context)
35- if employee_ids:
36- employee_id = employee_ids[0]
37- if employee_id:
38- res = self.get_days(cr, uid, ids, employee_id, context=context)
39- else:
40- res = dict.fromkeys(ids, {'leaves_taken': 0, 'remaining_leaves': 0, 'max_leaves': 0})
41- return res
42+ return self.pool.get('hr.holidays').get_stats(cr, uid, ids, context=context)
43
44 _columns = {
45 'name': fields.char('Leave Type', size=64, required=True, translate=True),
46@@ -82,6 +50,7 @@
47 'leaves_taken': fields.function(_user_left_days, string='Leaves Already Taken', help='This value is given by the sum of all holidays requests with a negative value.', multi='user_left_days'),
48 'remaining_leaves': fields.function(_user_left_days, string='Remaining Leaves', help='Maximum Leaves Allowed - Leaves Already Taken', multi='user_left_days'),
49 'virtual_remaining_leaves': fields.function(_user_left_days, string='Virtual Remaining Leaves', help='Maximum Leaves Allowed - Leaves Already Taken - Leaves Waiting Approval', multi='user_left_days'),
50+ 'leaves_tag': fields.function(_user_left_days, string='Leaves Tag', multi='user_left_days'),
51 'double_validation': fields.boolean('Apply Double Validation', help="When selected, the Allocation/Leave Requests for this type require a second validation to be approved."),
52 }
53 _defaults = {
54@@ -94,7 +63,7 @@
55 for record in self.browse(cr, uid, ids, context=context):
56 name = record.name
57 if not record.limit:
58- name = name + (' (%d/%d)' % (record.leaves_taken or 0.0, record.max_leaves or 0.0))
59+ name = record.leaves_tag
60 res.append((record.id, name))
61 return res
62
63@@ -112,6 +81,39 @@
64 },
65 }
66
67+ def get_stats(self, cr, uid, type_ids, employee_id=None, context=None):
68+ if context is None:
69+ context = {}
70+ status_type_pool = self.pool.get('hr.holidays.status')
71+ if employee_id is None:
72+ employee_id = context.get('employee_id')
73+ if not employee_id:
74+ employee_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context)
75+ if employee_ids:
76+ employee_id = employee_ids[0]
77+
78+ domain = [('holiday_status_id', 'in', type_ids), ('state', 'in', ['confirm', 'validate1', 'validate'])]
79+ if employee_id:
80+ domain += [('employee_id', '=', employee_id)]
81+ status_types = status_type_pool.browse(cr, uid, type_ids, context=context)
82+ result = dict((type.id, dict(max_leaves=0, leaves_taken=0, remaining_leaves=0,
83+ virtual_remaining_leaves=0, leaves_tag=type.name)) for type in status_types)
84+ holiday_ids = self.search(cr, uid, domain, context=context)
85+ for holiday in self.browse(cr, uid, holiday_ids, context=context):
86+ status_dict = result[holiday.holiday_status_id.id]
87+ if holiday.type == 'add':
88+ status_dict['virtual_remaining_leaves'] += holiday.number_of_days
89+ if holiday.state == 'validate':
90+ status_dict['max_leaves'] += holiday.number_of_days
91+ status_dict['remaining_leaves'] += holiday.number_of_days
92+ elif holiday.type == 'remove': # number of days is negative
93+ status_dict['virtual_remaining_leaves'] += holiday.number_of_days
94+ if holiday.state == 'validate':
95+ status_dict['leaves_taken'] -= holiday.number_of_days
96+ status_dict['remaining_leaves'] += holiday.number_of_days
97+ status_dict['leaves_tag'] = '%s (%d/%d)' % (holiday.holiday_status_id.name, status_dict.get('leaves_taken'), status_dict.get('max_leaves',0.0))
98+ return result
99+
100 def _employee_get(self, cr, uid, context=None):
101 emp_id = context.get('default_employee_id', False)
102 if emp_id:
103@@ -202,7 +204,33 @@
104 ('date_check2', "CHECK ( (type='add') OR (date_from <= date_to))", "The start date must be anterior to the end date."),
105 ('date_check', "CHECK ( number_of_days_temp >= 0 )", "The number of days must be greater than 0."),
106 ]
107-
108+
109+ def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
110+ if context is None:
111+ context = {}
112+ employee_flag = False
113+ if fields and 'employee_id' not in fields:
114+ fields.append('employee_id')
115+ employee_flag = True
116+ results = super(hr_holidays, self).read(cr, uid, ids, fields=fields, context=context, load=load)
117+
118+ if isinstance(results, (int, str)):
119+ results = results[0]
120+ for holiday in results:
121+ status_id = holiday.get('holiday_status_id')
122+ employee_id = holiday.get('employee_id')
123+ if isinstance(employee_id, (list, tuple)):
124+ employee_id = employee_id[0]
125+ if isinstance(status_id, (list, tuple)):
126+ status_id = holiday.get('holiday_status_id')[0]
127+ status = self.get_stats(cr, uid, [status_id], employee_id=employee_id, context=context)[status_id]
128+ holiday['holiday_status_id'] = (status_id, status['leaves_tag'])
129+ if employee_flag:
130+ del holiday['employee_id']
131+ if isinstance(ids, (int, str)):
132+ results = results[0]
133+ return results
134+
135 def copy(self, cr, uid, id, default=None, context=None):
136 if default is None:
137 default = {}
138@@ -439,7 +467,7 @@
139 for record in self.browse(cr, uid, ids, context=context):
140 if record.holiday_type != 'employee' or record.type != 'remove' or not record.employee_id or record.holiday_status_id.limit:
141 continue
142- leave_days = self.pool.get('hr.holidays.status').get_days(cr, uid, [record.holiday_status_id.id], record.employee_id.id, context=context)[record.holiday_status_id.id]
143+ leave_days = self.get_stats(cr, uid, [record.holiday_status_id.id], record.employee_id.id, context=context)[record.holiday_status_id.id]
144 if leave_days['remaining_leaves'] < 0 or leave_days['virtual_remaining_leaves'] < 0:
145 # Raising a warning gives a more user-friendly feedback than the default constraint error
146 raise Warning(_('The number of remaining leaves is not sufficient for this leave type.\n'

Subscribers

People subscribed via source and target branches