<?xml version="1.0"?>
<odoo>
    <record id="estate_property_action" model="ir.actions.act_window">
        <field name="name">Properties</field>
        <field name="res_model">estate.property</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{'search_default_available': True}</field>
    </record>

    <record id="estate_property_tree_view" model="ir.ui.view">
        <field name="name">estate.property.tree</field>
        <field name="model">estate.property</field>
        <field name="arch" type="xml">
            <tree string="Properties"  decoration-success="state in ('offer_accepted', 'offer_received')" decoration-muted="state == 'sold'" decoration-bf="state == 'offer_accepted'" >
                <field name="name" />
                <field name="property_type_id" />
                <field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}" />
                <field name="postcode" />
                <field name="bedrooms" />
                <field name="living_area" />
                <field name="expected_price" />
                <field name="selling_price" />
                <field name="date_availability" optional="hide" />
                <field name="state" invisible="True" />
            </tree>
        </field>
    </record>

    <record id="estate_property_view_form" model="ir.ui.view">
        <field name="name">estate.property.form</field>
        <field name="model">estate.property</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button name="action_sold" type="object" string="Sold" invisible="state in ('sold', 'cancelled')"/>
                    <button name="action_cancel" type="object" string="Cancel" invisible="state in ('sold', 'cancelled')"/>
                    <field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted,sold" />
                </header>
                <sheet>
                    <h1>
                        <field name="name" />
                    </h1>
                    <field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}" />
                    <group>
                        <group>
                            <field name="property_type_id" can_create="False" can_write="False" options="{'no_create': true, 'no_open': true}" />
                            <field name="postcode" />
                            <field name="date_availability" />
                        </group>
                        <group>
                            <field name="expected_price" />
                            <field name="best_price" />
                            <field name="selling_price" />
                        </group>
                    </group>

                    <notebook>
                        <page string="Details">
                            <group>
                                <field name="bedrooms" />
                                <field name="living_area" string="Living area (sqm)" />
                                <field name="facades" />
                                <field name="garage" />
                                <field name="garden" />
                                <field name="garden_area" string="Garden area (sqm)" invisible="not garden"/>
                                <field name="garden_orientation" invisible="not garden" />
                                <field name="total_area" string="Total area (sqm)" />
                            </group>
                        </page>
                        <page string="People">
                            <group>
                                <field name="salesman_id" default="self._uid" />
                                <field name="buyer_id" copy="False" />
                            </group>
                        </page>
                        <page string="Offers">
                            <field name="offer_ids" readonly="state in ('sold', 'cancelled', 'offer_accepted')"/>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record id="estate_property_view_search" model="ir.ui.view">
        <field name="name">estate.property.search</field>
        <field name="model">estate.property</field>
        <field name="arch" type="xml">
            <search>
                <field name="name" string="Title" />
                <field name="postcode"/>
                <field name="property_type_id" />
                <field name="bedrooms"/>
                <field name="expected_price" string="Expected price (sqm)"/>
                <field name="living_area" string="Minimum Living area" filter_domain="[('living_area', '>=', self)]" />
                <field name="facades"/>
                <filter string="Available" name="available" domain="['|',('state', '=', 'new'), ('state', '=', 'offer_received')]"/>
                <group expand="1" string="Group By">
                    <filter name="group_postcode" string="Postcode" context="{'group_by':'postcode'}"/>
                </group>
            </search>
        </field>
    </record>
</odoo>