From d2f7cd18108399153c8e11a07eb63861543c4bd5 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Thu, 24 Mar 2011 15:34:28 +0100 Subject: [PATCH] [IMP] search on email bzr revid: tfr@openerp.com-20110324143428-kamrtx5gsgzje4ez --- addons/crm/crm_lead.py | 50 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index b46bef7f003..872556e2833 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -97,7 +97,18 @@ class crm_lead(crm_case, osv.osv): duration = len(no_days) res[lead.id][field] = abs(int(duration)) return res - + + def _history_search(self, cr, uid, obj, name, args, context=None): + res = [] + msg_obj = self.pool.get('mailgate.message') + message_ids = msg_obj.search(cr, uid, [('history','=',True), ('name', args[0][1], args[0][2])], context=context) + lead_ids = self.search(cr, uid, [('message_ids', 'in', message_ids)], context=context) + + if lead_ids: + return [('id', 'in', lead_ids)] + else: + return [('id', '=', '0')] + def _get_email_subject(self, cr, uid, ids, fields, args, context=None): res = {} for obj in self.browse(cr, uid, ids, context=context): @@ -105,11 +116,12 @@ class crm_lead(crm_case, osv.osv): for msg in obj.message_ids: if msg.history: res[obj.id] = msg.name + break return res _columns = { # Overridden from res.partner.address: - 'partner_id': fields.many2one('res.partner', 'Partner', ondelete='set null', + 'partner_id': fields.many2one('res.partner', 'Partner', ondelete='set null', select=True, help="Optional linked partner, usually after conversion of the lead"), # From crm.case @@ -133,7 +145,7 @@ class crm_lead(crm_case, osv.osv): domain="['|',('section_id','=',section_id),('section_id','=',False)]"), 'channel_id': fields.many2one('res.partner.canal', 'Channel'), - 'contact_name': fields.char('Contact Name', size=64), + 'contact_name': fields.char('Contact Name', size=64), 'partner_name': fields.char("Customer Name", size=64,help='The name of the future partner that will be created while converting the into opportunity'), 'optin': fields.boolean('Opt-In', help="If opt-in is checked, this contact has accepted to receive emails."), 'optout': fields.boolean('Opt-Out', help="If opt-out is checked, this contact has refused to receive emails or unsubscribed to a campaign."), @@ -156,11 +168,11 @@ class crm_lead(crm_case, osv.osv): help='The state is set to \'Draft\', when a case is created.\ \nIf the case is in progress the state is set to \'Open\'.\ \nWhen the case is over, the state is set to \'Done\'.\ - \nIf the case needs to be reviewed then the state is set to \'Pending\'.'), + \nIf the case needs to be reviewed then the state is set to \'Pending\'.'), 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]), - 'subjects': fields.function(_get_email_subject, string='Subject of Email', method=True, type='char', size=64, store=True), + 'subjects': fields.function(_get_email_subject, fnct_search=_history_search, string='Subject of Email', method=True, type='char', size=64), } - + _defaults = { 'active': lambda *a: 1, @@ -173,8 +185,8 @@ class crm_lead(crm_case, osv.osv): 'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0], #'stage_id': _get_stage_id, } - - + + def onchange_partner_address_id(self, cr, uid, ids, add, email=False): """This function returns value of partner email based on Partner Address @@ -199,10 +211,10 @@ class crm_lead(crm_case, osv.osv): @param *args: Give Tuple Value """ leads = self.browse(cr, uid, ids) - - - - for i in xrange(0, len(ids)): + + + + for i in xrange(0, len(ids)): if leads[i].state == 'draft': value = {} if not leads[i].stage_id : @@ -213,7 +225,7 @@ class crm_lead(crm_case, osv.osv): self.log_open( cr, uid, leads[i]) res = super(crm_lead, self).case_open(cr, uid, ids, *args) return res - + def log_open(self, cr, uid, case): if case.type == 'lead': message = _("The lead '%s' has been opened.") % case.name @@ -283,10 +295,10 @@ class crm_lead(crm_case, osv.osv): def write(self, cr, uid, ids, vals, context=None): if not context: context = {} - + if 'date_closed' in vals: return super(crm_lead,self).write(cr, uid, ids, vals, context=context) - + if 'stage_id' in vals and vals['stage_id']: stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context) self.history(cr, uid, ids, _("Changed Stage to: ") + stage_obj.name, details=_("Changed Stage to: ") + stage_obj.name) @@ -298,7 +310,7 @@ class crm_lead(crm_case, osv.osv): message = _("The stage of opportunity '%s' has been changed to '%s'.") % (case.name, stage_obj.name) self.log(cr, uid, case.id, message) return super(crm_lead,self).write(cr, uid, ids, vals, context) - + def stage_next(self, cr, uid, ids, context=None): stage = super(crm_lead, self).stage_next(cr, uid, ids, context=context) if stage: @@ -307,7 +319,7 @@ class crm_lead(crm_case, osv.osv): data = {'probability': stage_obj.probability} self.write(cr, uid, ids, data) return stage - + def stage_previous(self, cr, uid, ids, context=None): stage = super(crm_lead, self).stage_previous(cr, uid, ids, context=context) if stage: @@ -317,7 +329,7 @@ class crm_lead(crm_case, osv.osv): self.write(cr, uid, ids, data) return stage - + def message_new(self, cr, uid, msg, context=None): """ Automatically calls when new email message arrives @@ -367,7 +379,7 @@ class crm_lead(crm_case, osv.osv): @param self: The object pointer @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, - @param ids: List of update mail’s IDs + @param ids: List of update mail’s IDs """ if isinstance(ids, (str, int, long)): ids = [ids]