From 780672e9b1657a7e388081d432d7c2c4766e5e3b Mon Sep 17 00:00:00 2001 From: "Amit Bhavsar (Open ERP)" Date: Wed, 11 Sep 2013 15:28:04 +0530 Subject: [PATCH] [imp] improve code and improve naming conventions. bzr revid: amb@tinyerp.com-20130911095804-u1dk4kdhwcls2trm --- addons/hr_applicant_document/hr_applicant_document.py | 10 +++++----- addons/hr_recruitment/hr_recruitment.py | 9 +++------ addons/hr_recruitment/hr_recruitment_view.xml | 6 +++--- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/addons/hr_applicant_document/hr_applicant_document.py b/addons/hr_applicant_document/hr_applicant_document.py index 45931478f26..b201b2b1889 100644 --- a/addons/hr_applicant_document/hr_applicant_document.py +++ b/addons/hr_applicant_document/hr_applicant_document.py @@ -27,11 +27,11 @@ class hr_applicant(osv.osv): res = {} attachment_pool = self.pool.get('ir.attachment') for id in ids: - res[id] = 0 - attachment_ids = attachment_pool.search(cr, uid, [('res_model','=','hr.applicant'),('res_id','=',id)], context=context) - if attachment_ids: - for attachment in attachment_pool.browse(cr, uid, attachment_ids, context=context): - res[id] = attachment.index_content + res[id] = '' + attachment_ids = attachment_pool.search(cr, uid, [('res_model', '=', 'hr.applicant'), ('res_id', '=', id)], context=context) + for attachment in attachment_pool.browse(cr, uid, attachment_ids, context=context): + # adding index content of all attachments into one in order to find easily from all attachments + res[id] += attachment.index_content or '' return res def _content_search(self, cursor, user, obj, name, args, context=None): diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 3ca69fc6289..3afce09a2da 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -189,11 +189,8 @@ class hr_applicant(osv.Model): def _compute_attachments(self, cr, uid, ids, fields, args, context=None): res = {} attachment_pool = self.pool.get('ir.attachment') - for applicant in self.browse(cr, uid, ids, context=context): - res[applicant.id] = 0 - attach = attachment_pool.search(cr, uid, [('res_model','=','hr.applicant'),('res_id','=',applicant.id)], context=context) - if attach: - res[applicant.id] = len(attach) + for applicant in ids: + res[applicant] = attachment_pool.search_count(cr, uid, [('res_model', '=', 'hr.applicant'), ('res_id', '=', applicant)], context=context) return res _columns = { @@ -240,7 +237,7 @@ class hr_applicant(osv.Model): multi='day_close', type="float", store=True), 'color': fields.integer('Color Index'), 'emp_id': fields.many2one('hr.employee', string='Employee', help='Employee linked to the applicant.'), - 'attachments': fields.function(_compute_attachments, string='Number of Attachments', \ + 'attachment_number': fields.function(_compute_attachments, string='Number of Attachments', \ type="integer"), 'user_email': fields.related('user_id', 'email', type='char', string='User Email', readonly=True), } diff --git a/addons/hr_recruitment/hr_recruitment_view.xml b/addons/hr_recruitment/hr_recruitment_view.xml index 8b7a16970d4..dc1a387019e 100644 --- a/addons/hr_recruitment/hr_recruitment_view.xml +++ b/addons/hr_recruitment/hr_recruitment_view.xml @@ -242,7 +242,7 @@ - +