From 24ca67b54550126013e96f0dc59f0240b6421d76 Mon Sep 17 00:00:00 2001 From: len-odoo Date: Mon, 19 Nov 2018 15:32:03 +0000 Subject: [PATCH] [FIX] mail: execute only once when setting automated actions at record update Fine-tuning of commit: d60f2ab0e26f5918a713cbe5abfc8f20f7d8ddb1 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 --- addons/mail/models/ir_actions.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/addons/mail/models/ir_actions.py b/addons/mail/models/ir_actions.py index b15b77f3ed9..bfecd028152 100644 --- a/addons/mail/models/ir_actions.py +++ b/addons/mail/models/ir_actions.py @@ -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 '',