-
diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py
index d22bd4c2e3c..bca46a3c91c 100644
--- a/addons/mail/mail_message.py
+++ b/addons/mail/mail_message.py
@@ -135,7 +135,7 @@ class mail_message(osv.Model):
_defaults = {
'type': 'email',
'date': lambda *a: fields.datetime.now(),
- 'author_id': lambda s,cr,uid,ctx={}: s._get_default_author(cr, uid, ctx),
+ 'author_id': lambda self,cr,uid,ctx: self._get_default_author(cr, uid, ctx),
'body': '',
}
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index 6e5f594354a..eda7adb995c 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -158,17 +158,16 @@ class mail_thread(osv.AbstractModel):
'mail_followers', 'res_id', 'partner_id',
reference_column='res_model', string='Followers'),
'message_comment_ids': fields.one2many('mail.message', 'res_id',
- domain=lambda self: [('model','=',self._name),('type','in',('comment','email'))],
- string='Related Messages',
- help="All messages related to the current document."),
+ domain=lambda self: [('model', '=', self._name), ('type', 'in', ('comment', 'email'))],
+ string='Comments and emails',
+ help="Comments and emails"),
'message_ids': fields.one2many('mail.message', 'res_id',
domain=lambda self: [('model','=',self._name)],
- string='Related Messages',
- help="All messages related to the current document."),
+ string='Messages',
+ help="Messages and communication history"),
'message_unread': fields.function(_get_message_data, fnct_search=_search_unread,
- string='Has Unread Messages', type='boolean',
- help="When checked, new messages require your attention.",
- multi="_get_message_data"),
+ type='boolean', string='Unread Messages', multi="_get_message_data",
+ help="If checked new messages require your attention."),
'message_summary': fields.function(_get_message_data, method=True,
type='text', string='Summary', multi="_get_message_data",
help="Holds the Chatter summary (number of messages, ...). "\
@@ -181,7 +180,7 @@ class mail_thread(osv.AbstractModel):
#------------------------------------------------------
def create(self, cr, uid, vals, context=None):
- """ Override of create to subscribe the current user. """
+ """ Override to subscribe the current user. """
thread_id = super(mail_thread, self).create(cr, uid, vals, context=context)
self.message_subscribe_users(cr, uid, [thread_id], [uid], context=context)
return thread_id
@@ -215,11 +214,8 @@ class mail_thread(osv.AbstractModel):
def _message_find_partners(self, cr, uid, message, header_fields=['From'], context=None):
""" Find partners related to some header fields of the message. """
s = ', '.join([decode(message.get(h)) for h in header_fields if message.get(h)])
- mails = tools.email_split(s)
- result = []
- for email in mails:
- result += self.pool.get('res.partner').search(cr, uid, [('email', 'ilike', email)], context=context)
- return result
+ return [partner_id for email in tools.email_split(s)
+ for partner_id in self.pool.get('res.partner').search(cr, uid, [('email', 'ilike', email)], context=context)]
def _message_find_user_id(self, cr, uid, message, context=None):
from_local_part = tools.email_split(decode(message.get('From')))[0]
@@ -551,16 +547,16 @@ class mail_thread(osv.AbstractModel):
#------------------------------------------------------
def log(self, cr, uid, id, message, secondary=False, context=None):
- _logger.warning("log() is deprecated. As this module inherit from \
- mail.thread, the message will be managed by this \
- module instead of by the res.log mechanism. Please \
- use the mail.thread OpenChatter API instead of the \
- now deprecated res.log.")
+ _logger.warning("log() is deprecated. As this module inherit from "\
+ "mail.thread, the message will be managed by this "\
+ "module instead of by the res.log mechanism. Please "\
+ "use mail_thread.message_post() instead of the "\
+ "now deprecated res.log.")
self.message_post(cr, uid, [id], message, context=context)
def message_post(self, cr, uid, thread_id, body='', subject=False,
- msg_type='notification', parent_id=False, attachments=None, context=None, **kwargs):
- """ Post a new message in an existing message thread, returning the new
+ type='notification', parent_id=False, attachments=None, context=None, **kwargs):
+ """ Post a new message in an existing thread, returning the new
mail.message ID. Extra keyword arguments will be used as default
column values for the new mail.message record.
@@ -568,7 +564,7 @@ class mail_thread(osv.AbstractModel):
:param str body: body of the message, usually raw HTML that will
be sanitized
:param str subject: optional subject
- :param str msg_type: mail_message.type
+ :param str type: mail_message.type
:param int parent_id: optional ID of parent message in this thread
:param tuple(str,str) attachments: list of attachment tuples in the form
``(name,content)``, where content is NOT base64 encoded
@@ -601,7 +597,7 @@ class mail_thread(osv.AbstractModel):
'res_id': thread_id or False,
'body': body,
'subject': subject,
- 'type': msg_type,
+ 'type': type,
'parent_id': parent_id,
'attachment_ids': attachment_ids,
})
@@ -615,40 +611,37 @@ class mail_thread(osv.AbstractModel):
def message_subscribe_users(self, cr, uid, ids, user_ids=None, context=None):
""" Wrapper on message_subscribe, using users. If user_ids is not
provided, subscribe uid instead. """
- # isinstance: because using message_subscribe_users called in a view set the context as user_ids
- if not user_ids or isinstance(user_ids, dict): user_ids = [uid]
+ if not user_ids: user_ids = [uid]
partner_ids = [user.partner_id.id for user in self.pool.get('res.users').browse(cr, uid, user_ids, context=context)]
return self.message_subscribe(cr, uid, ids, partner_ids, context=context)
def message_subscribe(self, cr, uid, ids, partner_ids, context=None):
""" Add partners to the records followers.
-
:param partner_ids: a list of partner_ids to subscribe
- :param return: new value of followers, for Chatter
+ :param return: new value of followers if read_back key in context
"""
self.write(cr, uid, ids, {'message_follower_ids': [(4, pid) for pid in partner_ids]}, context=context)
- # TDE: temp, must check followers widget
+ if context and context.get('read_back'):
+ return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids]
return []
- # return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids]
+
def message_unsubscribe_users(self, cr, uid, ids, user_ids=None, context=None):
""" Wrapper on message_subscribe, using users. If user_ids is not
provided, unsubscribe uid instead. """
- # isinstance: because using message_subscribe_users called in a view set the context as user_ids
- if not user_ids or isinstance(user_ids, dict): user_ids = [uid]
+ if not user_ids: user_ids = [uid]
partner_ids = [user.partner_id.id for user in self.pool.get('res.users').browse(cr, uid, user_ids, context=context)]
return self.message_unsubscribe(cr, uid, ids, partner_ids, context=context)
def message_unsubscribe(self, cr, uid, ids, partner_ids, context=None):
""" Remove partners from the records followers.
-
:param partner_ids: a list of partner_ids to unsubscribe
- :param return: new value of followers, for Chatter
+ :param return: new value of followers if read_back key in context
"""
self.write(cr, uid, ids, {'message_follower_ids': [(3, pid) for pid in partner_ids]}, context=context)
- # TDE: temp, must check followers widget
+ if context and context.get('read_back'):
+ return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids]
return []
- # return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids]
#------------------------------------------------------
# Thread state
@@ -679,4 +672,3 @@ class mail_thread(osv.AbstractModel):
partner_id = %s
''', (ids, self._name, partner_id))
return True
-
diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js
index 6125aac12dc..e5d216ed3d2 100644
--- a/addons/mail/static/src/js/mail_followers.js
+++ b/addons/mail/static/src/js/mail_followers.js
@@ -9,7 +9,7 @@ openerp_mail_followers = function(session, mail) {
* mail_followers Widget
* ------------------------------------------------------------
*
- * This widget handles the display of a list of records as a vetical
+ * This widget handles the display of a list of records as a vertical
* list, with an image on the left. The widget itself is a floatting
* right-sided box.
* This widget is mainly used to display the followers of records
@@ -65,25 +65,17 @@ openerp_mail_followers = function(session, mail) {
this.$el.find('div.oe_mail_recthread_aside').hide();
return;
}
- if (this.getParent().fields.message_is_follower === undefined) {
- // TDE: TMP, need to change all form views
- this.message_is_follower = false;
- }
- else {
- this.message_is_follower = this.getParent().fields.message_is_follower.get_value();
- }
return this.fetch_followers(value_);
},
fetch_followers: function (value_) {
- return this.ds_follow.call('read', [value_ || this.get_value(), ['name']]).then(this.proxy('display_followers'));
+ return this.ds_follow.call('read', [value_ || this.get_value(), ['name', 'user_ids']]).then(this.proxy('display_followers'));
},
- /**
- * Display the followers.
- * TODO: replace the is_follower check by fields read */
+ /** Display the followers, evaluate is_follower directly */
display_followers: function (records) {
var self = this;
+ this.message_is_follower = _.indexOf(_.flatten(_.pluck(records, 'user_ids')), this.session.uid) != -1;
var node_user_list = this.$el.find('ul.oe_mail_followers_display').empty();
this.$el.find('div.oe_mail_recthread_followers h4').html(this.options.title + ' (' + records.length + ')');
_(records).each(function (record) {
@@ -99,11 +91,13 @@ openerp_mail_followers = function(session, mail) {
},
do_follow: function () {
- return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id]]).pipe(this.proxy('set_value'));
+ var context = new session.web.CompoundContext(this.build_context(), {'read_back': true});
+ return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('set_value'));
},
do_unfollow: function () {
- return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id]]).pipe(this.proxy('set_value'));
+ var context = new session.web.CompoundContext(this.build_context(), {'read_back': true});
+ return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('set_value'));
},
});
};
diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py
index 9c148647b9b..f8fd02bfb7e 100644
--- a/addons/mail/tests/test_mail.py
+++ b/addons/mail/tests/test_mail.py
@@ -250,7 +250,7 @@ class test_mail(common.TransactionCase):
_attachments = [('First', 'My first attachment'), ('Second', 'My second attachment')]
# CASE1: post comment, body and subject specified
- msg_id = self.mail_group.message_post(cr, uid, self.group_pigs_id, body=_body1, subject=_subject, msg_type='comment')
+ msg_id = self.mail_group.message_post(cr, uid, self.group_pigs_id, body=_body1, subject=_subject, type='comment')
message = self.mail_message.browse(cr, uid, msg_id)
mail_ids = self.mail_mail.search(cr, uid, [], limit=1)
mail = self.mail_mail.browse(cr, uid, mail_ids[0])
@@ -280,7 +280,7 @@ class test_mail(common.TransactionCase):
# CASE2: post an email with attachments, parent_id, partner_ids
# TESTS: automatic subject, signature in body_html, attachments propagation
- msg_id2 = self.mail_group.message_post(cr, uid, self.group_pigs_id, body=_body2, msg_type='email',
+ msg_id2 = self.mail_group.message_post(cr, uid, self.group_pigs_id, body=_body2, type='email',
partner_ids=[(6, 0, [p_d_id])], parent_id=msg_id, attachments=_attachments)
message = self.mail_message.browse(cr, uid, msg_id2)
mail_ids = self.mail_mail.search(cr, uid, [], limit=1)
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index 41b10d6d4a3..3c93440642d 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -269,7 +269,7 @@ class mail_compose_message(osv.TransientModel):
post_values['attachments'] += new_attachments
post_values.update(email_dict)
# post the message
- active_model_pool.message_post(cr, uid, [res_id], msg_type='comment', context=context, **post_values)
+ active_model_pool.message_post(cr, uid, [res_id], type='comment', context=context, **post_values)
return {'type': 'ir.actions.act_window_close'}
From bacbb8e2f444ad7bf520ab3caf72351a1af28cc7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Tue, 4 Sep 2012 16:50:11 +0200
Subject: [PATCH 08/23] [REVIEW] base_stage: removed now dead
message_thread_followers method. mail_thread: set message_capable_models
back, because it is used in the plugin addon, adn therefore in various
plugin_XXX addons. Maybe a refactoring of those plugins could be done, but it
is beyond the scope of this refactoring.
bzr revid: tde@openerp.com-20120904145011-tlwgcu32uv8cwe6g
---
addons/base_status/base_stage.py | 11 -----------
addons/mail/mail_thread.py | 18 ++++++++++++------
2 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/addons/base_status/base_stage.py b/addons/base_status/base_stage.py
index 26afe548217..4cbb039490e 100644
--- a/addons/base_status/base_stage.py
+++ b/addons/base_status/base_stage.py
@@ -360,17 +360,6 @@ class base_stage(object):
def format_mail(self, obj, body):
return self.pool.get('base.action.rule').format_mail(obj, body)
- def message_thread_followers(self, cr, uid, ids, context=None):
- res = {}
- for case in self.browse(cr, uid, ids, context=context):
- l=[]
- if case.email_cc:
- l.append(case.email_cc)
- if case.user_id and case.user_id.email:
- l.append(case.user_id.email)
- res[case.id] = l
- return res
-
# ******************************
# Notifications
# ******************************
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index eda7adb995c..5bd81e3ccff 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -211,6 +211,15 @@ class mail_thread(osv.AbstractModel):
# Mail gateway
#------------------------------------------------------
+ def message_capable_models(self, cr, uid, context=None):
+ """ Used by the plugin addon, based for plugin_outlook and others. """
+ ret_dict = {}
+ for model_name in self.pool.obj_list():
+ model = self.pool.get(model_name)
+ if 'mail.thread' in getattr(model, '_inherit', []):
+ ret_dict[model_name] = model._description
+ return ret_dict
+
def _message_find_partners(self, cr, uid, message, header_fields=['From'], context=None):
""" Find partners related to some header fields of the message. """
s = ', '.join([decode(message.get(h)) for h in header_fields if message.get(h)])
@@ -378,9 +387,7 @@ class mail_thread(osv.AbstractModel):
for a given thread model, if the message did not belong to
an existing thread.
The default behavior is to create a new record of the corresponding
- model (based on some very basic info extracted from the message),
- then attach the message to the newly created record
- (by calling ``message_append_dict``).
+ model (based on some very basic info extracted from the message).
Additional behavior may be implemented by overriding this method.
:param dict msg_dict: a map containing the email details and
@@ -413,9 +420,8 @@ class mail_thread(osv.AbstractModel):
def message_update(self, cr, uid, ids, msg_dict, update_vals=None, context=None):
"""Called by ``message_process`` when a new message is received
- for an existing thread. The default behavior is to create a
- new mail.message in the given thread (by calling
- ``message_append_dict``)
+ for an existing thread. The default behavior is to update the record
+ with update_vals taken from the incoming email.
Additional behavior may be implemented by overriding this
method.
:param dict msg_dict: a map containing the email details and
From 9e8de4f5ed35ee1665526b3c2bc81fea6d3fe788 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Tue, 4 Sep 2012 17:34:34 +0200
Subject: [PATCH 09/23] [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
---
addons/base_action_rule/base_action_rule.py | 72 ++++++---------------
addons/crm/crm_action_rule.py | 31 ++-------
addons/crm/crm_lead.py | 18 ------
3 files changed, 25 insertions(+), 96 deletions(-)
diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py
index 8c115baed23..9f658b9294c 100644
--- a/addons/base_action_rule/base_action_rule.py
+++ b/addons/base_action_rule/base_action_rule.py
@@ -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 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')
+ 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):
diff --git a/addons/crm/crm_action_rule.py b/addons/crm/crm_action_rule.py
index 36700b5b6c2..ca6e02d99b5 100644
--- a/addons/crm/crm_action_rule.py
+++ b/addons/crm/crm_action_rule.py
@@ -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)
diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py
index 8117ed22c6f..881c0ace3cc 100644
--- a/addons/crm/crm_lead.py
+++ b/addons/crm/crm_lead.py
@@ -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:
From 39bd8f7595d83761847a5aa7dd7d2f73726cb56a Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 17:49:16 +0200
Subject: [PATCH 10/23] [FIX] base_status: fix deprecated
mail_message.schedule_with_attach -> message_port
bzr revid: odo@openerp.com-20120904154916-6y3chb54u0ypheog
---
addons/base_status/base_stage.py | 74 +++++++++++---------------------
1 file changed, 25 insertions(+), 49 deletions(-)
diff --git a/addons/base_status/base_stage.py b/addons/base_status/base_stage.py
index 4cbb039490e..529e70fdb49 100644
--- a/addons/base_status/base_stage.py
+++ b/addons/base_status/base_stage.py
@@ -297,55 +297,31 @@ class base_stage(object):
destination=False)
def remind_user(self, cr, uid, ids, context=None, attach=False, destination=True):
- mail_message = self.pool.get('mail.message')
- for case in self.browse(cr, uid, ids, context=context):
- if not destination and not case.email_from:
- return False
- if not case.user_id.email:
- return False
- if destination and case.section_id.user_id:
- case_email = case.section_id.user_id.email
- else:
- case_email = case.user_id.email
-
- src = case_email
- dest = case.user_id.email or ""
- body = case.description or ""
- for message in case.message_ids:
- if message.email_from and message.body:
- body = message.body
- break
-
- if not destination:
- src, dest = dest, case.email_from
- if body and case.user_id.signature:
- if body:
- body += '\n\n%s' % (case.user_id.signature)
- else:
- body = '\n\n%s' % (case.user_id.signature)
-
- body = self.format_body(body)
-
- attach_to_send = {}
-
- if attach:
- attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model', '=', self._name), ('res_id', '=', case.id)])
- attach_to_send = self.pool.get('ir.attachment').read(cr, uid, attach_ids, ['datas_fname', 'datas'])
- attach_to_send = dict(map(lambda x: (x['datas_fname'], base64.decodestring(x['datas'])), attach_to_send))
-
- # Send an email
- subject = "Reminder: [%s] %s" % (str(case.id), case.name, )
- mail_message.schedule_with_attach(cr, uid,
- src,
- [dest],
- subject,
- body,
- model=self._name,
- reply_to=case.section_id.reply_to,
- res_id=case.id,
- attachments=attach_to_send,
- context=context
- )
+ if 'message_post' in self:
+ for case in self.browse(cr, uid, ids, context=context):
+ if destination:
+ recipient_id = case.user_id.partner_id.id
+ else:
+ if not case.email_from:
+ return False
+ recipient_id = self.pool.get('res.partner').find_or_create(cr, uid, case.email_from, context=context)
+
+ body = case.description or ""
+ for message in case.message_ids:
+ if message.type == 'email' and message.body:
+ body = message.body
+ break
+ body = self.format_body(body)
+ attach_to_send = {}
+ if attach:
+ attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model', '=', self._name), ('res_id', '=', case.id)])
+ attach_to_send = self.pool.get('ir.attachment').read(cr, uid, attach_ids, ['datas_fname', 'datas'])
+ attach_to_send = dict(map(lambda x: (x['datas_fname'], x['datas'].decode('base64')), attach_to_send))
+
+ subject = "Reminder: [%s] %s" % (case.id, case.name)
+ self.message_post(cr, uid, case.id, body=body,
+ subject=subject, attachments=attach_to_send,
+ partner_ids=[recipient_id], context=context)
return True
def _check(self, cr, uid, ids=False, context=None):
From c0ac0611d1192d5a047a9119419fd6e4ef465808 Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 17:50:23 +0200
Subject: [PATCH 11/23] [IMP] misc bits - lint
bzr revid: odo@openerp.com-20120904155023-hchxi9jqemvqulpy
---
addons/mail/mail_thread.py | 2 +-
addons/project_issue/project_issue.py | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index 5bd81e3ccff..76787a8ac02 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -599,7 +599,7 @@ class mail_thread(osv.AbstractModel):
values = kwargs
values.update( {
- 'model': thread_id and context.get('thread_model', self._name) or False,
+ 'model': context.get('thread_model', self._name) if thread_id else False,
'res_id': thread_id or False,
'body': body,
'subject': subject,
diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py
index 9cc97ec470b..22384a12a10 100644
--- a/addons/project_issue/project_issue.py
+++ b/addons/project_issue/project_issue.py
@@ -363,7 +363,6 @@ class project_issue(base_stage, osv.osv):
return super(project_issue, self).write(cr, uid, ids, vals, context)
def onchange_task_id(self, cr, uid, ids, task_id, context=None):
- result = {}
if not task_id:
return {'value':{}}
task = self.pool.get('project.task').browse(cr, uid, task_id, context=context)
From 20c4bcf9fc978ee4a9ba81d7e1e471f4ccb4e6e1 Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 17:53:52 +0200
Subject: [PATCH 12/23] [REVERT] {crm,base}_action_rule: revert previous
attempt to fix deprecated schedule_with_attach
bzr revid: odo@openerp.com-20120904155352-shna0b9042wfs0gt
---
addons/base_action_rule/base_action_rule.py | 72 +++++++++++++++------
addons/crm/crm_action_rule.py | 31 +++++++--
2 files changed, 78 insertions(+), 25 deletions(-)
diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py
index 9f658b9294c..8c115baed23 100644
--- a/addons/base_action_rule/base_action_rule.py
+++ b/addons/base_action_rule/base_action_rule.py
@@ -301,10 +301,35 @@ 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, partner_ids, body, context=None):
+ 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')
body = self.format_mail(obj, body)
- 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)
+ 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)
+
def do_check(self, cr, uid, action, obj, context=None):
""" check Action
@@ -391,23 +416,32 @@ 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)
- # 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]
+ 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,
+ }
+
if action.act_email_to:
- 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)
+ 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])
return True
def _action(self, cr, uid, ids, objects, scrit=None, context=None):
diff --git a/addons/crm/crm_action_rule.py b/addons/crm/crm_action_rule.py
index ca6e02d99b5..36700b5b6c2 100644
--- a/addons/crm/crm_action_rule.py
+++ b/addons/crm/crm_action_rule.py
@@ -45,6 +45,23 @@ 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)
@@ -93,15 +110,17 @@ 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 = []
- # 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)
+ 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)
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)
From f5bc9db80c941df4b07630e7aa746f9c98388cb7 Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 18:05:12 +0200
Subject: [PATCH 13/23] [FIX] {crm,base}_action_rule: new attempt to fix
deprecated schedule_with_attach
bzr revid: odo@openerp.com-20120904160512-vg7np7tg83jlmyzp
---
addons/base_action_rule/base_action_rule.py | 35 +++++++++------------
addons/crm/crm_action_rule.py | 18 +++--------
2 files changed, 18 insertions(+), 35 deletions(-)
diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py
index 8c115baed23..237788d689a 100644
--- a/addons/base_action_rule/base_action_rule.py
+++ b/addons/base_action_rule/base_action_rule.py
@@ -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': '%s
' % body,
+ 'res_id': obj.id,
+ 'model': obj._table
+ }, context=context)
def do_check(self, cr, uid, action, obj, context=None):
diff --git a/addons/crm/crm_action_rule.py b/addons/crm/crm_action_rule.py
index 36700b5b6c2..8b1ba655afc 100644
--- a/addons/crm/crm_action_rule.py
+++ b/addons/crm/crm_action_rule.py
@@ -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)
From 5d2172192a944e481951ceaec12c0401e9127b09 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Tue, 4 Sep 2012 18:13:46 +0200
Subject: [PATCH 14/23] [FIX] portal: schedule_with_attach is now a mail.mail
creation immediately send.
bzr revid: tde@openerp.com-20120904161346-f3g3a3v2i3pi6jwk
---
addons/portal/wizard/portal_wizard.py | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py
index 0260ce338fc..85f6566eba6 100644
--- a/addons/portal/wizard/portal_wizard.py
+++ b/addons/portal/wizard/portal_wizard.py
@@ -171,7 +171,7 @@ class wizard(osv.osv_memory):
'url': wiz.portal_id.url or _("(missing url)"),
'db': cr.dbname,
}
- mail_message_obj = self.pool.get('mail.message')
+ mail_mail_obj = self.pool.get('mail.mail')
dest_uids = user_obj.search(cr, ROOT_UID, login_cond)
dest_users = user_obj.browse(cr, ROOT_UID, dest_uids)
for dest_user in dest_users:
@@ -184,10 +184,12 @@ class wizard(osv.osv_memory):
email_to = dest_user.email
subject = _(WELCOME_EMAIL_SUBJECT) % data
body = _(WELCOME_EMAIL_BODY) % data
- res = mail_message_obj.schedule_with_attach(cr, uid, email_from , [email_to], subject, body, context=context)
- if not res:
- _logger.warning(
- 'Failed to send email from %s to %s', email_from, email_to)
+ mail_id = mail_mail_obj.create(cr, uid, {
+ 'email_from': email_from ,
+ 'email_to': email_to,
+ 'subject': subject,
+ 'state': 'outgoing',
+ 'body_html': '%s
' % body}, context=context)
return {'type': 'ir.actions.act_window_close'}
From 6bea3b189b549b6f9dd24ab57a9889d7a8ea4e2f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Tue, 4 Sep 2012 18:14:53 +0200
Subject: [PATCH 15/23] [FIX] share: fixed call to schedule_with_attach, as
send_invite_email is now commented. This module will be cleaned in the next
few days, and all invite mechanism is likely to disappear.
scedule_with_attach is therefore commented and not really fixed.
bzr revid: tde@openerp.com-20120904161453-vq8zartows3eggtp
---
addons/share/wizard/share_wizard.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/addons/share/wizard/share_wizard.py b/addons/share/wizard/share_wizard.py
index a0489c9c017..c6b628c395f 100644
--- a/addons/share/wizard/share_wizard.py
+++ b/addons/share/wizard/share_wizard.py
@@ -775,8 +775,8 @@ class share_wizard(osv.TransientModel):
if res_id <= 0:
raise osv.except_osv(_('Record id not found'), _('The share engine has not been able to fetch a record_id for your invitation.'))
self.pool.get(model.model).message_subscribe(cr, uid, [res_id], new_ids + existing_ids, context=context)
- self.send_invite_email(cr, uid, wizard_data, context=context)
- self.send_invite_note(cr, uid, model.model, res_id, wizard_data, context=context)
+ # self.send_invite_email(cr, uid, wizard_data, context=context)
+ # self.send_invite_note(cr, uid, model.model, res_id, wizard_data, context=context)
# CLOSE
# A. Not invite: as before
@@ -820,9 +820,10 @@ class share_wizard(osv.TransientModel):
elif tmp_idx == len(wizard_data.result_line_ids)-2:
body += ' and'
body += '.'
- return self.pool.get(model_name).message_post(cr, uid, [res_id], _('System Notification'), body, context=context)
+ return self.pool.get(model_name).message_post(cr, uid, [res_id], body=body, context=context)
def send_invite_email(self, cr, uid, wizard_data, context=None):
+ # TDE Note: not updated because will disappear
message_obj = self.pool.get('mail.message')
notification_obj = self.pool.get('mail.notification')
user = self.pool.get('res.users').browse(cr, UID_ROOT, uid)
From acd610f039ac75fd94b6cca9bf29bee93f92c2c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Tue, 4 Sep 2012 18:19:56 +0200
Subject: [PATCH 16/23] [FIX] share: fixed second call to schedule_with_attach,
in send_emails. It has been replaced by a mail_mail.create() and
mail_mail.send().
bzr revid: tde@openerp.com-20120904161956-tw1xvl2vghndhif7
---
addons/share/wizard/share_wizard.py | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/addons/share/wizard/share_wizard.py b/addons/share/wizard/share_wizard.py
index c6b628c395f..375c33b1e8c 100644
--- a/addons/share/wizard/share_wizard.py
+++ b/addons/share/wizard/share_wizard.py
@@ -856,13 +856,13 @@ class share_wizard(osv.TransientModel):
def send_emails(self, cr, uid, wizard_data, context=None):
_logger.info('Sending share notifications by email...')
- mail_message = self.pool.get('mail.message')
+ mail_mail = self.pool.get('mail.mail')
user = self.pool.get('res.users').browse(cr, UID_ROOT, uid)
if not user.email:
raise osv.except_osv(_('Email required'), _('The current user must have an email address configured in User Preferences to be able to send outgoing emails.'))
# TODO: also send an HTML version of this mail
- msg_ids = []
+ mail_ids = []
for result_line in wizard_data.result_line_ids:
email_to = result_line.user_id.email
if not email_to:
@@ -885,10 +885,14 @@ class share_wizard(osv.TransientModel):
body += "--\n"
body += _("OpenERP is a powerful and user-friendly suite of Business Applications (CRM, Sales, HR, etc.)\n"
"It is open source and can be found on http://www.openerp.com.")
- msg_ids.append(mail_message.schedule_with_attach(cr, uid, user.email, [email_to], subject, body, model='share.wizard', context=context))
+ mail_ids.append(mail_mail.create(cr, uid, {
+ 'email_from': user.email,
+ 'email_to': email_to,
+ 'subject': subject,
+ 'body_html': '%s
' % body}, context=context))
# force direct delivery, as users expect instant notification
- mail_message.send(cr, uid, msg_ids, context=context)
- _logger.info('%d share notification(s) sent.', len(msg_ids))
+ mail_mail.send(cr, uid, mail_ids, context=context)
+ _logger.info('%d share notification(s) sent.', len(mail_ids))
def onchange_embed_options(self, cr, uid, ids, opt_title, opt_search, context=None):
wizard = self.browse(cr, uid, ids[0], context)
From 62cb85433bb4b5ac44fff1cc79b1ba1b475af2b3 Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 18:21:35 +0200
Subject: [PATCH 17/23] [FIX] base_calendar: attempt to fix deprecated
schedule_with_attach
bzr revid: odo@openerp.com-20120904162135-9a328743y387kuv9
---
addons/base_calendar/base_calendar.py | 31 +++++++++++----------------
1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py
index d560eaacd66..3f6b83bad62 100644
--- a/addons/base_calendar/base_calendar.py
+++ b/addons/base_calendar/base_calendar.py
@@ -471,18 +471,10 @@ property or property parameter."),
def _send_mail(self, cr, uid, ids, mail_to, email_from=tools.config.get('email_from', False), context=None):
"""
Send mail for event invitation to event attendees.
- @param cr: the current row, from the database cursor,
- @param uid: the current user’s ID for security checks,
- @param ids: List of attendee’s IDs.
@param email_from: Email address for user sending the mail
- @param context: A standard dictionary for contextual values
@return: True
"""
- if context is None:
- context = {}
-
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.name
- mail_message = self.pool.get('mail.message')
for att in self.browse(cr, uid, ids, context=context):
sign = att.sent_by_uid and att.sent_by_uid.signature or ''
sign = '
'.join(sign and sign.split('\n') or [])
@@ -508,17 +500,18 @@ property or property parameter."),
}
body = html_invitation % body_vals
if mail_to and email_from:
- attach = self.get_ics_file(cr, uid, res_obj, context=context)
- mail_message.schedule_with_attach(cr, uid,
- email_from,
- mail_to,
- sub,
- body,
- attachments=attach and {'invitation.ics': attach} or None,
- content_subtype='html',
- reply_to=email_from,
- context=context
- )
+ ics_file = self.get_ics_file(cr, uid, res_obj, context=context)
+ vals = {'email_from': email_from,
+ 'email_to': mail_to,
+ 'state': 'outgoing',
+ 'subject': sub,
+ 'body_html': body,
+ 'auto_delete': True}
+ if ics_file:
+ vals['attachment_ids'] = [(0,0,{'name': 'invitation.ics',
+ 'datas_fname': 'invitation.ics',
+ 'datas': str(ics_file).encode('base64')})]
+ self.pool.get('mail.mail').create(cr, uid, vals, context=context)
return True
def onchange_user_id(self, cr, uid, ids, user_id, *args, **argv):
From c85552b472f210a9016eced3289daa525c456ef2 Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 18:21:40 +0200
Subject: [PATCH 18/23] [FIX] typo
bzr revid: odo@openerp.com-20120904162140-g03z16djdvbiqiiz
---
addons/base_action_rule/base_action_rule.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py
index 237788d689a..7e9bbacab13 100644
--- a/addons/base_action_rule/base_action_rule.py
+++ b/addons/base_action_rule/base_action_rule.py
@@ -320,7 +320,8 @@ the rule to mark CC(mail to any other person defined in actions)."),
'subject': '[%d] %s' % (obj.id, tools.ustr(obj.name)),
'body_html': '%s
' % body,
'res_id': obj.id,
- 'model': obj._table
+ 'model': obj._table_name,
+ 'auto_delete': True
}, context=context)
From 81497cdc2f65591f12175922b13bae7eb1b82999 Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 18:36:44 +0200
Subject: [PATCH 19/23] [FIX] base_calendar: attempt to fix deprecated
schedule_with_attach (part2)
bzr revid: odo@openerp.com-20120904163644-b0o4guocm0b7ymob
---
addons/base_calendar/base_calendar.py | 50 +++++++--------------------
1 file changed, 12 insertions(+), 38 deletions(-)
diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py
index 3f6b83bad62..a6d5f6859af 100644
--- a/addons/base_calendar/base_calendar.py
+++ b/addons/base_calendar/base_calendar.py
@@ -805,7 +805,6 @@ class calendar_alarm(osv.osv):
"""
if context is None:
context = {}
- mail_message = self.pool.get('mail.message')
current_datetime = datetime.now()
alarm_ids = self.search(cr, uid, [('state', '!=', 'done')], context=context)
@@ -842,36 +841,10 @@ class calendar_alarm(osv.osv):
else:
re_dates = [alarm.trigger_date]
- for r_date in re_dates:
- ref = alarm.model_id.model + ',' + str(alarm.res_id)
-
- # search for alreay sent requests
- #if request_obj.search(cr, uid, [('trigger_date', '=', r_date), ('ref_doc1', '=', ref)], context=context):
- #continue
-
- # Deactivated because of the removing of res.request
- # TODO: when cleaning calendar module, re-add this in a new mechanism
- #if alarm.action == 'display':
- #value = {
- #'name': alarm.name,
- #'act_from': alarm.user_id.id,
- #'act_to': alarm.user_id.id,
- #'body': alarm.description,
- #'trigger_date': r_date,
- #'ref_doc1': ref
- #}
- #request_id = request_obj.create(cr, uid, value)
- #request_ids = [request_id]
- #for attendee in res_obj.attendee_ids:
- #if attendee.user_id:
- #value['act_to'] = attendee.user_id.id
- #request_id = request_obj.create(cr, uid, value)
- #request_ids.append(request_id)
- #request_obj.request_send(cr, uid, request_ids)
-
+ if re_dates:
if alarm.action == 'email':
- sub = '[Openobject Reminder] %s' % (alarm.name)
- body = """
+ sub = '[OpenERP Reminder] %s' % (alarm.name)
+ body = """
Event: %s
Event Date: %s
Description: %s
@@ -881,20 +854,21 @@ From:
----
%s
-
+
""" % (alarm.name, alarm.trigger_date, alarm.description, \
alarm.user_id.name, alarm.user_id.signature)
mail_to = [alarm.user_id.email]
for att in alarm.attendee_ids:
mail_to.append(att.user_id.email)
if mail_to:
- mail_message.schedule_with_attach(cr, uid,
- tools.config.get('email_from', False),
- mail_to,
- sub,
- body,
- context=context
- )
+ vals = {
+ 'state': 'outgoing',
+ 'subject': sub,
+ 'body_html': body,
+ 'email_to': mail_to,
+ 'email_from': tools.config.get('email_from', mail_to),
+ }
+ self.pool.get('mail.mail').create(cr, uid, vals, context=context)
if next_trigger_date:
update_vals.update({'trigger_date': next_trigger_date})
else:
From d5661c50965ff648fba74b48de47215159406ff3 Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 18:55:53 +0200
Subject: [PATCH 20/23] [FIX] survey: attempt to fix deprecated
schedule_with_attach
bzr revid: odo@openerp.com-20120904165553-nxhbgmkpyk7imp4q
---
.../survey/wizard/survey_send_invitation.py | 26 +++++++++++++++----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/addons/survey/wizard/survey_send_invitation.py b/addons/survey/wizard/survey_send_invitation.py
index da439959ec5..5677a985e09 100644
--- a/addons/survey/wizard/survey_send_invitation.py
+++ b/addons/survey/wizard/survey_send_invitation.py
@@ -116,7 +116,6 @@ class survey_send_invitation(osv.osv_memory):
existing = ""
created = ""
error = ""
- user_exists = False
new_user = []
attachments = {}
current_sur = survey_ref.browse(cr, uid, context.get('active_id'), context=context)
@@ -150,8 +149,14 @@ class survey_send_invitation(osv.osv_memory):
mail = record['mail']%{'login':partner.email, 'passwd':user.password, \
'name' : partner.name}
if record['send_mail_existing']:
- mail_message.schedule_with_attach(cr, uid, record['mail_from'], [partner.email] , \
- record['mail_subject_existing'] , mail, context=context)
+ vals = {
+ 'state': 'outgoing',
+ 'subject': record['mail_subject_existing'],
+ 'body_html': '%s
' % mail,
+ 'email_to': partner.email,
+ 'email_from': record['mail_from'],
+ }
+ self.pool.get('mail.mail').create(cr, uid, vals, context=context)
existing+= "- %s (Login: %s, Password: %s)\n" % (user.name, partner.email, \
user.password)
continue
@@ -160,8 +165,19 @@ class survey_send_invitation(osv.osv_memory):
out+= partner.email + ',' + passwd + '\n'
mail= record['mail'] % {'login' : partner.email, 'passwd' : passwd, 'name' : partner.name}
if record['send_mail']:
- ans = mail_message.schedule_with_attach(cr, uid, record['mail_from'], [partner.email], \
- record['mail_subject'], mail, attachments=attachments, context=context)
+ vals = {
+ 'state': 'outgoing',
+ 'subject': record['mail_subject'],
+ 'body_html': '%s
' % mail,
+ 'email_to': partner.email,
+ 'email_from': record['mail_from'],
+ }
+ if attachments:
+ vals['attachment_ids'] = [(0,0,{'name': a_name,
+ 'datas_fname': a_name,
+ 'datas': str(a_content).encode('base64')})
+ for a_name, a_content in attachments]
+ ans = self.pool.get('mail.mail').create(cr, uid, vals, context=context)
if ans:
res_data = {'name': partner.name or _('Unknown'),
'login': partner.email,
From 622bb963125379c09aaed636c7696b30a5246542 Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 19:03:30 +0200
Subject: [PATCH 21/23] [FIX] survey: attempt to fix deprecated
schedule_with_attach (part2)
bzr revid: odo@openerp.com-20120904170330-nd6rv6jaiofb2hw3
---
addons/survey/wizard/survey_answer.py | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py
index 66098b45fa8..e2216ea8389 100644
--- a/addons/survey/wizard/survey_answer.py
+++ b/addons/survey/wizard/survey_answer.py
@@ -420,7 +420,17 @@ class survey_question_wiz(osv.osv_memory):
if user_email and resp_email:
user_name = user_obj.browse(cr, uid, uid, context=context).name
mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(user_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks."
- mail_message.schedule_with_attach(cr, uid, user_email, [resp_email], "Survey Answer Of " + str(user_name) , mail, attachments=attachments, context=context)
+ vals = {'state': 'outgoing',
+ 'subject': "Survey Answer Of " + user_name,
+ 'body_html': '%s
' % mail,
+ 'email_to': [resp_email],
+ 'email_from': user_email}
+ if attachments:
+ vals['attachment_ids'] = [(0,0,{'name': a_name,
+ 'datas_fname': a_name,
+ 'datas': str(a_content).encode('base64')})
+ for a_name, a_content in attachments]
+ self.pool.get('mail.mail').create(cr, uid, vals, context=context)
xml_form = etree.Element('form', {'string': _('Complete Survey Answer')})
etree.SubElement(xml_form, 'separator', {'string': 'Complete Survey', 'colspan': "4"})
From b9fd1cae1448af71bb3c93a1b5412e1b2c39ff5c Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 19:08:49 +0200
Subject: [PATCH 22/23] [FIX] hr_evaluation: attempt to fix deprecated
schedule_with_attach
bzr revid: odo@openerp.com-20120904170849-w4xdfuykz6ycor8v
---
addons/hr_evaluation/hr_evaluation.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/addons/hr_evaluation/hr_evaluation.py b/addons/hr_evaluation/hr_evaluation.py
index def21f2b169..3508dc36d49 100644
--- a/addons/hr_evaluation/hr_evaluation.py
+++ b/addons/hr_evaluation/hr_evaluation.py
@@ -228,9 +228,13 @@ class hr_evaluation(osv.osv):
body = phase.mail_body % {'employee_name': child.name, 'user_signature': child.user_id.signature,
'eval_name': phase.survey_id.title, 'date': time.strftime('%Y-%m-%d'), 'time': time }
sub = phase.email_subject
- dest = [child.work_email]
- if dest:
- mail_message.schedule_with_attach(cr, uid, evaluation.employee_id.work_email, dest, sub, body, context=context)
+ if child.work_email:
+ vals = {'state': 'outgoing',
+ 'subject': sub,
+ 'body_html': '%s
' % body,
+ 'email_to': child.work_email,
+ 'email_from': evaluation.employee_id.work_email}
+ self.pool.get('mail.mail').create(cr, uid, vals, context=context)
self.write(cr, uid, ids, {'state':'wait'}, context=context)
return True
From 5e1da73b29e076c0bfe9c2740df56a68c6cd987d Mon Sep 17 00:00:00 2001
From: Olivier Dony
Date: Tue, 4 Sep 2012 19:16:29 +0200
Subject: [PATCH 23/23] [FIX] account_followup: attempt to fix deprecated
schedule_with_attach
bzr revid: odo@openerp.com-20120904171629-kdo7erx35cfsty2y
---
.../account_followup/wizard/account_followup_print.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py
index d151d2171a4..2b573fe0275 100644
--- a/addons/account_followup/wizard/account_followup_print.py
+++ b/addons/account_followup/wizard/account_followup_print.py
@@ -213,8 +213,6 @@ class account_followup_print_all(osv.osv_memory):
mod_obj = self.pool.get('ir.model.data')
move_obj = self.pool.get('account.move.line')
user_obj = self.pool.get('res.users')
- line_obj = self.pool.get('account_followup.stat')
- mail_message = self.pool.get('mail.message')
if context is None:
context = {}
@@ -241,7 +239,6 @@ class account_followup_print_all(osv.osv_memory):
if (not dest) and partner.type=='default':
if partner.email:
dest = [partner.email]
- src = tools.config.options['email_from']
if not data.partner_lang:
body = data.email_body
else:
@@ -281,7 +278,12 @@ class account_followup_print_all(osv.osv_memory):
msg = ''
if dest:
try:
- mail_message.schedule_with_attach(cr, uid, src, dest, sub, body, context=context)
+ vals = {'state': 'outgoing',
+ 'subject': sub,
+ 'body_html': '%s
' % body,
+ 'email_to': dest,
+ 'email_from': data_user.email or tools.config.options['email_from']}
+ self.pool.get('mail.mail').create(cr, uid, vals, context=context)
msg_sent += partner.name + '\n'
except Exception, e:
raise osv.except_osv('Error !', e )