[imp] improve code and improve naming conventions.
authorAmit Bhavsar (Open ERP) <amb@tinyerp.com>
Wed, 11 Sep 2013 09:58:04 +0000 (15:28 +0530)
committerAmit Bhavsar (Open ERP) <amb@tinyerp.com>
Wed, 11 Sep 2013 09:58:04 +0000 (15:28 +0530)
bzr revid: amb@tinyerp.com-20130911095804-u1dk4kdhwcls2trm

addons/hr_applicant_document/hr_applicant_document.py
addons/hr_recruitment/hr_recruitment.py
addons/hr_recruitment/hr_recruitment_view.xml

index 4593147..b201b2b 100644 (file)
@@ -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):
index 3ca69fc..3afce09 100644 (file)
@@ -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),
     }
index 8b7a169..dc1a387 100644 (file)
                 <field name="department_id"/>
                 <field name="categ_ids"/>
                 <field name="message_summary"/>
-                <field name="attachments"/>
+                <field name="attachment_number"/>
                 <templates>
                     <t t-name="kanban-tooltip">
                         <ul class="oe_kanban_tooltip">
                                 </div>
                                 <div class="oe_kanban_footer_left" style="margin-top:5px;">
                                     <t t-raw="record.message_summary.raw_value"/>
-                                    <a t-if="record.attachments.raw_value == 1" name="attachment_tree_view" type="object" style="margin-right: 10px"> <field name="attachments"/> Document</a> 
+                                    <a t-if="record.attachment_number.raw_value == 1" name="attachment_tree_view" type="object" style="margin-right: 10px"> <field name="attachment_number"/> Document</a> 
                                                        
-                                    <a t-if="record.attachments.raw_value gt 1" name="attachment_tree_view" type="object" style="margin-right: 10px"> <field name="attachments"/> Documents</a> 
+                                    <a t-if="record.attachment_number.raw_value gt 1" name="attachment_tree_view" type="object" style="margin-right: 10px"> <field name="attachment_number"/> Documents</a> 
 
                                 </div>