<?xml version="1.0" encoding="utf-8" ?>
<!--
  © 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<!--
    Customize all mandate views (and actions) to fit SEPA mandate style
-->
<odoo>
    <record id="view_mandate_form" model="ir.ui.view">
        <field name="name">sdd.mandate.form</field>
        <field name="model">account.banking.mandate</field>
        <field name="inherit_id" ref="account_banking_mandate.view_mandate_form" />
        <field name="arch" type="xml">
            <button name="validate" position="before">
                <button name="print_report" type="object" string="Print" />
            </button>
            <field name="partner_id" position="after">
                <field
                    name="scheme"
                    attrs="{'invisible': [('format', '!=', 'sepa')],
                                         'required': [('format', '=', 'sepa')]}"
                />
                <field
                    name="recurrent_sequence_type"
                    attrs="{'invisible': ['|', ('type', '=', 'oneoff'), ('format', '!=', 'sepa')],
                           'required': [('type', '=', 'recurrent')]}"
                />
            </field>
            <field name="type" position="attributes">
                <attribute
                    name="attrs"
                >{'required': [('format', '=', 'sepa')]}</attribute>
            </field>

        </field>
    </record>
    <record id="view_mandate_tree" model="ir.ui.view">
        <field name="name">sdd.mandate.tree</field>
        <field name="model">account.banking.mandate</field>
        <field name="inherit_id" ref="account_banking_mandate.view_mandate_tree" />
        <field name="arch" type="xml">
            <field name="type" position="after">
                <field
                    name="scheme"
                    widget="badge"
                    decoration-info="scheme == 'CORE'"
                    decoration-success="scheme == 'B2B'"
                />
                <field
                    name="recurrent_sequence_type"
                    string="Sequence Type"
                    widget="badge"
                    decoration-info="recurrent_sequence_type == 'first'"
                    decoration-success="recurrent_sequence_type == 'recurring'"
                    decoration-warning="recurrent_sequence_type == 'final'"
                />
            </field>
            <field name="type" position="attributes">
                <attribute name="decoration-info">type == 'recurrent'</attribute>
                <attribute name="decoration-warning">type == 'oneoff'</attribute>
            </field>
            <field name="format" position="attributes">
                <attribute name="decoration-success">format == 'sepa'</attribute>
            </field>

        </field>
    </record>
    <record id="view_mandate_search" model="ir.ui.view">
        <field name="name">sdd.mandate.search</field>
        <field name="model">account.banking.mandate</field>
        <field name="inherit_id" ref="account_banking_mandate.view_mandate_search" />
        <field name="arch" type="xml">
            <filter name="expired" position="after">
                <separator />
                <filter
                    name="oneoff"
                    string="One-Off"
                    domain="[('type', '=', 'oneoff')]"
                />
                <filter
                    name="recurrent"
                    string="Recurrent"
                    domain="[('type', '=', 'recurrent')]"
                />
            </filter>
            <filter name="signature_date_groupby" position="before">
                <filter
                    name="type_groupby"
                    string="Type"
                    context="{'group_by': 'type'}"
                />
                <filter
                    name="scheme_groupby"
                    string="Scheme"
                    context="{'group_by': 'scheme'}"
                />
                <filter
                    name="recurrent_sequence_type_groupby"
                    string="Sequence Type"
                    context="{'group_by': 'recurrent_sequence_type'}"
                />
            </filter>
        </field>
    </record>
</odoo>
