<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <record model="ir.ui.view" id="view_voucher_tree">
            <field name="name">account.voucher.tree</field>
            <field name="model">account.voucher</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree colors="blue:state in ('draft');gray:state in ('cancel')" string="Voucher Entries">
                    <field name="date"/>
                    <field name="number"/>
                    <field name="reference"/>
                    <field name="partner_id"/>
                    <field name="journal_id"/>
                    <field name="period_id" groups="base.group_extended" invisible="context.get('visible', True)"/>
                    <field name="type" invisible="context.get('visible', True)"/>
                    <field name="amount" sum="Total Amount"/>
                    <field name="state"/>
                    <button name="proforma_voucher" string="Post" states="draft" icon="terp-document-new"/>
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="view_voucher_form">
            <field name="name">account.voucher.form</field>
            <field name="model">account.voucher</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Accounting Voucher">
                    <group col="6" colspan="4">
                        <field name="partner_id" required="1" on_change="onchange_journal_voucher(line_ids, tax_id, amount, partner_id, journal_id, type)"/>
                        <field name="journal_id" widget="selection" select="1" on_change="onchange_journal_voucher(line_ids, tax_id, amount, partner_id, journal_id, type)"/>
                        <field name="type" required="1"/>
                        <field name="name" colspan="4"/>
                        <field name="reference" select="1"/>
                        <field name="account_id" widget="selection" invisible="True"/>
                    </group>
                    <notebook colspan="4">
                        <page string="Voucher Entry">
                            <field name="line_ids" on_change="onchange_price(line_ids, tax_id, partner_id)" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="180">
                                <tree string="Voucher Items" editable="bottom">
                                    <field name="account_id"/>
                                    <field name="name"/>
                                    <field name="amount" sum="Total Amount"/>
                                    <field name="type"/>
                                    <field name="account_analytic_id" groups="analytic.group_analytic_accounting"/>
                                </tree>
                            </field>
                            <group col="2" colspan="3">
                                <separator string="Internal Notes" colspan="2"/>
                                <field name="narration" colspan="2" nolabel="1"/>
                            </group>
                            <group col="2" colspan="1">
                                <group col="2" colspan="1" >
                                    <separator string="Other Information" colspan="2"/>
                                    <field name="number"/>
                                    <field name="date" on_change="onchange_date(date)"/>
                                    <field name="currency_id" invisible="True"/>
                                </group>
                                <group col="4" colspan="1" attrs="{'invisible':[('type','in',['payment', 'receipt', False])]}">
                                    <separator string="Total" colspan="4"/>
                                    <field name="tax_id" on_change="onchange_price(line_ids, tax_id, partner_id)" widget="selection"/><field name="tax_amount" nolabel="1"/><button type="object" icon="terp-stock_format-scientific" name="compute_tax" groups="base.group_extended" string="Compute Tax" attrs="{'invisible': [('state','!=','draft')]}"/>
                                    <label colspan="1" string=""/><field name="amount" string="Total"/>
                                </group>
                            </group>
                        </page>
                        <page string="Journal Items" groups="base.group_extended" attrs="{'invisible': [('state','!=','posted')]}">
                            <group col="6" colspan="4">
                                <field name="company_id" widget="selection" groups="base.group_multi_company"/>
                                <field name="period_id"/>
                                <field name="audit"/>
                            </group>
                            <separator string="Journal Items" colspan="4"/>
                            <field name="move_ids" colspan="4" nolabel="1" readonly="1"/>
                        </page>
                    </notebook>
                    <group col="10" colspan="4">
                        <field name="state"/>
                        <button name="cancel_voucher" string="Cancel" states="draft,proforma"  icon="gtk-cancel"/>
                        <button name="proforma_voucher" string="Post" states="draft" icon="terp-camera_test"/>
                        <button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
                        <button name="cancel_voucher" string="Cancel" type="object" states="posted" icon="terp-stock_effects-object-colorize" confirm="Are you sure to unreconcile this record ?"/>
                    </group>
                </form>
            </field>
        </record>

        <record id="view_voucher_filter" model="ir.ui.view">
            <field name="name">account.voucher.select</field>
            <field name="model">account.voucher</field>
            <field name="type">search</field>
            <field name="priority">1</field>
            <field name="arch" type="xml">
                <search string="Search Vouchers">
                    <group col='8' colspan='4'>
                        <filter icon="terp-document-new" string="Draft" domain="[('state','=','draft')]" help="Draft Vouchers"/>
                        <filter icon="terp-camera_test" string="Posted" domain="[('state','=','posted')]" help="Posted Vouchers"/>
                        <separator orientation="vertical"/>
                        <filter icon="terp-stock_effects-object-colorize" string="To Review" domain="[('state','=','posted')]" groups="base.group_extended" help="To Review"/>
                        <separator orientation="vertical"/>
                        <field name="date"/>
                        <field name="number"/>
                        <field name="partner_id"/>
                    </group>
                    <newline/>
                    <group col='8' colspan='4'>
                        <field name="journal_id" widget="selection" context="{'journal_id': self, 'set_visible':False}" />
                        <field name="period_id" groups="base.group_extended"/>
                    </group>
                   <newline/>
                    <group expand="0" string="Group By..." colspan="4" col="10">
                        <filter string="Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
                        <filter string="Journal" icon="terp-folder-orange" domain="[]" context="{'group_by':'journal_id'}"/>
                        <filter string="Period" icon="terp-go-month" domain="[]" context="{'group_by':'period_id','visible':True}"/>
                        <filter string="State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
                    </group>
                    <newline/>
                    <group expand="0" string="Extended options..." col='8' colspan='4'>
                        <field name="reference"/>
                        <field name="name"/>
                        <field name="narration"/>
                        <field name="amount"/>
                   </group>
                </search>
            </field>
        </record>

        <record id="account_cash_statement_graph" model="ir.ui.view">
            <field name="name">account.voucher.graph</field>
            <field name="model">account.voucher</field>
            <field name="type">graph</field>
            <field name="arch" type="xml">
                <graph string="Voucher Statistics" type="bar">
                    <field name="date"/>
                    <field name="amount" operator="+"/>
                </graph>
            </field>
         </record>

        <!-- Journal Vouchers -->
        <record model="ir.actions.act_window" id="action_voucher_list">
            <field name="name">Journal Vouchers</field>
            <field name="res_model">account.voucher</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form,graph</field>
            <field name="context">{'type':'general'}</field>
            <field name="view_id" eval="view_voucher_tree"/>
            <field name="search_view_id" ref="view_voucher_filter"/>
        </record>
        <record id="action_journal_voucher_tree" model="ir.actions.act_window.view">
            <field eval="1" name="sequence"/>
            <field name="view_mode">tree</field>
            <field name="act_window_id" ref="action_voucher_list"/>
        </record>
        <record id="action_journal_voucher_form" model="ir.actions.act_window.view">
            <field eval="2" name="sequence"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_voucher_form"/>
            <field name="act_window_id" ref="action_voucher_list"/>
        </record>
        <menuitem action="action_voucher_list" id="menu_encode_entries_by_voucher" parent="account.menu_finance_entries" sequence="6"/>

        <act_window
            domain="[('journal_id','=',active_id)]"
            id="act_journal_voucher_open"
            name="Voucher Entries"
            context="{'journal_id': active_id, 'type':type}"
            res_model="account.voucher"
            src_model="account.journal"/>

        <record model="ir.actions.act_window" id="action_review_voucher_list">
            <field name="name">Vouchers Entries</field>
            <field name="res_model">account.voucher</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" eval="view_voucher_tree"/>
            <field name="domain">[('state','=','posted')]</field>
            <field name="context">{'state':'posted'}</field>
            <field name="search_view_id" ref="view_voucher_filter"/>
        </record>

        <record id="view_bank_statement_form_invoice" model="ir.ui.view">
            <field name="name">account.bank.statement.invoice.form.inherit</field>
            <field name="model">account.bank.statement</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="account.view_bank_statement_form"/>
            <field name="arch" type="xml">
            	<field name="currency" invisible="1" position="after">
            		<button name="%(action_view_account_statement_from_invoice_lines)d"
                            string="Import Invoices" type="action" icon="gtk-execute"
                            attrs="{'invisible':[('state','=','confirm')]}"/>
            	</field>
            </field>
        </record>


        <record id="view_bank_statement_form_voucher" model="ir.ui.view">
            <field name="name">account.bank.statement.voucher.form.inherit</field>
            <field name="model">account.bank.statement</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="account.view_bank_statement_form"/>
            <field name="arch" type="xml">
                <xpath expr="/form/notebook/page[@name='statement_line_ids']/field[@name='line_ids']/tree/field[@name='amount']" position="after">
                    <field name="voucher_id" context="{'default_type': amount &lt; 0 and 'payment' or 'receipt', 'type': amount &lt; 0 and 'payment' or 'receipt', 'default_partner_id': partner_id, 'default_journal_id': parent.journal_id, 'default_amount': abs(amount), 'default_reference': ref, 'default_date': date, 'default_name': name}"/>
                    <field name="amount_reconciled"/>
                </xpath>
            </field>
        </record>

    </data>
</openerp>
