<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright 2019 Akretion France (http://www.akretion.com)
  @author Alexis de Lattre <alexis.delattre@akretion.com>
  License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
-->

<odoo>

<record id="commission_rule_form" model="ir.ui.view">
    <field name="name">commission.rule.form</field>
    <field name="model">commission.rule</field>
    <field name="arch" type="xml">
        <form>
            <sheet>
                <group name="main">
                    <field name="profile_id" invisible="not context.get('commission_rule_main_view')"/>
                    <field name="applied_on" widget="radio"/>
                    <field name="company_id" invisible="1"/>
                </group>
                <group name="match" string="Match">
                    <field name="partner_ids" attrs="{'invisible': [('applied_on', 'not in', ('0_customer_product', '1_customer_product_category'))], 'required': [('applied_on', 'in', ('0_customer_product', '1_customer_product_category'))]}"/>
                    <field name="product_categ_ids" attrs="{'invisible': [('applied_on', 'not in', ('1_customer_product_category', '3_product_category'))], 'required': [('applied_on', 'in', ('1_customer_product_category', '3_product_category'))]}"/>
                    <field name="product_ids" attrs="{'invisible': [('applied_on', 'not in', ('0_customer_product', '2_product'))], 'required': [('applied_on', 'in', ('0_customer_product', '2_product'))]}"/>
                    <field name="date_start"/>
                    <field name="date_end"/>
                </group>
                <group name="compute" string="Compute">
                    <label for="rate"/>
                    <div name="rate">
                        <field name="rate" class="oe_inline"/> %
                    </div>
                    <field name="base" widget="radio"/>
                </group>
            </sheet>
        </form>
    </field>
</record>

<record id="commission_rule_tree" model="ir.ui.view">
    <field name="name">commission.rule.tree</field>
    <field name="model">commission.rule</field>
    <field name="arch" type="xml">
        <tree>
            <field name="profile_id" invisible="not context.get('commission_rule_main_view')"/>
            <field name="applied_on"/>
            <field name="date_start"/>
            <field name="date_end"/>
            <field name="rate" string="Rate (%)"/>
            <field name="base"/>
        </tree>
    </field>
</record>

<record id="commission_rule_search" model="ir.ui.view">
    <field name="name">commission.rule.search</field>
    <field name="model">commission.rule</field>
    <field name="arch" type="xml">
        <search>
            <field name="profile_id"/>
            <filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
            <group name="groupby">
                <filter name="profile_groupby" string="Profile" context="{'group_by': 'profile_id'}"/>
            </group>
        </search>
    </field>
</record>


<record id="commission_rule_action" model="ir.actions.act_window">
    <field name="name">Commission Rules</field>
    <field name="res_model">commission.rule</field>
    <field name="view_mode">tree,form</field>
    <field name="context">{'commission_rule_main_view': True}</field>
</record>


<menuitem id="commission_rule_menu" action="commission_rule_action" parent="commission_config_root" sequence="20"/>


</odoo>
