<?xml version="1.0"?>
<form string="Server Action">
                    <header invisible="context.get('is_modal')">
                        <button name="create_action" string="Create Contextual Action" type="object" class="btn-primary" invisible="binding_model_id" help="Display an option in the 'More' top-menu in order to run this action."/>
                        <button name="unlink_action" string="Remove Contextual Action" type="object" invisible="not binding_model_id" help="Remove 'More' top-menu contextual action related to this action"/>
                        <button name="run" string="Run" type="object" class="btn-primary" invisible="model_name != 'ir.actions.server' or state != 'code'" help="Run this action manually."/>
                    </header>
                    <sheet>
                        <div class="oe_button_box" name="button_box">
                            <button type="object" name="action_open_parent_action" invisible="not parent_id" class="oe_stat_button" icon="fa-database">
                                <div class="o_stat_info">
                                    <span class="o_stat_text">Parent Action</span>
                                </div>
                            </button>
                            <button type="object" name="action_open_scheduled_action" invisible="not ir_cron_ids or context.key != 'server_action'" context="{'key': 'ir_cron'}" class="oe_stat_button" icon="fa-refresh">
                                <div class="o_stat_info">
                                    <span class="o_stat_text">Scheduled Action</span>
                                </div>
                            </button>
                        </div>
                        <h1 class="oe_title">
                            <field name="automated_name" invisible="1"/> <!-- needed for name compute -->
                            <field name="name" placeholder="Set an explicit name"/>
                        </h1>
                        <group invisible="context.get('is_modal')">
                            <group>
                                <field name="model_id" options="{'no_create': True, 'no_open': True}" groups="base.group_no_one"/>
                                <field name="model_id" options="{'no_create': True, 'no_open': True}" groups="!base.group_no_one" invisible="context.get('default_model_id')" domain="[('id', 'in', available_model_ids)]"/>
                            </group>
                            <group groups="base.group_no_one">
                                <field name="group_ids" widget="many2many_tags"/>
                            </group>
                        </group>
                        <t name="action_content" invisible="not model_id">
                            <field name="allowed_states" invisible="1"/> <!-- Used to filter state using selection_badge_with_filter -->
                            <div class="d-flex flex-column">
                                <label for="state"/>
                                <field name="state" widget="selection_badge_with_filter" options="{'size': 'sm', 'allowed_selection_field': 'allowed_states'}"/>
                            </div>
                            <div class="alert alert-warning" role="alert" invisible="not warning">
                                <i class="fa fa-warning pe-2" title="Warning"/><field class="d-inline" name="warning" nolabel="1"/>
                            </div>
                            <div class="d-flex flex-row flex-wrap gap-2" invisible="state != 'object_write'">
                                <field name="evaluation_type" class="oe_inline"/>
                                <field name="update_path" widget="field_selector" class="oe_inline" options="{'model': 'model_name'}"/>
                                <field name="update_field_id" invisible="True"/>  <!-- The field is store=True and readonly=False, in this view we want to save the value from compute/onchange -->
                                <field name="update_related_model_id" invisible="True"/> <!-- This field is required for 'resource_ref' to compute possible m2m and m2o values -->
                                <span invisible="evaluation_type != 'value' or update_field_type not in ['one2many', 'many2many']">by</span>
                                <field name="update_m2m_operation" class="oe_inline" invisible="evaluation_type != 'value' or update_field_type not in ['one2many', 'many2many']" required="update_field_type in ['one2many', 'many2many']"/>
                                <span invisible="evaluation_type != 'value' or update_field_type in ['one2many', 'many2many']">to</span>
                                <span invisible="evaluation_type != 'sequence'">with</span>
                                <field name="value" class="oe_inline" placeholder="Set a value..." invisible="update_field_id == False or value_field_to_show != 'value' or evaluation_type != 'value'" string="Custom Value"/>
                                <field name="html_value" class="w-100" placeholder="Set a value..." invisible="update_field_id == False or value_field_to_show != 'html_value' or evaluation_type != 'value'" string="Custom Value"/>
                                <field name="sequence_id" class="oe_inline" placeholder="Select a sequence..." invisible="evaluation_type != 'sequence'" required="evaluation_type == 'sequence'"/>
                                <field name="resource_ref" class="oe_inline" placeholder="Choose a value..." string="Custom Value" options="{'model_field': 'update_related_model_id', 'no_create': True, 'no_open': True}" invisible="update_field_id == False or value_field_to_show != 'resource_ref' or evaluation_type == 'equation' or update_m2m_operation == 'clear'"/>
                                <field name="selection_value" class="oe_inline" placeholder="Choose a value..." options="{'no_create': True, 'no_open': True}" invisible="update_field_id == False or value_field_to_show != 'selection_value' or evaluation_type == 'equation'"/>
                                <field name="update_boolean_value" class="oe_inline" invisible="evaluation_type != 'value' or value_field_to_show != 'update_boolean_value'" required="value_field_to_show == 'update_boolean_value'"/>
                                <span invisible="update_field_id != False or evaluation_type != 'value'" class="o_actions_server_set_a_value text-muted">Set a value...</span>
                                <span invisible="evaluation_type != 'equation'">
                                    to this Python expression:
                                </span>
                                <div class="w-100 d-flex flex-row gap-3" invisible="evaluation_type != 'equation'">
                                    <field name="value" class="w-50" widget="code" options="{'mode': 'python'}" string="Expression"/>
                                    <div class="w-50 opacity-75">
                                        <span colspan="2" class="text-muted"> Available variables: </span>
                                            <ul colspan="2" class="text-muted">
                                                <li><code>env</code>: environment on which the action is triggered</li>
                                                <li><code>model</code>: model of the record on which the action is triggered; is a void recordset</li>
                                                <li><code>record</code>: record on which the action is triggered</li>
                                                <li><code>records</code>: recordset of all records on which the action is triggered in multi mode</li>
                                                <li><code>time</code>, <code>datetime</code>, <code>dateutil</code>, <code>timezone</code>: useful Python libraries</li>
                                                <li><code>float_compare()</code>: utility function to compare floats based on a specific precision</li>
                                            </ul>
                                    </div>
                                </div>
                            </div>
                            <group invisible="state not in ['object_create', 'object_copy']">
                                <group>
                                    <field name="crud_model_id" options="{'no_create': True, 'no_open': True}" required="state in ['object_create', 'object_copy']"/>
                                    <field name="value" widget="char" string="Name" invisible="state != 'object_create'" help="The name of the record to create" placeholder="e.g. Follow-up"/>
                                    <field name="resource_ref" placeholder="Choose a record..." string="Duplicate from" options="{'model_field': 'crud_model_id', 'no_create': True, 'no_open': True}" invisible="crud_model_id == False or state != 'object_copy'" required="state == 'object_copy'"/>
                                    <field name="link_field_id" domain="[('model_id', '=', model_id), ('relation', '=', crud_model_name),                                         ('ttype', 'in', ['many2one', 'one2many', 'many2many'])]" placeholder="Select a field to link the record to" options="{'no_create': True, 'no_open': True}" context="{'default_model_id': model_id, 'default_relation': crud_model_name}"/>
                                </group>
                            </group>
                            <group invisible="state != 'webhook'">
                                <group>
                                    <field name="webhook_url" string="URL" placeholder="e.g. https://maker.ifttt.com/use/..."/>
                                    <field name="webhook_field_ids" string="Fields" widget="many2many_tags" context="{'hide_model': 1}" domain="[('model_id', '=', model_id)]" placeholder="Select fields to include in the request..."/>
                                </group>
                                <group>
                                    <label for="webhook_sample_payload"/>
                                    <field name="webhook_sample_payload" string="Sample Payload" nolabel="1" colspan="2" readonly="1" widget="code" options="{'mode': 'javascript'}"/>
                                </group>
                            </group>
                            <t invisible="state != 'multi'">
                                <field name="child_ids" widget="many2many" mode="kanban" context="{                                     'is_modal': 1,                                     'default_model_id': model_id,                                 }"/>
                                <p class="opacity-50 mb-1 mt-3 mt-md-n2 mt-lg-0">
                                    If several actions return an action, only the last one will be executed.
                                </p>
                            </t>
                            <notebook invisible="state != 'code'">
                                <page string="Code">
                                    <field name="code" invisible="state != 'code'" widget="code" options="{'mode': 'python'}" placeholder="Enter Python code here. Help about Python expression is available in the help tab of this document."/>
                                </page>
                                <page string="Help">
                                    <p>The following variables can be used:</p>
                                    <ul>
                                        <li><code>env</code>: environment on which the action is triggered</li>
                                        <li><code>model</code>: model of the record on which the action is triggered; is a void recordset</li>
                                        <li><code>record</code>: record on which the action is triggered; may be be void</li>
                                        <li><code>records</code>: recordset of all records on which the action is triggered in multi mode; may be void</li>
                                        <li><code>time</code>, <code>datetime</code>, <code>dateutil</code>, <code>timezone</code>: useful Python libraries</li>
                                        <li><code>float_compare()</code>: utility function to compare floats based on a specific precision</li>
                                        <li><code>log(message, level='info')</code>: logging function to record debug information in <code>ir.logging</code> table</li>
                                        <li><code>_logger.info(message)</code>: logger to emit messages in server logs</li>
                                        <li><code>UserError</code>: exception class for raising user-facing warning messages</li>
                                        <li><code>Command</code>: x2many commands namespace</li>
                                        <li>To return an action, assign: <code>action = {...}</code></li>
                                        <li>To notify progress for CRON call and re-trigger a call if there is remaining tasks, use <code>env['ir.cron']._notify_progress(done=task_done_count, remaining=task_remaining_count)</code></li>
                                    </ul>
                                    <div>
                                        <p>Example of Python code:</p>
                                        <pre style="white-space: pre-wrap">partner_name = record.name + '_code'
env['res.partner'].create({'name': partner_name})
    </pre>
                                    </div>
                                </page>
                            </notebook>
                        </t>
                    </sheet>
                </form>
            