summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjem-odoo <jem@openerp.com>2018-06-26 11:19:46 +0200
committerjem-odoo <jem@openerp.com>2018-08-10 16:30:19 +0200
commitfa5a50e86cb3b0133311541d080b253c3048274b (patch)
treed9cd477bb9e136dbbb8b90cd435f9eda75dd7d43
parent80ef7146d21eb5763336fc11b0ad964910be4730 (diff)
[IMP] mail: activity schedule with view
This commit extends the activity API to allow scheduling activity with a Qweb template to format the activity message. Task #39340
-rw-r--r--addons/mail/models/mail_activity.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py
index 4f760baad73..27b95c43eda 100644
--- a/addons/mail/models/mail_activity.py
+++ b/addons/mail/models/mail_activity.py
@@ -8,6 +8,8 @@ import pytz
from odoo import api, exceptions, fields, models, _
+from odoo.tools import pycompat
+
class MailActivityType(models.Model):
""" Activity Types are used to categorize activities. Each type is a different
@@ -188,7 +190,7 @@ class MailActivity(models.Model):
def _compute_has_recommended_activities(self):
for record in self:
record.has_recommended_activities = bool(record.previous_activity_type_id.next_type_ids)
-
+
@api.multi
@api.onchange('previous_activity_type_id')
def _onchange_previous_activity_type_id(self):
@@ -602,6 +604,33 @@ class MailActivityMixin(models.AbstractModel):
activities |= self.env['mail.activity'].create(create_vals)
return activities
+ def activity_schedule_with_view(self, act_type_xmlid='', date_deadline=None, summary='', views_or_xmlid='', render_context=None, **act_values):
+ """ Helper method: Schedule an activity on each record of the current record set.
+ This method allow to the same mecanism as `activity_schedule`, but provide
+ 2 additionnal parameters:
+ :param views_or_xmlid: record of ir.ui.view or string representing the xmlid
+ of the qweb template to render
+ :type views_or_xmlid: string or recordset
+ :param render_context: the values required to render the given qweb template
+ :type render_context: dict
+ """
+ if self.env.context.get('mail_activity_automation_skip'):
+ return False
+
+ render_context = render_context or dict()
+ if isinstance(views_or_xmlid, pycompat.string_types):
+ views = self.env.ref(views_or_xmlid, raise_if_not_found=False)
+ else:
+ views = views_or_xmlid
+ if not views:
+ return
+ activities = self.env['mail.activity']
+ for record in self:
+ render_context['object'] = record
+ note = views.render(render_context, engine='ir.qweb', minimal_qcontext=True)
+ activities |= record.activity_schedule(act_type_xmlid=act_type_xmlid, date_deadline=date_deadline, summary=summary, note=note, **act_values)
+ return activities
+
def activity_reschedule(self, act_type_xmlids, user_id=None, date_deadline=None, new_user_id=None):
""" Reschedule some automated activities. Activities to reschedule are
selected based on type xml ids and optionally by user. Purpose is to be