Skip to content

Commit 546648b

Browse files
committed
[IMP] estate: Chapter 11 Add the Sprinkles
1 parent a4fe342 commit 546648b

9 files changed

+121
-16
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
'version': '0.1',
1313
'depends': ['base', 'web'],
1414
'application': True,
15-
'installable': True,
1615
'data': [
1716
'data/ir.model.access.csv',
1817
'views/estate_property_tag_views.xml',
@@ -21,5 +20,5 @@
2120
'views/estate_property_views.xml',
2221
'views/estate_menus.xml',
2322
],
24-
'licence': 'AGPL-3'
23+
'license': 'LGPL-3'
2524
}

estate/models/estate_property.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class EstatePropertyModel(models.Model):
99
_name = 'estate.property'
1010
_description = "Real Estate property database"
11+
_order = 'id desc'
1112
name = fields.Char(required=True)
1213
description = fields.Text()
1314
postcode = fields.Char()

estate/models/estate_property_offer.py

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

910
price = fields.Float()
1011
status = fields.Selection(
@@ -13,6 +14,8 @@ class EstatePropertyOffer(models.Model):
1314
)
1415
partner_id = fields.Many2one('res.partner', string="Partner", required=True)
1516
property_id = fields.Many2one('estate.property', string="Property", required=True)
17+
# Related field for Stat Button logic
18+
property_type_id = fields.Many2one(related='property_id.property_type_id', string="Property Type", store=True)
1619

1720
validity = fields.Integer(string="Validity (days)", default=7)
1821
date_deadline = fields.Date(string="Deadline", compute='_compute_date_deadline', inverse='_inverse_date_deadline')

estate/models/estate_property_tag.py

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

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

1012
_name_check = models.Constraint('UNIQUE(name)', "The name must be unique.")
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
from odoo import fields, models
1+
from odoo import api, fields, models
22

33

44
class EstatePropertyTypeModel(models.Model):
55
_name = 'estate.property.type'
66
_description = "Real Estate property types database"
7-
7+
_order = 'sequence, name'
8+
89
name = fields.Char(required=True)
10+
sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.")
911

1012
_name_check = models.Constraint('UNIQUE(name)', "The name must be unique.")
13+
14+
# Inline view link
15+
property_ids = fields.One2many('estate.property', 'property_type_id')
16+
17+
# Stat button logic
18+
offer_ids = fields.One2many('estate.property.offer', 'property_type_id')
19+
offer_count = fields.Integer(compute='_compute_offer_count')
20+
21+
@api.depends('offer_ids')
22+
def _compute_offer_count(self):
23+
for record in self:
24+
record.offer_count = len(record.offer_ids)

estate/views/estate_property_offer_views.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<odoo>
3+
<record id="estate_property_offer_action" model="ir.actions.act_window">
4+
<field name="name">Property Offers</field>
5+
<field name="res_model">estate.property.offer</field>
6+
<field name="view_mode">list,form</field>
7+
<field name="domain">[('property_type_id', '=', active_id)]</field>
8+
</record>
9+
310
<record id="estate_property_offer_view_list" model="ir.ui.view">
411
<field name="name">estate.property.offer.list</field>
512
<field name="model">estate.property.offer</field>
613
<field name="arch" type="xml">
7-
<list string="Offers">
14+
<list string="Offers" editable="bottom"
15+
decoration-success="status == 'accepted'"
16+
decoration-danger="status == 'refused'">
817
<field name="price"/>
918
<field name="partner_id"/>
1019
<field name="validity"/>

estate/views/estate_property_tag_views.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<odoo>
3+
<record id="estate_property_tag_view_form" model="ir.ui.view">
4+
<field name="name">estate.property.tag.view.form</field>
5+
<field name="model">estate.property.tag</field>
6+
<field name="arch" type="xml">
7+
<form string="Property Tag">
8+
<sheet>
9+
<div class="oe_title">
10+
<h1 class="mb32">
11+
<field name="name" class="mb16" />
12+
</h1>
13+
</div>
14+
<field name="color" />
15+
</sheet>
16+
</form>
17+
</field>
18+
</record>
19+
320
<record id="estate_property_tag_action" model="ir.actions.act_window">
421
<field name="name">Property Tags</field>
522
<field name="res_model">estate.property.tag</field>

estate/views/estate_property_type_views.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,51 @@
55
<field name="res_model">estate.property.type</field>
66
<field name="view_mode">list,form</field>
77
</record>
8+
9+
<record id="estate_property_type_view_form" model="ir.ui.view">
10+
<field name="name">estate.property.type.form</field>
11+
<field name="model">estate.property.type</field>
12+
<field name="arch" type="xml">
13+
<form string="Property Type">
14+
<sheet>
15+
<div class="oe_button_box" name="button_box">
16+
<button name="%(estate.estate_property_offer_action)d"
17+
type="action"
18+
class="oe_stat_button"
19+
icon="oi-view-list"
20+
context="{'search_default_property_type_id': id}"
21+
invisible="offer_count == 0">
22+
<div class="o_stat_info">
23+
<field name="offer_count" class="o_stat_value"/>
24+
<span class="o_stat_text">Offers</span>
25+
</div>
26+
</button>
27+
</div>
28+
<h1><field name="name"/></h1>
29+
<notebook>
30+
<page string="Properties">
31+
<field name="property_ids" readonly="True">
32+
<list>
33+
<field name="name"/>
34+
<field name="expected_price"/>
35+
<field name="state"/>
36+
</list>
37+
</field>
38+
</page>
39+
</notebook>
40+
</sheet>
41+
</form>
42+
</field>
43+
</record>
44+
45+
<record id="estate_property_type_view_list" model="ir.ui.view">
46+
<field name="name">estate.property.type.view.list</field>
47+
<field name="model">estate.property.type</field>
48+
<field name="arch" type="xml">
49+
<list>
50+
<field name="sequence" widget="handle" />
51+
<field name="name" />
52+
</list>
53+
</field>
54+
</record>
855
</odoo>

estate/views/estate_property_views.xml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@
55
<field name="name">estate.property.list</field>
66
<field name="model">estate.property</field>
77
<field name="arch" type="xml">
8-
<list string="Properties">
8+
<list string="Properties"
9+
decoration-success="state in ['offer_received', 'offer_accepted']"
10+
decoration-info="state == 'offer_accepted'"
11+
decoration-muted="state == 'sold'">
912
<field name="name"/>
1013
<field name="postcode"/>
1114
<field name="bedrooms"/>
15+
<field name="property_type_id"/>
16+
<field name="date_availability" string="Available From" optional="hide"/>
17+
<field name="expected_price"/>
18+
<field name="selling_price"/>
19+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
20+
<field name="state" column_invisible="True"/>
1221
<field name="living_area" string="Living Area (sqm)"/>
1322
<field name="expected_price"/>
1423
<field name="selling_price"/>
15-
<field name="date_availability" string="Available From"/>
1624
</list>
1725
</field>
1826
</record>
@@ -23,27 +31,31 @@
2331
<field name="arch" type="xml">
2432
<form string="Property">
2533
<header>
26-
<button name="action_sold" type="object" string="Sold" statusbar_visible="new,offer_received,offer_accepted"/>
27-
<button name="action_cancel" type="object" string="Cancel" statusbar_visible="new,offer_received,offer_accepted"/>
34+
<button name="action_sold" type="object" string="Sold"
35+
invisible="(state == 'sold') or (state == 'cancelled')" />
36+
<button name="action_cancel" type="object" string="Cancel"
37+
invisible="(state == 'sold') or (state == 'cancelled')" />
2838
<field name="state" widget="statusbar" statusbar_visible="new,offer_received,offer_accepted,sold"/>
2939
</header>
3040
<sheet>
3141
<div class="oe_title">
3242
<h1>
3343
<field name="name"/>
3444
</h1>
35-
<field name="tag_ids" widget="many2many_tags"/>
45+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
3646
</div>
3747
<group>
3848
<group>
39-
<field name="state"/>
49+
<field name="property_type_id" widget="many2one"
50+
can_create="false" can_edit="false"
51+
option="{'no_create_edit': true}" />
4052
<field name="postcode"/>
41-
<field name="property_type_id"/>
53+
<field name="date_availability"/>
4254
</group>
4355
<group>
4456
<field name="expected_price"/>
45-
<field name="best_price"/> <field name="selling_price"/>
46-
<field name="date_availability"/>
57+
<field name="best_price"/>
58+
<field name="selling_price"/>
4759
</group>
4860
</group>
4961
<notebook>
@@ -55,8 +67,8 @@
5567
<field name="facades"/>
5668
<field name="garage"/>
5769
<field name="garden"/>
58-
<field name="garden_area"/>
59-
<field name="garden_orientation"/>
70+
<field name="garden_area" invisible="not garden"/>
71+
<field name="garden_orientation" invisible="not garden"/>
6072
<field name="total_area"/>
6173
</group>
6274
</page>
@@ -100,6 +112,7 @@
100112
<field name="name">Properties</field>
101113
<field name="res_model">estate.property</field>
102114
<field name="view_mode">list,form</field>
115+
<field name="context">{'search_default_available': 1}</field>
103116
<field name="help" type="html">
104117
<p class="o_view_nocontent_smiling_face">
105118
Create your first property advertisement!

0 commit comments

Comments
 (0)