<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Account operation rule form view -->
    <record id="view_account_operation_rule_form" model="ir.ui.view">
      <field name="name">account.operation.rule.form</field>
      <field name="model">account.operation.rule</field>
      <field name="arch" type="xml">
        <form string="Statement Operation Rule">
          <sheet>
            <div class="oe_title">
              <label for="name" class="oe_edit_only"/>
              <h1>
                <field name="name"/>
              </h1>
            </div>
            <group name="options">
              <field name="rule_type"/>
            </group>
            <group name="rule" string="Rule">
              <group name="amount" attrs="{'invisible': [('rule_type', 'not in', ('rounding', 'currency'))]}">
                <label for="amount" string="When the balance is between"/>
                <div>
                  <field name="amount_min" class="oe_inline" /> And
                  <field name="amount_max" class="oe_inline" />
                </div>
                <label for="currencies" string="And the currency is one of" attrs="{'invisible': [('rule_type', '!=', 'currency')]}"/>
                <div attrs="{'invisible': [('rule_type', '!=', 'currency')]}">
                  <field name="currencies" class="oe_inline" widget="many2many_tags"/>
                </div>
              </group>
            </group>
            <group name="operations" string="Result">
              <label for="operations" string="Then the following operations will be applied:" colspan="2"/>
              <field name="operations" nolabel="1"/>
            </group>
          </sheet>
        </form>
      </field>
    </record>

    <!-- Account operation rule tree view -->
    <record id="view_account_operation_rule_tree" model="ir.ui.view">
      <field name="name">account.operation.rule.tree</field>
      <field name="model">account.operation.rule</field>
      <field name="arch" type="xml">
        <tree string="Statement Operation Rules">
          <field name="sequence" widget="handle"/>
          <field name="name"/>
          <field name="rule_type"/>
          <field name="amount_min"/>
          <field name="amount_max"/>
          <field name="operations"/>
        </tree>
      </field>
    </record>

    <!-- Account operation rule search view -->
    <record id="view_account_operation_rule_search" model="ir.ui.view">
      <field name="name">account.operation.rule.search</field>
      <field name="model">account.operation.rule</field>
      <field name="arch" type="xml">
        <search string="Statement Operation Rules">
          <field name="name"/>
          <field name="rule_type"/>
          <field name="amount_min"/>
          <field name="amount_max"/>
          <field name="operations"/>
        </search>
      </field>
    </record>

    <!-- Account operation rule action -->
    <record id="action_account_operation_rule" model="ir.actions.act_window">
      <field name="name">Reconciliation Rules</field>
      <field name="res_model">account.operation.rule</field>
      <field name="view_type">form</field>
      <field name="view_mode">tree,form</field>
      <field name="search_view_id" ref="view_account_operation_rule_search"/>
      <field name="help" type="html">
        <p class="oe_view_nocontent_create">
          Click to create a reconciliation rule.
          </p><p>
          Those can be used to automatically create a move line when reconciling
          your bank statements.
        </p>
      </field>
    </record>

    <!-- Add operation rule link in Bank card menu in Accounting Dashboard -->
    <record id="account_journal_dashboard_kanban_view" model="ir.ui.view">
      <field name="name">account.journal.dashboard.kanban.inherit</field>
      <field name="model">account.journal</field>
      <field name="inherit_id" ref="account.account_journal_dashboard_kanban_view"/>
      <field name="arch" type="xml">
        <xpath expr="//a[contains(@context, 'action_account_operation_template')]/parent::div" position="after">
          <div>
            <a type="object" name="open_reconciliation_rules" groups="account.group_account_manager">
              Reconciliation Rules
            </a>
          </div>
        </xpath>
      </field>
    </record>

</odoo>
