<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="bid_bond_tree" model="ir.ui.view">
            <field name="name">bid.bond.tree</field>
            <field name="model">bid.bond</field>
            <field name="arch" type="xml">
                <tree string="Bid Bond">
                    <field name="name"/>
                    <field name="sale_order_id"/>
                    <field name="bidbond_type"/>
                    <field name="bidbond_date"/>
                    <field name="bidbond_amount"/>
                    <field name="expiry_date"/>
                    <field name="partner_id"/>
                    <field name="contract_amount"/>
                </tree>
            </field>
        </record>

        <record id="bid_bond_form" model="ir.ui.view">
            <field name="name">bid.bond.form</field>
            <field name="model">bid.bond</field>
            <field name="arch" type="xml">
                <form string="Bid Bond">
                    <header>

                        <button name="action_send" string="Send" type="object" states="draft" class="btn-primary"/>
                        
                        <button name="action_confirm" string="Confirm" type="object" states="send" class="btn-primary"/>
                        
                        <button name="action_ceo_approve" string="CEO Aprrove" type="object" class="btn-primary" attrs="{'invisible': ['|', ('ceo_approve', '=', False), ('state', '!=', 'confirm')]}"/>
                        
                        <button name="action_approve" string="Financial Approve" type="object" states="ceo_approve" class="btn-primary"/>

                        <button name="action_approve" string="Financial Approve" type="object" class="btn-primary" attrs="{'invisible': ['|', ('ceo_approve', '=', True), ('state', '!=', 'confirm')]}"/>

                        <field name="state" widget="statusbar" statusbar_visible="draft,send,confirm,approve"/>

                    </header>

                    <sheet>
                        <div class="oe_title">
                            <h1>
                                <field name="name" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
                            </h1>
                        </div>
                        <group>
                            <group>
                                <field name="bidbond_type" required="1" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
                                <field name="ceo_approve" invisible="1" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
                                <field name="bidbond_date" required="1" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
                                <field name="expiry_date" required="1" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
                                <field name="bidbond_amount" required="1" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
                            </group>

                            <group>
                                <field name="partner_id" readonly="1" force_save="1" required="1" />
                                <field name="sale_order_id" readonly="1" force_save="1" />
                                <field name="contract_amount" readonly="1" force_save="1"/>
                                <field name="lg_percent"  attrs="{'readonly':[('state', '!=', 'draft')]}"/>
                                <field name="lg_request"  attrs="{'readonly':[('state', '!=', 'draft')]}"/>
                                <field name="bidbond_id"  attrs="{'readonly':[('state', '!=', 'draft')], 'invisible': [('lg_request', '!=', 'extention')], 'required': [('lg_request', '=', 'extention')]}"/>

                            </group>
                            
                        </group>

                        <notebook>
                            <page name='project_location' string="Project Location">
                                <group>
                                    <field name="project_country_id" readonly="1"/>
                                    <field name="project_state_id" readonly="1"/>
                                    <field name="city_id" readonly="1"/>
                                </group>
                            </page>

                            <page name="client_location" string="Customer Location">
                                <group>
                                    <field name="customer_country_id" readonly="1"/>
                                    <field name="customer_state_id" readonly="1" string="Region"/>
                                </group>

                            </page>
                        </notebook>
                    </sheet>
                    <div class="oe_chatter">
                        <field name="message_follower_ids"/>
                        <field name="activity_ids"/>
                        <field name="message_ids"/>
                    </div>
                </form>
            </field>
        </record>


        <record id="action_bid_bond" model="ir.actions.act_window">
            <field name="name">Bid Bond</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">bid.bond</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{}</field>
        </record>

        <record id="action_bid_bond_from_sale_order" model="ir.actions.act_window">
            <field name="name">Bid Bond</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">bid.bond</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[('sale_order_id', '=', active_id)]</field>
            <field name="context">{'default_sale_order_id': active_id}</field>
        </record>

    </data>
</odoo>
