<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <record model="ir.ui.view" id="asset_sell_tree">
        <field name="name">asset.sell.tree</field>
        <field name="model">asset.sell</field>
        <field name="arch" type="xml">
            <tree string="Sell Asset">
                <field name="asset_id"/>
                <field name="action"/>
                <field name="state"/>
            </tree>
        </field>
    </record>

    <record model="ir.ui.view" id="asset_sell_form">
        <field name="name">asset.sell.form</field>
        <field name="model">asset.sell</field>
        <field name="arch" type="xml">
            <form string="Sell Asset">
                <header>
                    <button groups='exp_asset_base.group_assets_manager' name="act_confirm"   invisible="state != 'draft'"  string="Confirm" type="object" class="oe_highlight"/>
                    <button groups='exp_asset_base.group_assets_manager' name="act_approve"  invisible="state != 'confirm'"  string="Approve" type="object" class="oe_highlight"/>
                    <button groups="exp_asset_base.group_assets_manager" name="do_action"  invisible="state != 'approve'"  string="Done" type="object" class="oe_highlight"/>
                    <button groups="exp_asset_base.group_assets_manager" name="act_draft"   invisible="state not in ['approve','confirm']"  string="Set to Draft" type="object"/>
                    <field name="state" widget="statusbar" statusbar_visible="draft,confirm,approve,done"/>
                </header>
                <sheet>
                    <field name="select_invoice_line_id" invisible="1"/>
                    <field name="gain_or_loss" invisible="1"/>
                    <field name="company_id" invisible="1"/>
                    <group>
                        <group>
                            <field name="asset_id"  readonly="state != 'draft'" context="{'form_view_ref': 'odex30_account_asset.view_account_asset_form'}"/>
                            <field name="action" readonly="state != 'draft'"/>
                            <field name="invoice_id" options="{'no_create': True}" readonly="state != 'draft'" invisible="action != 'sell'" required="action = 'sell'"   />
                            <field name="invoice_line_id" options="{'no_create': True}" readonly="state != 'draft'" invisible="select_invoice_line_id = False" required="select_invoice_line_id = True"/>
                        </group>
                        <group>
                            <field name="gain_account_id" invisible="gain_or_loss != 'gain'" readonly="state != 'draft'" required="gain_or_loss = 'gain'"  />
                            <field name="loss_account_id" invisible="gain_or_loss != 'loss'" readonly="state != 'draft'" required="gain_or_loss = 'loss'"/>
                        </group>
                    </group>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

     <record id="action_asset_sell" model="ir.actions.act_window">
        <field name="name">Asset Sell</field>
        <field name="res_model">asset.sell</field>
        <field name="view_mode">tree,form</field>
    </record>

    <menuitem id="asset_sell_menu"
                  parent="menu_account_asset_operation"
                  action="action_asset_sell"
                  name="Assets Sell" sequence="4"/>

</odoo>
