<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record model="ir.ui.view" id="transaction_wizard_first">
            <field name="name">transaction.wizard.first</field>
            <field name="model">banking.transaction.wizard</field>
            <field name="arch" type="xml">
                <form string="Match transaction"  version="7.0">
                    <!-- fields used for form logic -->
                    <field name="statement_line_parent_id" invisible="True"/>
                    <field name="invoice_ids" invisible="True"/>
                    <field name="move_line_ids" invisible="True"/>
                    <field name="match_multi" invisible="True"/>
                    <field name="duplicate" invisible="True"/>
                    <group colspan="2" col="2">
                        <group colspan="2" col="4">
                            <separator string="Transaction data" colspan="4"/>
                            <field name="partner_id"/>
                            <field name="date"/>
                            <field name="amount"/>
                            <field name="ref"/>
                            <field name="message" colspan="4"/>
                        </group>
                        
                        <!-- (semi-) automatic matching and selection -->
                        
                        <group colspan="2" col="4">

                            <separator string="Current match" colspan="4"/>
                            <field name="match_type"/>
                            <newline />
                            <field name="move_currency_amount" />
                            <newline />
                            <field name="residual"/>
                            <group attrs="{'invisible': [('match_multi', '=', False)]}" colspan="4" col="2">
                                <separator string="Multiple matches" colspan="2"/>
                                <label colspan="2" string="Multiple matches were found for this bank transfer. You must pick one of the matches or select a match manually below." />
                            </group>
                            </group>
                            </group>
                            <group>
                            <newline/>
                                <!-- show if we have an invoice type match (but the user may need to select from multiple options)
                                     or whenever there is an invoice_id (e.g. in case of a manual match) 
                                -->
                                <field name='invoice_id'
                                       attrs="{'readonly': [('match_multi', '=', False)], 'invisible': [('match_type', '!=', 'invoice'),('invoice_id', '=', False)]}" colspan="2"
                                       domain="[('id', 'in', invoice_ids[0][2])]"
                                       />
                                <!-- show if we have a move type match or a manual match without an invoice_id
                                -->
                                <field name='move_line_id'
                                       attrs="{'readonly': [('match_multi', '=', False)], 'invisible': [('match_type', '!=', 'move'),('invoice_id', '=', False)]}" colspan="2"
                                       domain="[('id', 'in', move_line_ids[0][2])]"
                                       />
                             <newline/>
                            <field colspan="2" name='analytic_account_id' />
                            <button colspan="1"
                                    name="trigger_write"
                                    type="object"
                                    attrs="{'invisible': [('match_multi', '=', False)]}"
                                    string="Select"/>
                            <newline/>

                            <!-- residual and write off -->
                            
                        </group>
                        <notebook>
                            <!-- Duplicate flagging -->
                            <page string="Duplicate" attrs="{'invisible': [('duplicate', '=', False)]}">
                                <group  colspan="2" col="2">
                                    <label colspan="2" string="This bank transfer was marked as a duplicate. You can either confirm that this is not the case, or remove the bank transfer from the system."/>
                                    <newline/>
                                    <button colspan="1"
                                            name="reverse_duplicate"
                                            type="object"
                                            string="Remove duplicate flag"/>
                                </group>
                            </page>
                            <!-- Redo automatic match -->
                            <page string="Match again">
                                <label string="You can let the system try to match this bank statement line again after you have made any changes in the database (for instance, add an invoice or a bank account)."  colspan="2"/>
                                <newline/>                           
                                <button colspan="1"
                                        name="trigger_match"
                                        type="object"
                                        string="Match again"/>
                            </page>
                            <!-- Manual selection -->
                            <page string="Manual match">
                                <separator string="Match one or more invoices" colspan="4"/>
                                <field name="manual_invoice_ids" colspan="4"
                                       context="{'search_default_partner_id': partner_id}"
                                       />
                                <separator string="Or match one or more entries" colspan="4"/>
                                <field name="manual_move_line_ids" colspan="4"
                                       context="{'search_default_partner_id': partner_id}"
                                       />
                                <button name="trigger_write"
                                        type="object"
                                        string="Match" />
                            </page>
                            <page string="Write-Off" attrs="{'invisible': [('match_type', '=', False)]}">
                                <group colspan="2" col="2">
                                    <label string="Choose what you want to do with the eventual difference between the paid amount and the sum of allocated amounts. You can either choose to keep open this difference on the partner's account, or reconcile it with the payment."  colspan="2"/>
                                    <field name="payment_option" />
                                    <field name="writeoff_account_id" attrs="{'required':[('payment_option','=','with_writeoff')],'invisible':[('payment_option','=','without_writeoff')]}" />
                                    <field name="writeoff_analytic_id"
                                           groups="analytic.group_analytic_accounting"
                                           attrs="{'invisible':[('payment_option','=','without_writeoff')]}" />
                                    <button colspan="1"
                                            name="trigger_write"
                                            type="object"
                                            string="Set write-off account"/>
                                </group>                                
                            </page>
                            <page string="Disable reconciliation" attrs="{'invisible': [('match_type', '==', False)]}">
                                <group colspan="2" col="2">
                                    <label string="You can disable the reconciliation of this bank transfer"  colspan="2"/>
                                    <newline/>                           
                                    <button colspan="1"
                                            name="disable_match"
                                            type="object"
                                            string="Disable reconciliation"/>
                                </group>
                            </page>
                        </notebook>
                        <footer>
                            <button icon="gtk-ok" string="Close" special="cancel"/>
                        </footer>
                    
                </form>
            </field>
        </record>
    </data>
</openerp>
