[IMP] crm_lead: removed _send_mail_to_salesman, never called; base_action_rule: cleaned email_send with new message_post; cleaned do_action about partner_ids search; crm_action_rule: removed email_send that was a duplicate of the base_action_rule one; updated do_action about partner_ids search.

bzr revid: tde@openerp.com-20120904153434-vqnrfgwz4rq1ox5m
This commit is contained in:
Thibault Delavallée 2012-09-04 17:34:34 +02:00
parent bacbb8e2f4
commit 9e8de4f5ed
3 changed files with 25 additions and 96 deletions

View File

@ -301,35 +301,10 @@ the rule to mark CC(mail to any other person defined in actions)."),
}
return self.format_body(body % data)
def email_send(self, cr, uid, obj, emails, body, emailfrom=None, context=None):
""" send email
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param email: pass the emails
@param emailfrom: Pass name the email From else False
@param context: A standard dictionary for contextual values """
if not emailfrom:
emailfrom = tools.config.get('email_from', False)
if context is None:
context = {}
mail_message = self.pool.get('mail.message')
def email_send(self, cr, uid, obj, partner_ids, body, context=None):
body = self.format_mail(obj, body)
if not emailfrom:
if hasattr(obj, 'user_id') and obj.user_id and obj.user_id.email:
emailfrom = obj.user_id.email
name = '[%d] %s' % (obj.id, tools.ustr(obj.name))
emailfrom = tools.ustr(emailfrom)
reply_to = emailfrom
if not emailfrom:
raise osv.except_osv(_('Error!'),
_("No email ID found for your company address."))
return mail_message.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, res_id=obj.id)
subject = '[%d] %s' % (obj.id, tools.ustr(obj.name))
return obj.message_post(cr, uid, obj.id, subject=name, body=body, partner_ids=partner_ids, context=context)
def do_check(self, cr, uid, action, obj, context=None):
""" check Action
@ -416,32 +391,23 @@ the rule to mark CC(mail to any other person defined in actions)."),
if action.act_method:
getattr(model_obj, 'act_method')(cr, uid, [obj.id], action, context)
emails = []
if hasattr(obj, 'user_id') and action.act_mail_to_user:
if obj.user_id:
emails.append(obj.user_id.email)
if action.act_mail_to_watchers:
emails += (action.act_email_cc or '').split(',')
if action.act_mail_to_email:
emails += (action.act_mail_to_email or '').split(',')
locals_for_emails = {
'user' : self.pool.get('res.users').browse(cr, uid, uid, context=context),
'obj' : obj,
}
# Email: find partner_ids
res_partner_obj = self.pool.get('res.partner')
partner_ids = []
if action.act_mail_to_user and obj._columns.get('user_id') and obj.user_id:
partner_ids.append(obj.user_id.partner_id.id)
if action.act_mail_to_watchers and action.act_email_cc:
partner_ids += [res_partner_obj.find_or_create(cr, uid, mail, context=context)
for mail in action.act_email_cc.split(',') if mail]
if action.act_mail_to_email and action.act_mail_to_email:
partner_ids += [res_partner_obj.find_or_create(cr, uid, mail, context=context)
for mail in action.act_mail_to_email.split(',') if mail]
if action.act_email_to:
emails.append(safe_eval(action.act_email_to, {}, locals_for_emails))
emails = filter(None, emails)
if len(emails) and action.act_mail_body:
emails = list(set(emails))
email_from = safe_eval(action.act_email_from, {}, locals_for_emails)
emails = tools.email_split(','.join(filter(None, emails)))
email_froms = tools.email_split(email_from)
if email_froms:
self.email_send(cr, uid, obj, emails, action.act_mail_body, emailfrom=email_froms[0])
emails = safe_eval(action.act_email_to, {}, locals_for_emails)
partner_ids += [res_partner_obj.find_or_create(cr, uid, mail, context=context)
for mail in emails if mail]
if partner_ids:
self.email_send(cr, uid, obj, partner_ids, action.act_mail_body, context=context)
return True
def _action(self, cr, uid, ids, objects, scrit=None, context=None):

View File

@ -45,23 +45,6 @@ class base_action_rule(osv.osv):
help="Check this if you want the rule to send an email to the partner."),
}
def email_send(self, cr, uid, obj, emails, body, emailfrom=tools.config.get('email_from', False), context=None):
mail_message = self.pool.get('mail.message')
body = self.format_mail(obj, body)
if not emailfrom:
if hasattr(obj, 'user_id') and obj.user_id and obj.user_id.email:
emailfrom = obj.user_id.email
name = '[%d] %s' % (obj.id, tools.ustr(obj.name))
emailfrom = tools.ustr(emailfrom)
if hasattr(obj, 'section_id') and obj.section_id and obj.section_id.alias_id:
reply_to = obj.section_id.alias_id.name_get()[0][1]
else:
reply_to = emailfrom
if not emailfrom:
raise osv.except_osv(_('Error!'), _("There is no email for your company address."))
return mail_message.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model=obj._name, reply_to=reply_to, res_id=obj.id)
def do_check(self, cr, uid, action, obj, context=None):
ok = super(base_action_rule, self).do_check(cr, uid, action, obj, context=context)
@ -110,17 +93,15 @@ class base_action_rule(osv.osv):
model_obj.write(cr, uid, [obj.id], write, context)
super(base_action_rule, self).do_action(cr, uid, action, model_obj, obj, context=context)
emails = []
if hasattr(obj, 'email_from') and action.act_mail_to_partner:
emails.append(obj.email_from)
emails = filter(None, emails)
if len(emails) and action.act_mail_body:
emails = list(set(emails))
self.email_send(cr, uid, obj, emails, action.act_mail_body)
# Post a message if act_mail_to_partner and act_mail_body
if not action.act_mail_body or not action.act_mail_to_partner:
return True
if obj._columns.get('email_from') and obj.email_from:
partner_ids = [self.pool.get('res.partner').find_or_create(cr, uid, obj.email_from, context=context)]
self.email_send(cr, uid, obj, partner_ids, action.act_mail_body, context=context)
return True
def state_get(self, cr, uid, context=None):
"""Gets available states for crm"""
res = super(base_action_rule, self).state_get(cr, uid, context=context)

View File

@ -668,24 +668,6 @@ class crm_lead(base_stage, osv.osv):
partner_ids[lead.id] = partner_id
return partner_ids
def _send_mail_to_salesman(self, cr, uid, lead, context=None):
"""
Send mail to salesman with updated Lead details.
@ lead: browse record of 'crm.lead' object.
"""
#TOFIX: mail template should be used here instead of fix subject, body text.
message = self.pool.get('mail.message')
email_to = lead.user_id and lead.user_id.email
if not email_to:
return False
email_from = lead.section_id and lead.section_id.user_id and lead.section_id.user_id.email or email_to
partner = lead.partner_id and lead.partner_id.name or lead.partner_name
subject = "lead %s converted into opportunity" % lead.name
body = "Info \n Id : %s \n Subject: %s \n Partner: %s \n Description : %s " % (lead.id, lead.name, lead.partner_id.name, lead.description)
return message.schedule_with_attach(cr, uid, email_from, [email_to], subject, body)
def allocate_salesman(self, cr, uid, ids, user_ids, team_id=False, context=None):
index = 0
for lead_id in ids: