<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2017 Carlos Dauden <carlos.dauden@tecnativa.com>
     License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
    <record id="view_partner_form" model="ir.ui.view">
        <field name="inherit_id" ref="base.view_partner_form" />
        <field name="model">res.partner</field>
        <field name="groups_id" eval="[(4, ref('account.group_account_invoice'))]" />
        <field type="xml" name="arch">
            <xpath expr="//div[@name='button_box']" position="inside">
                <field name="customer_rank" invisible="1" />
                <button
                    name="act_show_contract"
                    type="object"
                    class="oe_stat_button"
                    icon="fa-book"
                    context="{'default_contract_type': 'sale', 'contract_type': 'sale'}"
                    attrs="{'invisible': [('customer_rank','=',0)]}"
                    help="Show the sale contracts for this partner"
                >
                    <field
                        name="sale_contract_count"
                        widget="statinfo"
                        string="Sale Contracts"
                    />
                </button>
                <field name="supplier_rank" invisible="1" />
                <button
                    name="act_show_contract"
                    type="object"
                    class="oe_stat_button"
                    icon="fa-book"
                    context="{'default_contract_type': 'purchase', 'contract_type': 'purchase'}"
                    attrs="{'invisible': [('supplier_rank','=',0)]}"
                    help="Show the purchase contracts for this partner"
                >
                    <field
                        name="purchase_contract_count"
                        widget="statinfo"
                        string="Purchase Contracts"
                    />
                </button>
            </xpath>
        </field>
    </record>
    <record id="view_res_partner_filter" model="ir.ui.view">
        <field name="inherit_id" ref="base.view_res_partner_filter" />
        <field name="model">res.partner</field>
        <field type="xml" name="arch">
            <filter name="inactive" position="after">
                <separator />
                <filter
                    name="filter_running_contract"
                    string="With running contracts"
                    domain="['|', ('contract_ids.date_end', '&gt;=', context_today().strftime('%Y-%m-%d')), '&amp;', ('contract_ids.date_end', '=', False), ('contract_ids.recurring_next_date', '!=', False)]"
                />
            </filter>
        </field>
    </record>
</odoo>
