[imp] improve code and improve naming conventions.

bzr revid: amb@tinyerp.com-20130911095804-u1dk4kdhwcls2trm
This commit is contained in:
Amit Bhavsar (Open ERP) 2013-09-11 15:28:04 +05:30
parent e21681633c
commit 780672e9b1
3 changed files with 11 additions and 14 deletions

View 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):

View 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),
}

View File

@ -242,7 +242,7 @@
<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">
@ -295,9 +295,9 @@
</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>