<?xml version="1.0"?>
<form string="Server Action">
                    <header>
                        <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>
                        <h1 class="oe_title">
                            <field name="name" placeholder="e.g. Mass archive contacts"/>
                        </h1>
                        <div class="d-flex flex-column">
                            <label for="state"/>
                            <field name="state" widget="selection_badge" options="{'size': 'sm'}"/>
                        </div>
                        <group string="Technical Settings" groups="base.group_no_one">
                            <group>
                                <field name="model_id" options="{'no_create': True, 'no_open': True}"/>
                                <field name="groups_id" widget="many2many_tags"/>
                            </group>
                        </group>
                        <separator string="Action Details" groups="base.group_no_one"/>
                        <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="DynamicModelFieldSelectorChar" class="oe_inline" options="{'model': 'model_name'}" required="state == 'object_write'"/>
                            <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>
                            <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="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 == 'equation'" class="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 name="action_wrapper">
                            <group name="action_content">
                                <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)]"/>

                                <field name="crud_model_id" options="{'no_create': True, 'no_open': True}" invisible="state != 'object_create'" required="state == 'object_create'"/>
                                <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="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}" invisible="state != 'object_create'" context="{'default_model_id': model_id, 'default_relation': crud_model_name}"/>
                                    <field name="webhook_url" string="URL" invisible="state != 'webhook'" placeholder="e.g. https://maker.ifttt.com/use/..."/>
                                    <field name="webhook_field_ids" string="Fields" invisible="state != 'webhook'" widget="many2many_tags" context="{'hide_model': 1}" domain="[('model_id', '=', model_id)]" placeholder="Select fields to include in the request..."/>
                                </group>
                                <group invisible="state != 'webhook'">
                                    <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>
                        <field name="child_ids" domain="[('model_id', '=', model_id)]" invisible="state != 'multi'"/>
                        <p class="oe_grey" invisible="state != 'multi'">
                            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.
                        </p>
                        <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>
                    </sheet>
                </form>
            