<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>

        <record id="view_voucher_filter_customer_pay" model="ir.ui.view">
            <field name="name">account.voucher.customer.pay.select</field>
            <field name="model">account.voucher</field>
            <field name="type">search</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" string="Customer"/>
                    </group>
                    <newline/>
                    <group col='8' colspan='4'>
                        <field name="journal_id" widget="selection" context="{'journal_id': self, 'set_visible':False}" domain="[('type','in',('bank','cash'))]"/>
                        <field name="period_id" groups="base.group_extended"/>
                    </group>
                   <newline/>
                    <group expand="0" string="Group By..." colspan="4" col="10">
                        <filter string="Customer" 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="view_voucher_filter_vendor_pay" model="ir.ui.view">
            <field name="name">account.voucher.purchase.pay.select</field>
            <field name="model">account.voucher</field>
            <field name="type">search</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" string="Supplier"/>
                    </group>
                    <newline/>
                    <group col='8' colspan='4'>
                        <field name="journal_id" widget="selection" context="{'journal_id': self, 'set_visible':False}" domain="[('type','in',('bank','cash'))]"/>
                        <field name="period_id" groups="base.group_extended"/>
                    </group>
                   <newline/>
                    <group expand="0" string="Group By..." colspan="4" col="10">
                        <filter string="Supplier" 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 model="ir.ui.view" id="view_low_priority_payment_form">
            <field name="name">account.voucher.payment.low.priority.form</field>
            <field name="model">account.voucher</field>
            <field name="type">form</field>
            <field name="priority">1</field>
            <field name="arch" type="xml">
                <form string="Bill Payment">
                    <group col="6" colspan="4">
                        <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type)" context="{'invoice_currency':currency_id}" string="Vendor"/>
                        <field name="journal_id"
                            domain="[('type','in',['bank', 'cash'])]"
                            widget="selection" select="1"
                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type)"
                            string="Payment Method"/>
                        <field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type)"/>
                        <field name="reference" select="1" string="Payment Ref"/>
                        <field name="name" colspan="4"/>
                        <field name="account_id"
                            widget="selection"
                            invisible="True"/>
                        <field name="pre_line" invisible="1"/>
                        <field name="type" invisible="True"/>
                    </group>
                    <notebook colspan="4">
                        <page string="Payment Information">
                            <field name="line_dr_ids" attrs="{'invisible': [('type', '=', 'receipt')]}" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140">
                                <tree string="Open Vendor Journal Entries" editable="bottom">
                                    <field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
                                        on_change="onchange_move_line_id(move_line_id)"
                                        domain="[('account_id.type','=','payable'), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
                                        />
                                    <field name="account_id" groups="base.group_extended" domain="[('type','=','payable')]"/>
                                    <field name="date_original" readonly="1"/>
                                    <field name="date_due" readonly="1"/>
                                    <field name="amount_original" readonly="1"/>
                                    <field name="amount_unreconciled" sum="Open Balance" readonly="1"/>
                                    <field name="amount" sum="Payment"/>
                                </tree>
                            </field>
                            <field name="line_cr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('type', '=', 'payment')]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}">
                                <tree string="Open Customer Journal Entries" editable="bottom">
                                    <field name="move_line_id"/>
                                    <field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]"/>
                                    <field name="date_original"/>
                                    <field name="amount_original"/>
                                    <field name="amount" sum="Payment"/>
                                </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">
                                <separator string="Other Information" colspan="2"/>
                                <field name="date" select="1" on_change="onchange_date(date)"/>
                                <field name="currency_id" invisible="True"/>
                                <field name="number"/>
                            </group>
                        </page>
                    </notebook>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="view_vendor_payment_form">
            <field name="name">account.voucher.payment.form</field>
            <field name="model">account.voucher</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Bill Payment">
                    <group col="6" colspan="4">
                        <field name="partner_id" domain="[('supplier','=',True)]" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type)" context="{'invoice_currency':currency_id}" string="Vendor"/>
                        <field name="journal_id"
                            domain="[('type','in',['bank', 'cash'])]"
                            widget="selection" select="1"
                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type)"
                            string="Payment Method"/>
                        <field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type)"/>
                        <field name="reference" select="1" string="Payment Ref"/>
                        <field name="name" colspan="4"/>
                        <field name="account_id"
                            widget="selection"
                            invisible="True"/>
                        <field name="pre_line" invisible="1"/>
                        <field name="type" invisible="True"/>
                    </group>
                    <notebook colspan="4">
                        <page string="Payment Information">
                            <field name="line_dr_ids" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140">
                                <tree string="Vendor Invoices and Outstanding transactions" editable="bottom">
                                    <field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
                                        on_change="onchange_move_line_id(move_line_id)"
                                        domain="[('account_id.type','=','payable'), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
                                        />
                                    <field name="account_id" groups="base.group_extended" domain="[('type','=','payable')]"/>
                                    <field name="date_original" readonly="1"/>
                                    <field name="date_due" readonly="1"/>
                                    <field name="amount_original" readonly="1"/>
                                    <field name="amount_unreconciled" sum="Open Balance" readonly="1"/>
                                    <field name="amount" sum="Payment"/>
                                </tree>
                                <form string="Payment Information">
                                    <label string="Form view not available for Payment Lines"/>
                                </form>
                            </field>
                            <field name="line_cr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('pre_line','=',False)]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}">
                                <tree string="Credits" editable="bottom">
                                    <field name="move_line_id"/>
                                    <field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]"/>
                                    <field name="date_original"/>
                                    <field name="amount_original"/>
                                    <field name="amount" sum="Payment"/>
                                </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">
                                <separator string="Other Information" colspan="2"/>
                                <field name="date" select="1" on_change="onchange_date(date)"/>
                                <field name="currency_id" invisible="True"/>
                                <field name="number"/>
                            </group>
                        </page>
                        <page string="Journal Items" groups="base.group_extended" attrs="{'invisible': [('state','!=','posted')]}">
                            <group col="6" colspan="4">
                                <field name="company_id" select="1" 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="cancel_voucher" string="Unreconcile" type="object" states="posted" icon="terp-stock_effects-object-colorize" confirm="Are you sure to unreconcile this record ?"/>
                        <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"/>
                    </group>
                </form>
            </field>
        </record>

        <record id="action_vendor_payment" model="ir.actions.act_window">
            <field name="name">Vendor Payment</field>
            <field name="res_model">account.voucher</field>
            <field name="view_type">form</field>
            <field name="domain">[('journal_id.type', 'in', ['bank', 'cash']), ('type','=','payment')]</field>
            <field name="context">{'type':'payment'}</field>
            <field name="view_id" eval="False"/>
            <field name="search_view_id" ref="view_voucher_filter_vendor_pay"/>
            <field name="target">current</field>
        </record>
        <record id="action_vendor_payment_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_vendor_payment"/>
        </record>
        <record id="action_vendor_payment_form" model="ir.actions.act_window.view">
            <field eval="2" name="sequence"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_vendor_payment_form"/>
            <field name="act_window_id" ref="action_vendor_payment"/>
        </record>


        <menuitem action="action_vendor_payment" icon="STOCK_JUSTIFY_FILL" sequence="12"
            id="menu_action_vendor_payment"  parent="account.menu_finance_payables"/>

        <record model="ir.ui.view" id="view_vendor_receipt_form">
            <field name="name">account.voucher.receipt.form</field>
            <field name="model">account.voucher</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Sales Payment">
                    <group col="6" colspan="4">
                        <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type)" string="Customer"/>
                        <field name="journal_id"
                            domain="[('type','in',['bank', 'cash'])]"
                            widget="selection" select="1"
                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type)"
                            string="Payment Method"/>
                        <field name="amount"
                            on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type)"/>
                        <field name="reference" select="1" string="Payment Ref"/>
                        <field name="name" colspan="4"/>
                        <field name="account_id"
                            widget="selection"
                            invisible="True"/>
                        <field name="pre_line" invisible="1"/>
                        <field name="type" invisible="True"/>
                    </group>
                    <notebook colspan="4">
                        <page string="Payment Information">
                            <field name="line_cr_ids" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140">
                                <tree string="Invoices and outstanding transactions" editable="bottom">
                                    <field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
                                        on_change="onchange_move_line_id(move_line_id)"
                                        domain="[('account_id.type','in',('receivable','payable')), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
                                        />
                                    <field name="account_id"  groups="base.group_extended" domain="[('type','=','receivable')]"/>
                                    <field name="date_original" readonly="1"/>
                                    <field name="date_due" readonly="1"/>
                                    <field name="amount_original" readonly="1"/>
                                    <field name="amount_unreconciled" sum="Open Balance" readonly="1"/>
                                    <field name="amount" sum="Payment"/>
                                </tree>
                            </field>
                            <field name="line_dr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('pre_line','=',False)]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}">
                                <tree string="Credits" editable="bottom">
                                    <field name="move_line_id"/>
                                    <field name="account_id"  groups="base.group_extended" domain="[('type','=','receivable')]"/>
                                    <field name="date_original"/>
                                    <field name="amount_original"/>
                                    <field name="amount" sum="Payment"/>
                                </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">
                                <separator string="Other Information" colspan="2"/>
                                <field name="date" select="1" on_change="onchange_date(date)"/>
                                <field name="currency_id" invisible="True"/>
                                <field name="number"/>
                            </group>
                        </page>
                        <page string="Journal Items" groups="base.group_extended" attrs="{'invisible': [('state','!=','posted')]}">
                            <group col="6" colspan="4">
                                <field name="company_id" select="1" 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="cancel_voucher" string="Unreconcile" type="object" states="posted" icon="terp-stock_effects-object-colorize" confirm="Are you sure to unreconcile this record ?"/>
                        <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"/>
                    </group>
                </form>
            </field>
        </record>

        <record id="action_vendor_receipt" model="ir.actions.act_window">
            <field name="name">Sales Payment</field>
            <field name="res_model">account.voucher</field>
            <field name="view_type">form</field>
            <field name="domain">[('journal_id.type', 'in', ['bank', 'cash']), ('type','=','receipt')]</field>
            <field name="context">{'type':'receipt'}</field>
            <field name="search_view_id" ref="view_voucher_filter_customer_pay"/>
            <field name="view_id" eval="False"/>
            <field name="target">current</field>
        </record>
        <record id="action_vendor_receipt_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_vendor_receipt"/>
        </record>
        <record id="action_vendor_receipt_form" model="ir.actions.act_window.view">
            <field eval="2" name="sequence"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_vendor_receipt_form"/>
            <field name="act_window_id" ref="action_vendor_receipt"/>
        </record>

        <menuitem action="action_vendor_receipt" icon="STOCK_JUSTIFY_FILL" sequence="12"
            id="menu_action_vendor_receipt"  parent="account.menu_finance_receivables"/>
    </data>
</openerp>
