[FIX] mail: execute only once when setting automated actions at record update

Fine-tuning of commit: d60f2ab0e2
Which applied when the next action was to create a new activity.
However the problem is also present when the next action is to send an email.
We extract the logic in a new private function to share the code in both cases.

opw 1904156

closes odoo/odoo#28819
This commit is contained in:
len-odoo
2018-11-19 19:36:14 +00:00
parent 180de24df0
commit 24ca67b545
+20 -12
View File
@@ -76,10 +76,28 @@ class ServerActions(models.Model):
records.message_subscribe(self.partner_ids.ids, self.channel_ids.ids)
return False
@api.model
def _is_recompute(self, action):
"""When an activity is set on update of a record,
update might be triggered many times by recomputes.
When need to know it to skip these steps."""
records = self.env[action.model_id.model].browse(
self._context.get('active_ids', self._context.get('active_id')))
old_values = action._context.get('old_values')
if old_values:
field_names = list(old_values[records[0].id])
field = records._fields[field_names[0]]
# Pick an arbitrary field; if it is marked to be recomputed,
# it means we are in an extraneous write triggered by the recompute.
# In this case, we should not create a new activity.
if records._recompute_check(field):
return True
return False
@api.model
def run_action_email(self, action, eval_context=None):
# TDE CLEANME: when going to new api with server action, remove action
if not action.template_id or not self._context.get('active_id'):
if not action.template_id or not self._context.get('active_id') or self._is_recompute(action):
return False
# Clean context from default_type to avoid making attachment
# with wrong values in subsequent operations
@@ -90,21 +108,11 @@ class ServerActions(models.Model):
@api.model
def run_action_next_activity(self, action, eval_context=None):
if not action.activity_type_id or not self._context.get('active_id'):
if not action.activity_type_id or not self._context.get('active_id') or self._is_recompute(action):
return False
records = self.env[action.model_id.model].browse(self._context.get('active_ids', self._context.get('active_id')))
old_values = action._context.get('old_values')
if old_values:
field_names = list(old_values[records[0].id])
field = records._fields[field_names[0]]
# Pick an arbitrary field; if it is marked to be recomputed,
# it means we are in an extraneous write triggered by the recompute.
# In this case, we should not create a new activity.
if records._recompute_check(field):
return False
vals = {
'summary': action.activity_summary or '',
'note': action.activity_note or '',