[IMP] improved function to open attachments.
authorTurkesh Patel (Open ERP) <tpa@tinyerp.com>
Tue, 24 Dec 2013 13:38:13 +0000 (19:08 +0530)
committerTurkesh Patel (Open ERP) <tpa@tinyerp.com>
Tue, 24 Dec 2013 13:38:13 +0000 (19:08 +0530)
bzr revid: tpa@tinyerp.com-20131224133813-5pbsd3jxbj1ypxk1

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

index b6e7cc9..6ef301c 100644 (file)
@@ -561,21 +561,13 @@ class hr_job(osv.osv):
         action['context'] = str({'search_default_job_id': [job.id], 'default_job_id': job.id, 'default_user_id': job.user_id.id})
         return action
 
-    def attachment_tree_view(self, cr, uid, ids, context):
+    def open_attachments(self, cr, uid, ids, context):
+        #open attachments of job and related applicantions.
+        model, action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base','action_attachment')
+        action = self.pool.get(model).read(cr, uid, action_id, context=context)
         applicant_ids = self.pool.get('hr.applicant').search(cr, uid, [('job_id', 'in', ids)], context=context)
-        domain = ['|', '&', ('res_model', '=', 'hr.job'), ('res_id', 'in', ids), '&',('res_model', '=', 'hr.applicant'), ('res_id', 'in', applicant_ids)]
-        res_id = ids and ids[0] or False
-        return {
-            'name': _('Attachments'),
-            'domain': domain,
-            'res_model': 'ir.attachment',
-            'type': 'ir.actions.act_window',
-            'view_id': False,
-            'view_mode': 'tree,form',
-            'view_type': 'form',
-            'limit': 80,
-            'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, res_id)
-        }
+        action['domain'] = str(['|', '&', ('res_model', '=', 'hr.job'), ('res_id', 'in', ids), '&',('res_model', '=', 'hr.applicant'), ('res_id', 'in', applicant_ids)])
+        return action
 
 class applicant_category(osv.osv):
     """ Category of applicant """
index b66bb4b..d182cf5 100644 (file)
             </xpath>
             <div name="buttons" position="inside">
                 <button string="Applications" name="%(action_hr_job_applications)d" context="{'default_user_id': user_id}" type="action"/>
-                <button name="attachment_tree_view" string="Documents" type="object"/>
+                <button name="open_attachments" string="Documents" type="object"/>
             </div>
         </field>
     </record>
                                                 <span t-if="record.application_ids.raw_value.length lt 2"><t t-esc="record.application_ids.raw_value.length"/> Application</span>
                                             </a>
                                             <br/>
-                                            <a t-if="record.document_ids.raw_value.length gt 0" name="attachment_tree_view" type="object">
+                                            <a t-if="record.document_ids.raw_value.length gt 0" name="open_attachments" type="object">
                                                 <span t-if="record.document_ids.raw_value.length gt 1"><t t-esc="record.document_ids.raw_value.length"/> Documents</span>
                                                 <span t-if="record.document_ids.raw_value.length lt 2"><t t-esc="record.document_ids.raw_value.length"/> Document</span>
                                             </a>