<?xml version="1.0" encoding="utf-8"?>
<!--
  account_check_deposit for Odoo/OpenERP
  Copyright (C) 2012-2015 Akretion (http://www.akretion.com/)
  @author: BenoƮt GUILLOT <benoit.guillot@akretion.com>
  @author: Chafique DELLI <chafique.delli@akretion.com>
  @author: Alexis de Lattre <alexis.delattre@akretion.com>
  The licence is in the file __openerp__.py
-->

<openerp>
    <data>

        <record id="account_check_deposit_view_form" model="ir.ui.view">
            <field name="name">account.check.deposit.form</field>
            <field name="model">account.check.deposit</field>
            <field name="arch" type="xml">
                <form string="Checks Deposit">
                    <header>
                        <button name="validate_deposit" states="draft"
                                string="Validate"
                                type="object" class="oe_highlight"/>
                        <button name="backtodraft" states="done"
                                string="Back to Draft" type="object" />
                        <field name="state" widget="statusbar"
                               statusbar_visible="draft,done" />
                    </header>
                    <sheet>
                        <h1>
                            <field name="name" class="oe_inline" nolabel="1" />
                        </h1>
                        <group name="main">
                            <group name="left">
                                <field name="deposit_date" />
                                <field name="journal_id" options="{'no_create_edit': True, 'no_create': True}"/>
                                <field name="destination_journal_id" options="{'no_create_edit': True, 'no_create': True}"/>
                                <field name="journal_default_account_id"
                                    invisible="1"/>
                                <field name="currency_id"
                                    groups="base.group_multi_currency"/>
                                <field name="partner_bank_id"/>
                            </group>
                            <group name="right">
                                <field name="company_id"
                                       groups="base.group_multi_company"/>
                                <field name="currency_none_same_company_id"
                                    invisible="1"/>
                                <field name="check_count"/>
                                <field name="total_amount" widget="monetary"
                                    options="{'currency_field': 'currency_id'}"/>
                                <field name="move_id"/>
                            </group>
                        </group>
                        <group string="Check Payments" name="check_payments">
                            <field name="check_payment_ids" nolabel="1"
                                   widget="many2many"
                                   domain="[('reconciled', '=', False),
                                            ('debit', '>', 0),
                                            ('check_deposit_id', '=', False),
                                            ('currency_id', '=', currency_none_same_company_id),
                                            ('account_id', '=', journal_default_account_id)]"
                                    context="{'currency': currency_id, 'journal_id': journal_id, 'change_check_holder_name': True}"
                                    options="{'reload_on_button': true}">
                                <tree string="Check Payments" editable="top" delete="false">
                                    <field name="date"/>
                                    <field name="date_maturity"/>
                                    <field name="move_id"/>
                                    <field name="journal_id"/>
                                    <field name="name"/>
                                    <field name="ref"/>
                                    <field name="partner_id"/>
                                    <field name="check_holder_name"/>
                                    <field name="account_id"/>
                                    <field name="debit" sum="Total Debit"/>
                                    <field name="credit" sum="Total Credit"/>
                                    <field name="amount_currency" readonly="True" groups="base.group_multi_currency"/>
                                    <field name="full_reconcile_id"/>
                                    <field name="state_deposit" invisible="1"/>
                                    <button name="delete_check_payment"
                                            string="DELETE"
                                            type="object" class="fa fa-trash-o"
                                            icon="fa-trash-o"
                                            confirm="Please confirm you want to delete this record?"
                                            attrs="{'invisible': [('state_deposit', '!=', 'draft')]}"/>
                                </tree>
                            </field>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

        <record id="account_check_deposit_view_tree" model="ir.ui.view">
            <field name="name">account.check.deposit.tree</field>
            <field name="model">account.check.deposit</field>
            <field name="arch" type="xml">
                <tree string="Checks Deposits" colors="blue:state=='draft';">
                    <field name="name"/>
                    <field name="deposit_date"/>
                    <field name="journal_id"/>
                    <field name="partner_bank_id"/>
                    <field name="check_count"/>
                    <field name="total_amount"/>
                    <field name="currency_id" groups="base.group_multi_currency"/>
                    <field name="is_reconcile"/>
                    <field name="company_id" groups="base.group_multi_company"/>
                    <field name="state"/>
                </tree>
            </field>
        </record>

        <record id="view_check_deposit_search" model="ir.ui.view">
            <field name="name">account.check.deposit.search</field>
            <field name="model">account.check.deposit</field>
            <field name="arch" type="xml">
                <search string="Checks Deposit Search">
                    <field name="name" string="Checks Deposit"/>
                    <filter name="draft" string="Draft"
                        domain="[('state', '=', 'draft')]" />
                    <filter name="done" string="Done"
                        domain="[('state', '=', 'done')]" />
                    <group string="Group By" name="groupby">
                        <filter name="date_groupby" string="Deposit Date"
                            context="{'group_by': 'deposit_date'}"/>
                        <filter name="journal_groupby" string="Journal"
                            context="{'group_by': 'journal_id'}" />
                        <filter name="currency_groupby" string="Currency"
                            context="{'group_by': 'currency_id'}" />
                        <filter name="partner_bank_groupby" string="Bank Account"
                            context="{'group_by': 'partner_bank_id'}" />
                    </group>
                </search>
            </field>
        </record>

        <record id="action_check_deposit_tree" model="ir.actions.act_window">
            <field name="name">Checks Deposits</field>
            <field name="res_model">account.check.deposit</field>
            <field name="view_mode">tree,form</field>
        </record>

        <menuitem action="action_check_deposit_tree"
                  id="menu_check_deposit_tree"
                  parent="account.menu_finance_entries"
                  sequence="20"/>

    </data>
</openerp>