From 3897de56b7ca8248ced9ce0dafa9edf5e076c400 Mon Sep 17 00:00:00 2001 From: "Yogesh Parekh (OpenERP)" Date: Wed, 26 Mar 2014 17:30:56 +0530 Subject: [PATCH] [IMP]: Convert buttons into stat buttons in hr modules bzr revid: ypa@tinyerp.com-20140326120056-qqauj7pmhf0uxhuj --- addons/hr/hr.py | 39 +++++++++++++++++ addons/hr_contract/hr_contract_view.xml | 8 +++- addons/hr_evaluation/hr_evaluation_view.xml | 7 +++- addons/hr_holidays/hr_holidays_view.xml | 8 +++- addons/hr_payroll/hr_payroll.py | 10 +++++ addons/hr_payroll/hr_payroll_view.xml | 15 ++++++- addons/hr_recruitment/hr_recruitment_view.xml | 42 +++++++++++++++---- .../hr_timesheet_sheet/hr_timesheet_sheet.py | 14 +++++++ .../hr_timesheet_sheet_view.xml | 13 +++++- 9 files changed, 140 insertions(+), 16 deletions(-) diff --git a/addons/hr/hr.py b/addons/hr/hr.py index a13a1866493..4efa72e8f5e 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -92,6 +92,17 @@ class hr_job(osv.Model): res.append(employee.job_id.id) return res + def _count_all(self, cr, uid, ids, field_name, arg, context=None): + res = dict(map(lambda x: (x,{'documents_count': 0, 'application_count': 0,}), ids)) + try: + for data in self.browse(cr, uid, ids, context=context): + res[data.id] = {'documents_count': len(data.document_ids), + 'application_count': len(data.applicant_ids), + } + except: + pass + return res + _name = "hr.job" _description = "Job Position" _inherit = ['mail.thread', 'ir.needaction_mixin'] @@ -122,6 +133,10 @@ class hr_job(osv.Model): track_visibility='always', help="By default 'Closed', set it to 'In Recruitment' if recruitment process is going on for this job position."), 'write_date': fields.datetime('Update Date', readonly=True), + 'applicant_ids':fields.one2many('hr.applicant', 'job_id', 'Applications'), + 'application_count': fields.function(_count_all, type='integer', string='Applications', multi=True), + 'document_ids': fields.one2many('ir.attachment', 'company_id', 'Documents'), + 'documents_count': fields.function(_count_all, type='integer', string='Documents', multi=True), } _defaults = { @@ -186,6 +201,20 @@ class hr_employee(osv.osv): def _set_image(self, cr, uid, id, name, value, args, context=None): return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context) + + def _count_all(self, cr, uid, ids, field_name, arg, context=None): + res = dict(map(lambda x: (x,{'appraisal_count': 0, 'leaves_count': 0, 'contracts_count': 0, 'timesheet_count': 0, 'payslip_count': 0,}), ids)) + try: + for datas in self.browse(cr, uid, ids, context=context): + res[datas.id] = {'appraisal_count': len(datas.appraisal_ids), + 'leaves_count': len(datas.leave_ids), + 'contracts_count': len(datas.contract_ids), + 'timesheet_count': len(datas.timsheet_ids), + 'payslip_count': len(datas.payslip_ids) + } + except: + pass + return res _columns = { #we need a related field in order to be able to sort the employee by name @@ -237,6 +266,16 @@ class hr_employee(osv.osv): 'city': fields.related('address_id', 'city', type='char', string='City'), 'login': fields.related('user_id', 'login', type='char', string='Login', readonly=1), 'last_login': fields.related('user_id', 'date', type='datetime', string='Latest Connection', readonly=1), + 'appraisal_ids': fields.one2many('hr.evaluation.interview', 'user_to_review_id', 'Appraisal Interviews'), + 'leave_ids': fields.one2many('hr.holidays', 'employee_id', 'Leaves'), + 'contracts_ids': fields.one2many('hr.contract', 'employee_id', 'Contracts'), + 'timsheet_ids': fields.one2many('hr_timesheet_sheet.sheet', 'employee_id', 'Timesheets'), + 'payslip_ids': fields.one2many('hr.payslip', 'employee_id', 'Payslips'), + 'appraisal_count': fields.function(_count_all, type='integer', string='Appraisal Interviews', multi=True), + 'leaves_count': fields.function(_count_all, type='integer', string='Leaves', multi=True), + 'contracts_count': fields.function(_count_all, type='integer', string='Contracts', multi=True), + 'timesheet_count': fields.function(_count_all, type='integer', string='Timsheets', multi=True), + 'payslip_count': fields.function(_count_all, type='integer', string='Payslips', multi=True), } def _get_default_image(self, cr, uid, context=None): diff --git a/addons/hr_contract/hr_contract_view.xml b/addons/hr_contract/hr_contract_view.xml index c21690401f2..eb1adaad9fc 100644 --- a/addons/hr_contract/hr_contract_view.xml +++ b/addons/hr_contract/hr_contract_view.xml @@ -21,7 +21,13 @@ - diff --git a/addons/hr_evaluation/hr_evaluation_view.xml b/addons/hr_evaluation/hr_evaluation_view.xml index 28bc4a6c96e..42e48771701 100644 --- a/addons/hr_evaluation/hr_evaluation_view.xml +++ b/addons/hr_evaluation/hr_evaluation_view.xml @@ -145,7 +145,12 @@ - diff --git a/addons/hr_holidays/hr_holidays_view.xml b/addons/hr_holidays/hr_holidays_view.xml index d4b84bab012..a15a18d20aa 100644 --- a/addons/hr_holidays/hr_holidays_view.xml +++ b/addons/hr_holidays/hr_holidays_view.xml @@ -483,7 +483,13 @@ - diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 081fe226c3a..b3394c455c8 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -258,6 +258,15 @@ class hr_payslip(osv.osv): for r in res: result[r[0]].append(r[1]) return result + + def _count_detail_payslip(self, cr, uid, ids, field_name, arg, context=None): + res = {} + try: + for details in self.browse(cr, uid, ids, context=context): + res[details.id] = len(details.line_ids) + except: + pass + return res _columns = { 'struct_id': fields.many2one('hr.payroll.structure', 'Structure', readonly=True, states={'draft': [('readonly', False)]}, help='Defines the rules that have to be applied to this payslip, accordingly to the contract chosen. If you let empty the field contract, this field isn\'t mandatory anymore and thus the rules applied will be all the rules set on the structure of all contracts of the employee valid for the chosen period'), @@ -287,6 +296,7 @@ class hr_payslip(osv.osv): 'details_by_salary_rule_category': fields.function(_get_lines_salary_rule_category, method=True, type='one2many', relation='hr.payslip.line', string='Details by Salary Rule Category'), 'credit_note': fields.boolean('Credit Note', help="Indicates this payslip has a refund of another", readonly=True, states={'draft': [('readonly', False)]}), 'payslip_run_id': fields.many2one('hr.payslip.run', 'Payslip Batches', readonly=True, states={'draft': [('readonly', False)]}), + 'payslip_count': fields.function(_count_detail_payslip, type='integer', string="Payslip Computation Details"), } _defaults = { 'date_from': lambda *a: time.strftime('%Y-%m-01'), diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 4410784c63c..6232f593b90 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -222,7 +222,12 @@
-