From 8135812d34ceeaebde9ef33b96502910debf4c43 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Tue, 15 Apr 2014 12:54:19 +0200 Subject: [PATCH] [FIX] moves the field definitions of models hr.job and hr.employee that should have been in submodules to their correct place (in hr_something) to avoid dependencies problems (addons hr, hr_*) bzr revid: ged@openerp.com-20140415105419-wy026n5k10wo80wb --- addons/hr/hr.py | 39 ------------------- addons/hr_contract/hr_contract.py | 10 +++++ addons/hr_evaluation/hr_evaluation.py | 11 ++++++ addons/hr_evaluation/hr_evaluation_view.xml | 2 +- addons/hr_holidays/hr_holidays.py | 12 ++++++ addons/hr_payroll/hr_payroll.py | 11 ++++++ addons/hr_recruitment/hr_recruitment.py | 13 +++++++ addons/hr_recruitment/hr_recruitment_view.xml | 16 +++++--- .../hr_timesheet_sheet/hr_timesheet_sheet.py | 20 ++++++++++ 9 files changed, 89 insertions(+), 45 deletions(-) diff --git a/addons/hr/hr.py b/addons/hr/hr.py index 4efa72e8f5e..a13a1866493 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -92,17 +92,6 @@ 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'] @@ -133,10 +122,6 @@ 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 = { @@ -201,20 +186,6 @@ 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 @@ -266,16 +237,6 @@ 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.py b/addons/hr_contract/hr_contract.py index d74253b5d53..d641c490ec2 100644 --- a/addons/hr_contract/hr_contract.py +++ b/addons/hr_contract/hr_contract.py @@ -38,6 +38,15 @@ class hr_employee(osv.osv): res[emp.id] = False return res + def _contracts_count(self, cr, uid, ids, field_name, arg, context=None): + res = dict(map(lambda x: (x,0), ids)) + try: + for employee in self.browse(cr, uid, ids, context=context): + res[employee.id] = len(employee.contract_ids) + except: + pass + return res + _columns = { 'manager': fields.boolean('Is a Manager'), 'medic_exam': fields.date('Medical Examination Date'), @@ -47,6 +56,7 @@ class hr_employee(osv.osv): 'vehicle_distance': fields.integer('Home-Work Dist.', help="In kilometers"), 'contract_ids': fields.one2many('hr.contract', 'employee_id', 'Contracts'), 'contract_id':fields.function(_get_latest_contract, string='Contract', type='many2one', relation="hr.contract", help='Latest contract of the employee'), + 'contracts_count': fields.function(_contracts_count, type='integer', string='Contracts'), } diff --git a/addons/hr_evaluation/hr_evaluation.py b/addons/hr_evaluation/hr_evaluation.py index 462154e9e4a..bfcbf6a3369 100644 --- a/addons/hr_evaluation/hr_evaluation.py +++ b/addons/hr_evaluation/hr_evaluation.py @@ -102,11 +102,22 @@ class hr_employee(osv.osv): _name = "hr.employee" _inherit="hr.employee" + def _appraisal_count(self, cr, uid, ids, field_name, arg, context=None): + res = dict(map(lambda x: (x,0), ids)) + try: + for employee in self.browse(cr, uid, ids, context=context): + res[employee.id] = len(employee.appraisal_ids) + except: + pass + return res _columns = { 'evaluation_plan_id': fields.many2one('hr_evaluation.plan', 'Appraisal Plan'), 'evaluation_date': fields.date('Next Appraisal Date', help="The date of the next appraisal is computed by the appraisal plan's dates (first appraisal + periodicity)."), + 'appraisal_ids': fields.one2many('hr.evaluation.interview', 'user_to_review_id', 'Appraisal Interviews'), + 'appraisal_count': fields.function(_appraisal_count, type='integer', string='Appraisal Interviews'), } + def run_employee_evaluation(self, cr, uid, automatic=False, use_new_cursor=False, context=None): now = parser.parse(datetime.now().strftime('%Y-%m-%d')) obj_evaluation = self.pool.get('hr_evaluation.evaluation') diff --git a/addons/hr_evaluation/hr_evaluation_view.xml b/addons/hr_evaluation/hr_evaluation_view.xml index ab8363049c1..e2b6a6274ab 100644 --- a/addons/hr_evaluation/hr_evaluation_view.xml +++ b/addons/hr_evaluation/hr_evaluation_view.xml @@ -149,7 +149,7 @@ class="oe_stat_button" icon="fa-sitemap" type="action"> - + diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index 932a290b4a1..356287dde7c 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -549,6 +549,15 @@ class hr_employee(osv.osv): result[holiday.employee_id.id]['current_leave_id'] = holiday.holiday_status_id.id return result + def _leaves_count(self, cr, uid, ids, field_name, arg, context=None): + res = dict(map(lambda x: (x,0), ids)) + try: + for employee in self.browse(cr, uid, ids, context=context): + res[employee.id] = len(employee.leave_ids) + except: + pass + return res + _columns = { 'remaining_leaves': fields.function(_get_remaining_days, string='Remaining Legal Leaves', fnct_inv=_set_remaining_days, type="float", help='Total number of legal leaves allocated to this employee, change this value to create allocation/leave request. Total based on all the leave types without overriding limit.'), 'current_leave_state': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Status", type="selection", @@ -557,6 +566,9 @@ class hr_employee(osv.osv): 'current_leave_id': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Type",type='many2one', relation='hr.holidays.status'), 'leave_date_from': fields.function(_get_leave_status, multi='leave_status', type='date', string='From Date'), 'leave_date_to': fields.function(_get_leave_status, multi='leave_status', type='date', string='To Date'), + 'leave_ids': fields.one2many('hr.holidays', 'employee_id', 'Leaves'), + 'leaves_count': fields.function(_leaves_count, type='integer', string='Leaves'), + } diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 8a8353ad5a0..e2cb1b3ad3f 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -982,9 +982,20 @@ class hr_employee(osv.osv): res[employee.id] = {'basic': result['sum']} return res + def _payslip_count(self, cr, uid, ids, field_name, arg, context=None): + res = dict(map(lambda x: (x,0), ids)) + try: + for employee in self.browse(cr, uid, ids, context=context): + res[employee.id] = len(employee.payslip_ids) + except: + pass + return res + _columns = { 'slip_ids':fields.one2many('hr.payslip', 'employee_id', 'Payslips', required=False, readonly=True), 'total_wage': fields.function(_calculate_total_wage, method=True, type='float', string='Total Basic Salary', digits_compute=dp.get_precision('Payroll'), help="Sum of all current contract's wage of employee."), + 'payslip_count': fields.function(_payslip_count, type='integer', string='Payslips'), + 'payslip_ids': fields.one2many('hr.payslip', 'employee_id', 'Payslips'), } diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 20e9e0930cc..d82463b2c47 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -517,6 +517,17 @@ class hr_job(osv.osv): ], context=context) 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 job in self.browse(cr, uid, ids, context=context): + res[job.id] = {'documents_count': len(job.document_ids), + 'application_count': len(job.applicant_ids), + } + except: + pass + return res + _columns = { 'survey_id': fields.many2one('survey', 'Interview Form', help="Choose an interview form for this job position and you will be able to print/answer this interview from all applicants who apply for this job"), 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True, @@ -524,8 +535,10 @@ class hr_job(osv.osv): "create new applicants for this job position."), 'address_id': fields.many2one('res.partner', 'Job Location', help="Address where employees are working"), 'application_ids': fields.one2many('hr.applicant', 'job_id', 'Applications'), + 'application_count': fields.function(_count_all, type='integer', string='Applications', multi=True), 'manager_id': fields.related('department_id', 'manager_id', type='many2one', string='Department Manager', relation='hr.employee', readonly=True, store=True), 'document_ids': fields.function(_get_attached_docs, type='one2many', relation='ir.attachment', string='Applications'), + 'documents_count': fields.function(_count_all, type='integer', string='Documents', multi=True), 'user_id': fields.many2one('res.users', 'Recruitment Responsible', track_visibility='onchange'), 'color': fields.integer('Color Index'), } diff --git a/addons/hr_recruitment/hr_recruitment_view.xml b/addons/hr_recruitment/hr_recruitment_view.xml index 6221d0d83f1..22735af30a9 100644 --- a/addons/hr_recruitment/hr_recruitment_view.xml +++ b/addons/hr_recruitment/hr_recruitment_view.xml @@ -75,20 +75,26 @@