From 7be6d6e3214e3d5be2b3085ec4b3b8cc2fd228e2 Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Tue, 3 Oct 2023 16:24:33 +0200 Subject: [PATCH] [IMP] base: rework the ir.actions.server views - inline configuration/display for 'update record' action type - don't use notebook when there's a single page that gets displayed - remove default field when updating a record Task-3450200 Part-of: odoo/odoo#138804 --- .../views/base_automation_views.xml | 2 +- odoo/addons/base/models/ir_actions.py | 25 +--- odoo/addons/base/views/ir_actions_views.xml | 135 +++++++++--------- 3 files changed, 73 insertions(+), 89 deletions(-) diff --git a/addons/base_automation/views/base_automation_views.xml b/addons/base_automation/views/base_automation_views.xml index b85851dd942..e60675869d2 100644 --- a/addons/base_automation/views/base_automation_views.xml +++ b/addons/base_automation/views/base_automation_views.xml @@ -122,7 +122,7 @@ name="action_server_ids" widget="one2many" class="o_base_automation_actions_field" - context="{'default_model_id': model_id, 'default_state': False, 'form_view_ref': 'base_automation.ir_actions_server_view_form_automation'}" + context="{'default_model_id': model_id, 'form_view_ref': 'base_automation.ir_actions_server_view_form_automation'}" > diff --git a/odoo/addons/base/models/ir_actions.py b/odoo/addons/base/models/ir_actions.py index 79caeb6fdc9..87bd638ed68 100644 --- a/odoo/addons/base/models/ir_actions.py +++ b/odoo/addons/base/models/ir_actions.py @@ -439,25 +439,6 @@ class IrActionsServer(models.Model): # - Command: x2many commands namespace # To return an action, assign: action = {...}\n\n\n\n""" - @api.model - def _default_update_field_id(self): - if self.model_id: - model_id = self.model_id.id - elif 'default_model_id' in self.env.context: - model_id = self.env.context['default_model_id'] - else: - return False - - ir_model = self.env["ir.model"].browse(model_id) - if ir_model: - fields = self.env[ir_model.model]._fields - if 'state' in fields: - return ir_model.field_id.filtered(lambda ir_field: ir_field.name == 'state') - elif 'stage_id' in fields: - return ir_model.field_id.filtered(lambda ir_field: ir_field.name == 'stage_id') - elif 'priority' in fields: - return ir_model.field_id.filtered(lambda ir_field: ir_field.name == 'priority') - name = fields.Char(compute='_compute_name', store=True, readonly=False, required=True) type = fields.Char(default='ir.actions.server') usage = fields.Selection([ @@ -508,7 +489,7 @@ class IrActionsServer(models.Model): groups_id = fields.Many2many('res.groups', 'ir_act_server_group_rel', 'act_id', 'gid', string='Allowed Groups', help='Groups that can execute the server action. Leave empty to allow everybody.') - update_field_id = fields.Many2one('ir.model.fields', string='Field to Update', default=_default_update_field_id, ondelete='cascade') + update_field_id = fields.Many2one('ir.model.fields', string='Field to Update', ondelete='cascade') update_related_model_id = fields.Many2one('ir.model', compute='_compute_update_related_model_id') value = fields.Text(help="For Python expressions, this field may hold a Python expression " @@ -518,8 +499,8 @@ class IrActionsServer(models.Model): "For Static values, the value will be used directly without evaluation, e.g." "`42` or `My custom name` or the selected record.") evaluation_type = fields.Selection([ - ('value', 'Custom Value'), - ('equation', 'Python expression') + ('value', 'Update'), + ('equation', 'Compute') ], 'Value Type', default='value', change_default=True) resource_ref = fields.Reference( string='Record', selection='_selection_target_model', inverse='_set_resource_ref') diff --git a/odoo/addons/base/views/ir_actions_views.xml b/odoo/addons/base/views/ir_actions_views.xml index 18a8d523b7d..161134f9281 100644 --- a/odoo/addons/base/views/ir_actions_views.xml +++ b/odoo/addons/base/views/ir_actions_views.xml @@ -331,27 +331,52 @@
+ + + + + + + +
+ + + + + to + + + + Set a value... + + to this Python expression: + +
+ +
+ Available variables: +
    +
  • env: environment on which the action is triggered
  • +
  • model: model of the record on which the action is triggered; is a void recordset
  • +
  • record: record on which the action is triggered
  • +
  • records: recordset of all records on which the action is triggered in multi mode
  • +
  • time, datetime, dateutil, timezone: useful Python libraries
  • +
  • float_compare(): utility function to compare floats based on a specific precision
  • +
+
+
- - - - domain="['|', ('model_id', '=', crud_model_id), ('model_id', '=', model_id)]"/> - - - - - - - - - Available variables: -
    -
  • env: environment on which the action is triggered
  • -
  • model: model of the record on which the action is triggered; is a void recordset
  • -
  • record: record on which the action is triggered
  • -
  • records: recordset of all records on which the action is triggered in multi mode
  • -
  • time, datetime, dateutil, timezone: useful Python libraries
  • -
  • float_compare(): utility function to compare floats based on a specific precision
  • -
-
- - - - - - - -

- If several child actions return an action, only the last one will be executed. - This may happen when having server actions executing code that returns an action, or server actions returning a client action. -

-
- - -
-

Help with Python expressions

-

Various fields may use Python code or Python expressions. The following variables can be used:

-
    -
  • env: environment on which the action is triggered
  • -
  • model: model of the record on which the action is triggered; is a void recordset
  • -
  • record: record on which the action is triggered; may be be void
  • -
  • records: recordset of all records on which the action is triggered in multi mode; may be void
  • -
  • time, datetime, dateutil, timezone: useful Python libraries
  • -
  • float_compare(): utility function to compare floats based on a specific precision
  • -
  • log(message, level='info'): logging function to record debug information in ir.logging table
  • -
  • _logger.info(message): logger to emit messages in server logs
  • -
  • UserError: exception class for raising user-facing warning messages
  • -
  • Command: x2many commands namespace
  • -
  • To return an action, assign: action = {...}
  • -
-
-

Example of Python code

-
-partner_name = record.name + '_code'
+                        
+                        

+ If several child actions return an action, only the last one will be executed. + This may happen when having server actions executing code that returns an action, or server actions returning a client action. +

+
- - +
+