Skip to content

Commit cad2ef0

Browse files
committed
[IMP] estate: Chapter 11 - Sprinkles
- Automatic and manual ordering - Decorations and invisible attributes - Stat button with action - Domain filters
1 parent 4353811 commit cad2ef0

8 files changed

+85
-17
lines changed

estate/models/estate_property.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class EstateProperty(models.Model):
77
_name = "estate.property"
88
_description = "Estate Property"
9+
_order = "id DESC"
910

1011
name = fields.Char(string="Title", required=True)
1112
description = fields.Text()
@@ -18,7 +19,7 @@ class EstateProperty(models.Model):
1819
facades = fields.Integer()
1920
garage = fields.Boolean()
2021
garden = fields.Boolean()
21-
garden_area = fields.Integer(string="Total Area (sqm)")
22+
garden_area = fields.Integer(string="Garden Area (sqm)")
2223
garden_orientation = fields.Selection(
2324
selection=[("north", "North"), ("south", "South"), ("east", "East"), ("west", "West")],
2425
help="The orientation of the Garden",

estate/models/estate_property_offer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class EstatePropertyOffer(models.Model):
66
_name = "estate.property.offer"
77
_description = "Estate Property Offer"
8+
_order = "price DESC"
89

910
price = fields.Float()
1011
status = fields.Selection(
@@ -15,6 +16,7 @@ class EstatePropertyOffer(models.Model):
1516
property_id = fields.Many2one("estate.property", required=True)
1617
validity = fields.Integer(string="Validity (days)", default=7)
1718
date_deadline = fields.Date(string="Deadline", compute="_compute_date_deadline", inverse="_inverse_date_deadline")
19+
property_type_id = fields.Many2one("estate.property.type", related="property_id.property_type_id", store=True)
1820

1921
@api.depends("create_date", "validity")
2022
def _compute_date_deadline(self):
@@ -40,9 +42,9 @@ def action_refuse_offer(self):
4042
for record in self:
4143
if record.status == "accepted":
4244
record.property_id.state = "new"
43-
record.status = "refused"
4445
record.property_id.selling_price = 0.0
4546
record.property_id.buyer_id = ""
47+
record.status = "refused"
4648
return True
4749

4850
_positive_offer_price = models.Constraint(

estate/models/estate_property_tag.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
class EstatePropertyTag(models.Model):
55
_name = "estate.property.tag"
66
_description = "Estate Property Tag"
7+
_order = "name"
78

89
name = fields.Char(required=True)
10+
color = fields.Integer()
911

1012
_unique_property_tag_name = models.Constraint(
1113
"UNIQUE(name)",
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
from odoo import models, fields
1+
from odoo import models, fields, api
22

33

44
class EstatePropertyType(models.Model):
55
_name = "estate.property.type"
66
_description = "Estate Property Type"
7+
_order = "name, sequence"
78

89
name = fields.Char(required=True)
10+
property_ids = fields.One2many("estate.property", "property_type_id")
11+
sequence = fields.Integer(default=1)
12+
offer_ids = fields.One2many("estate.property.offer", "property_type_id")
13+
offer_count = fields.Integer(compute="_compute_offer_count")
914

1015
_unique_property_type_name = models.Constraint(
1116
"UNIQUE(name)",
1217
"The tag name must be unique.",
1318
)
19+
20+
@api.depends("offer_ids")
21+
def _compute_offer_count(self):
22+
for record in self:
23+
record.offer_count = len(record.offer_ids)

estate/views/estate_property_offer_views.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
<field name="name">estate.property.offer.list</field>
2323
<field name="model">estate.property.offer</field>
2424
<field name="arch" type="xml">
25-
<list string="Properties">
25+
<list string="Properties" editable="bottom" decoration-danger="status=='refused'" decoration-success="status=='accepted'">
2626
<field name="price"/>
2727
<field name="partner_id"/>
2828
<field name="validity"/>
2929
<field name="date_deadline"/>
30-
<button name="action_accept_offer" type="object" icon="fa-check" title="Accept offer"/>
31-
<button name="action_refuse_offer" type="object" icon="fa-times" title="Refuse offer"/>
32-
<field name="status"/>
30+
<button name="action_accept_offer" type="object" icon="fa-check" title="Accept offer" invisible="status"/>
31+
<button name="action_refuse_offer" type="object" icon="fa-times" title="Refuse offer" invisible="status"/>
32+
<field name="status" optional="hide"/>
3333
</list>
3434
</field>
3535
</record>

estate/views/estate_property_tag_views.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@
1919
</form>
2020
</field>
2121
</record>
22+
23+
<record id="estate_property_tag_list" model="ir.ui.view">
24+
<field name="name">estate.property.tag.list</field>
25+
<field name="model">estate.property.tag</field>
26+
<field name="arch" type="xml">
27+
<list string="Properties types" editable="bottom">
28+
<field name="name"/>
29+
</list>
30+
</field>
31+
</record>
2232
</odoo>

estate/views/estate_property_type_views.xml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,59 @@
33
<record id="estate_property_type_action" model="ir.actions.act_window">
44
<field name="name">Property Types</field>
55
<field name="res_model">estate.property.type</field>
6-
<field name="view_mode">form</field>
6+
<field name="view_mode">list,form</field>
7+
</record>
8+
9+
<record id="estate_property_offers_action" model="ir.actions.act_window">
10+
<field name="name">Properties Offers</field>
11+
<field name="res_model">estate.property.offer</field>
12+
<field name="view_mode">list</field>
13+
<field name="domain">[("property_type_id", "=", active_id)]</field>
14+
</record>
15+
16+
<record id="estate_property_type_list" model="ir.ui.view">
17+
<field name="name">estate.property.type.list</field>
18+
<field name="model">estate.property.type</field>
19+
<field name="arch" type="xml">
20+
<list string="Properties types">
21+
<field name="sequence" widget="handle"/>
22+
<field name="name"/>
23+
</list>
24+
</field>
725
</record>
826

927
<record id="estate_property_type_form" model="ir.ui.view">
1028
<field name="name">estate.property.type.form</field>
1129
<field name="model">estate.property.type</field>
1230
<field name="arch" type="xml">
1331
<form string="New property type">
32+
<header>
33+
<div class="oe_button_box" name="button_box">
34+
<button
35+
class="oe_stat_button"
36+
name="%(estate_property_offers_action)d"
37+
type="action"
38+
icon="fa-money"
39+
>
40+
<field name="offer_count" widget="statinfo" string="Offers"/>
41+
</button>
42+
</div>
43+
</header>
1444
<sheet>
1545
<h1>
1646
<field name="name" placeholder="Property type"/>
1747
</h1>
48+
<notebook>
49+
<page string="Properties">
50+
<field name="property_ids">
51+
<list string="Types" create="false" edit="false" delete="false">
52+
<field name="name"/>
53+
<field name="expected_price"/>
54+
<field name="state"/>
55+
</list>
56+
</field>
57+
</page>
58+
</notebook>
1859
</sheet>
1960
</form>
2061
</field>

estate/views/estate_property_views.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44
<field name="name">Properties</field>
55
<field name="res_model">estate.property</field>
66
<field name="view_mode">list,form</field>
7+
<field name="context">{"search_default_state": True}</field>
78
</record>
89

910
<record id="estate_property_list" model="ir.ui.view">
1011
<field name="name">estate.property.list</field>
1112
<field name="model">estate.property</field>
1213
<field name="arch" type="xml">
13-
<list string="Properties">
14+
<list string="Properties" decoration-success="state in ('received', 'accepted')" decoration-bf="state=='accepted'" decoration-muted="state=='sold'">
1415
<field name="name"/>
1516
<field name="property_type_id"/>
1617
<field name="postcode"/>
1718
<field name="bedrooms"/>
1819
<field name="living_area"/>
1920
<field name="expected_price"/>
2021
<field name="selling_price"/>
21-
<field name="date_availability"/>
22+
<field name="date_availability" optional="hide"/>
2223
</list>
2324
</field>
2425
</record>
@@ -29,14 +30,15 @@
2930
<field name="arch" type="xml">
3031
<form string="New property">
3132
<header>
32-
<button name="action_property_sold" type="object" string="Sold"/>
33-
<button name="action_property_cancel" type="object" string="Cancel"/>
33+
<button name="action_property_sold" type="object" string="Sold" invisible="state in ('sold', 'cancelled')"/>
34+
<button name="action_property_cancel" type="object" string="Cancel" invisible="state in ('sold', 'cancelled')"/>
35+
<field name="state" widget="statusbar" statusbar_visible="new,received,accepted,sold"/>
3436
</header>
3537
<sheet>
3638
<h1>
3739
<field name="name" placeholder="New property"/>
3840
</h1>
39-
<field name="tag_ids" widget="many2many_tags"/>
41+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
4042
<group>
4143
<group>
4244
<field name="property_type_id"/>
@@ -57,13 +59,13 @@
5759
<field name="living_area"/>
5860
<field name="garage"/>
5961
<field name="garden"/>
60-
<field name="garden_area"/>
61-
<field name="garden_orientation"/>
62+
<field name="garden_area" invisible="not garden"/>
63+
<field name="garden_orientation" invisible="not garden"/>
6264
<field name="total_area"/>
6365
</group>
6466
</page>
6567
<page string="Offers">
66-
<field name="offer_ids"/>
68+
<field name="offer_ids" readonly="state in ('accepted','sold','cancelled')"/>
6769
</page>
6870
<page string="Other info">
6971
<group>
@@ -87,7 +89,7 @@
8789
<field name="postcode"/>
8890
<field name="expected_price"/>
8991
<field name="bedrooms"/>
90-
<field name="living_area"/>
92+
<field name="living_area" filter_domain="[('living_area', '>', self)]"/>
9193
<field name="facades"/>
9294
<separator/>
9395
<filter string="Available" name="state" domain="['|',('state', '=', 'new'),('state', '=', 'received')]"/>

0 commit comments

Comments
 (0)