[FIX] base, mail, sms: fix server actions naming computation
Fix name compute method: * correctly call super in batch; * correctly filter records; * remove dependency on context key (which was missing in triggers); In this commit we also consider the name update should always be done even outside of automated rules context. Having a whole compute method relying on a context key does not makes sense. As server actions are technical records, having the name always being correctly updated is better. Task-3527758 (Base Automation Refactor Fiximp) Part of Task-3527752 (Mail: The Pre-Major Freeze FixImpLint) Part-of: odoo/odoo#137133
This commit is contained in:
@@ -88,7 +88,7 @@
|
||||
name="action_server_ids"
|
||||
widget="one2many"
|
||||
class="o_base_automation_actions_field"
|
||||
context="{'default_model_id': model_id, 'default_state': False, 'automatic_action_name': True, 'form_view_ref': 'base_automation.view_server_action_form'}"
|
||||
context="{'default_model_id': model_id, 'default_state': False, 'form_view_ref': 'base_automation.view_server_action_form'}"
|
||||
>
|
||||
<kanban>
|
||||
<control>
|
||||
|
||||
@@ -79,11 +79,12 @@ class ServerActions(models.Model):
|
||||
compute='_compute_activity_info', readonly=False, store=True)
|
||||
|
||||
|
||||
@api.depends('state', 'template_id', 'partner_ids', 'activity_summary')
|
||||
@api.depends('template_id', 'partner_ids', 'activity_summary')
|
||||
def _compute_name(self):
|
||||
for action in self:
|
||||
if not action.state or not self.env.context.get('automatic_action_name'):
|
||||
continue
|
||||
to_update = self.filtered(
|
||||
lambda action: action.state in {'mail_post', 'followers', 'remove_followers', 'next_activity'}
|
||||
)
|
||||
for action in to_update:
|
||||
if action.state == 'mail_post':
|
||||
action.name = _(
|
||||
'Send email: %(template_name)s',
|
||||
@@ -104,8 +105,7 @@ class ServerActions(models.Model):
|
||||
'Next activity: %(activity_name)s',
|
||||
activity_name=action.activity_summary or action.activit_type_id.name
|
||||
)
|
||||
else:
|
||||
super(ServerActions, action)._compute_name()
|
||||
super(ServerActions, self - to_update)._compute_name()
|
||||
|
||||
@api.depends('model_id', 'state')
|
||||
def _compute_template_id(self):
|
||||
|
||||
@@ -26,18 +26,15 @@ class ServerActions(models.Model):
|
||||
compute='_compute_sms_method',
|
||||
readonly=False, store=True)
|
||||
|
||||
@api.depends('state', 'sms_template_id')
|
||||
@api.depends('sms_template_id')
|
||||
def _compute_name(self):
|
||||
for action in self:
|
||||
if not action.state or not self.env.context.get('automatic_action_name'):
|
||||
continue
|
||||
if action.state == 'sms':
|
||||
action.name = _(
|
||||
'Send SMS: %(template_name)s',
|
||||
template_name=action.sms_template_id.name
|
||||
)
|
||||
else:
|
||||
super(ServerActions, action)._compute_name()
|
||||
to_update = self.filtered(lambda action: action.state == 'sms')
|
||||
for action in to_update:
|
||||
action.name = _(
|
||||
'Send SMS: %(template_name)s',
|
||||
template_name=action.sms_template_id.name
|
||||
)
|
||||
super(ServerActions, self - to_update)._compute_name()
|
||||
|
||||
@api.depends('model_id', 'state')
|
||||
def _compute_sms_template_id(self):
|
||||
|
||||
@@ -533,16 +533,20 @@ class IrActionsServer(models.Model):
|
||||
|
||||
@api.depends('state', 'update_field_id', 'crud_model_id', 'value')
|
||||
def _compute_name(self):
|
||||
for action in self:
|
||||
if not action.state or not self.env.context.get('automatic_action_name'):
|
||||
continue
|
||||
for action in self.filtered('state'):
|
||||
if action.state == 'object_write':
|
||||
action.name = _("Update %s", action.update_field_id.field_description)
|
||||
action.name = _(
|
||||
"Update %(field_name)s",
|
||||
field_name=action.update_field_id.field_description
|
||||
)
|
||||
elif action.state == 'object_create':
|
||||
action.name = _("Create %s with name %s", action.crud_model_id.name, action.value)
|
||||
action.name = _(
|
||||
"Create %(model_name)s with name %(value)s",
|
||||
model_name=action.crud_model_id.name,
|
||||
value=action.value
|
||||
)
|
||||
else:
|
||||
state_name = dict(action._fields['state']._description_selection(self.env))[action.state]
|
||||
action.name = state_name
|
||||
action.name = dict(action._fields['state']._description_selection(self.env))[action.state]
|
||||
|
||||
@api.onchange('model_id')
|
||||
def _compute_crud_model_id(self):
|
||||
|
||||
Reference in New Issue
Block a user