[FIX] {crm,base}_action_rule: new attempt to fix deprecated schedule_with_attach
bzr revid: odo@openerp.com-20120904160512-vg7np7tg83jlmyzp
This commit is contained in:
parent
20c4bcf9fc
commit
f5bc9db80c
|
@ -302,33 +302,26 @@ 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 user’s 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')
|
||||
emailfrom = tools.config.get('email_from')
|
||||
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))
|
||||
if not emailfrom and hasattr(obj, 'user_id') and obj.user_id and obj.user_id.email:
|
||||
emailfrom = obj.user_id.email
|
||||
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)
|
||||
_("Missing default email address or missing email on responsible user"))
|
||||
return self.pool.get('mail.mail').create(cr, uid,
|
||||
{ 'email_from': emailfrom,
|
||||
'email_to': emails.join(','),
|
||||
'reply_to': reply_to,
|
||||
'state': 'outgoing',
|
||||
'subject': '[%d] %s' % (obj.id, tools.ustr(obj.name)),
|
||||
'body_html': '<pre>%s</pre>' % body,
|
||||
'res_id': obj.id,
|
||||
'model': obj._table
|
||||
}, context=context)
|
||||
|
||||
|
||||
def do_check(self, cr, uid, action, obj, context=None):
|
||||
|
|
|
@ -46,21 +46,11 @@ class base_action_rule(osv.osv):
|
|||
}
|
||||
|
||||
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:
|
||||
mail_id = super(base_action_rule, self).email_send(cr, uid, obj, emails, body, emailfrom=emailfrom, context=context)
|
||||
if mail_id and 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)
|
||||
self.pool.get('mail.mail').write(cr, uid, [mail_id], {'reply_to': reply_to}, context=context)
|
||||
return mail_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)
|
||||
|
|
Loading…
Reference in New Issue