<odoo>
  <data>

    <record id="config_form" model="ir.ui.view">
        <field name="model">runbot.build.config</field>
        <field name="arch" type="xml">
            <form string="Build config">
                <sheet>
                    <div invisible="not protected">
                        <i class="fa fa-warning text-warning"/>This record is protected and can only be edited by config administrator.
                    </div>
                    <group>
                        <field name="name"/>
                        <field name="description"/>
                        <field name="step_order_ids">
                            <list string="Step list" editable="bottom">
                                <field name="step_id" widget="Many2one" options="{'no_edit': 1}"/>
                                <field name="sequence" widget="handle"/>
                            </list>
                        </field>
                        <field name="protected"/>
                        <field name="group" groups="base.group_no_one"/>
                    </group>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

     <record id="config_step_form" model="ir.ui.view">
        <field name="model">runbot.build.config.step</field>
        <field name="arch" type="xml">
            <form string="Build config step">
                <sheet>
                    <div class="label label-warning" invisible="not protected">
                        This record is protected and can only be edited by config administrator.
                    </div>
                    <group string="General settings">
                        <field name="name"/>
                        <field name="description"/>
                        <field name="domain_filter"/>
                        <field name="job_type"/>
                        <field name="make_stats"/>
                        <field name="protected"/>
                        <field name="default_sequence" groups="base.group_no_one"/>
                        <field name="group" groups="base.group_no_one"/>
                        <field name="break_after_if_ko"/>
                        <field name="break_before_if_ko"/>
                    </group>
                    <group string="Stats regexes" invisible="not make_stats">
                      <field name="build_stat_regex_ids">
                          <list string="Regexes" editable="bottom">
                              <field name="name"/>
                              <field name="regex"/>
                              <field name="description"/>
                          </list>
                      </field>
                    </group>
                    <group string="Python settings" invisible="job_type not in 'python'">
                        <field name="python_code" widget="ace" options="{'mode': 'python'}"/>
                        <field name="python_result_code" widget="ace" options="{'mode': 'python'}"/>
                        <field name="running_job"/>
                    </group>
                    <group string="Test settings" invisible="job_type not in ('python', 'install_odoo')">
                        <field name="create_db" groups="base.group_no_one"/>
                        <field name="install_modules"/>
                        <field name="demo_mode"/>
                        <field name="db_name" groups="base.group_no_one"/>
                        <field name="cpu_limit" groups="base.group_no_one"/>
                        <field name="container_cpus" groups="base.group_no_one"/>
                        <field name="coverage"/>
                        <field name="paths_to_omit" invisible="not coverage"/>
                        <field name="test_enable"/>
                        <field name="test_tags"/>
                        <field name="enable_auto_tags"/>
                        <field name="sub_command"/>
                    </group>
                    <group string="Extra Parameters" invisible="job_type not in ('python', 'install_odoo', 'test_upgrade', 'run_odoo')">
                        <field name="extra_params"/>
                        <field name="additionnal_env"/>
                        <field name="enable_log_db"/>
                    </group>
                    <group string="Create settings" invisible="job_type not in ('python', 'create_build')">
                        <field name="create_config_ids" widget="many2many_tags" options="{'no_create': True}" />
                        <field name="number_builds"/>
                        <field name="make_orphan"/>
                    </group>
                    <group invisible="job_type not in ('python', 'configure_upgrade')">
                      <group class="col" string="Target version settings">
                        <field string="Current" name="upgrade_to_current"/>
                        <field string="Master" name="upgrade_to_master"/>
                        <field string="Major" name="upgrade_to_major_versions"/>
                        <field string="All saas" name="upgrade_to_all_versions"/>
                        <field string="Explicit list" name="upgrade_to_version_ids" widget="many2many_tags"/>
                      </group>
                      <group class="col" string="Source version settings">
                        <field string="Major" name="upgrade_from_previous_major_version"/>
                        <field string="Last saas" name="upgrade_from_last_intermediate_version"/>
                        <field string="All saas" name="upgrade_from_all_intermediate_version"/>
                        <field string="Explicit list" name="upgrade_from_version_ids" widget="many2many_tags"/>
                      </group>
                      <group string="Upgrade settings" class="o_group_col_12">
                        <field name="upgrade_flat"/>
                        <field name="upgrade_config_id"/>
                        <field string="Db to upgrade" name="upgrade_dbs">
                          <list editable="bottom">
                              <field name="config_id"/>
                              <field name="db_pattern"/>
                              <field name="min_target_version_id"/>
                          </list>
                        </field>
                      </group>
                    </group>
                    <group string="Restore settings" invisible="job_type != 'restore'">
                        <field name="restore_download_db_suffix"/>
                        <field name="restore_rename_db_suffix"/>
                    </group>

                    <group string="Codeowner settings" invisible="job_type not in ('codeowner', 'python')">
                        <field name="fallback_reviewer"/>
                    </group>
                    <group>
                      <field name="step_order_ids" groups="base.group_no_one" readonly="1">
                        <list>
                            <field name="config_id" widget="Many2one" options="{'no_edit': 1}"/>
                        </list>
                      </field>
                    </group>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <record id="runbot_config_tree_view" model="ir.ui.view">
      <field name="name">Runbot Config list view</field>
      <field name="model">runbot.build.config</field>
      <field name="arch" type="xml">
        <list string="Build Configs">
          <field name="name"/>
          <field name="description"/>
        </list>
      </field>
    </record>

    <record id="runbot_step_config_tree_view" model="ir.ui.view">
      <field name="name">Runbot Config Step list view</field>
      <field name="model">runbot.build.config.step</field>
      <field name="arch" type="xml">
        <list string="Build Config Steps">
          <field name="name"/>
          <field name="job_type"/>
          <field name="group"/>
        </list>
      </field>
    </record>

    <record id="runbot_config_search_view" model="ir.ui.view">
      <field name="name">runbot.build.config.filter</field>
      <field name="model">runbot.build.config</field>
      <field name="arch" type="xml">
        <search string="Search config">
          <field name="name"/>
          <field name="group_name"/>
          <filter string="Is in a group" name='is_in_group' domain="[(['group', '!=', False])]"/>
          <filter string="No step's defined" name="no_step" domain="[(['step_order_ids', '=', False])]"/>
        </search>
      </field>
    </record>

    <record id="runbot_config_step_search_view" model="ir.ui.view">
      <field name="name">runbot.build.config.step.filter</field>
      <field name="model">runbot.build.config.step</field>
      <field name="arch" type="xml">
        <search string="Search config step">
          <field name="name"/>
          <field name="group_name"/>
          <field name="python_code" filter_domain="[
              '|',
              ('python_code', 'ilike', self),
              ('python_result_code', 'ilike', self),
          ]">
        </field>
          <filter string="Install job" name='install_job' domain="[(['job_type', '=', 'install_odoo'])]"/>
          <filter string="Run job" name='run_job' domain="[(['job_type', '=', 'run_odoo'])]"/>
          <filter string="Python job" name='python_job' domain="[(['job_type', '=', 'python'])]"/>
          <filter string="Create job" name='create_job' domain="[(['job_type', '=', 'create_build'])]"/>
          <separator/>
          <filter string="Is in a group" name='is_in_group' domain="[(['group', '!=', False])]"/>
          <separator/>
          <filter string="No config defined" name="no_step" domain="[(['step_order_ids', '=', False])]"/>
        </search>
      </field>
    </record>

    <record id="open_view_job_config_tree" model="ir.actions.act_window">
        <field name="name">Build Configs</field>
        <field name="res_model">runbot.build.config</field>
        <field name="view_mode">list,form</field>
    </record>

    <record id="open_view_job_tree" model="ir.actions.act_window">
        <field name="name">Build Config Steps</field>
        <field name="res_model">runbot.build.config.step</field>
        <field name="view_mode">list,form</field>
    </record>



  </data>
</odoo>
