Skip to content

Commit fe8cbbb

Browse files
[IMP] estate: add the sprinkles (ch 11)
1 parent 56e6200 commit fe8cbbb

9 files changed

+95
-18
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
'data': [
1616
'security/ir.model.access.csv',
1717
'views/estate_property_views.xml',
18-
'views/estate_property_type_views.xml',
1918
'views/estate_property_tag_views.xml',
2019
'views/estate_property_offer_views.xml',
20+
'views/estate_property_type_views.xml',
2121
'views/estate_menus.xml',
2222
],
2323
'license': 'LGPL-3',

estate/models/estate_property.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class EstateProperty(models.Model):
77
_name = "estate.property"
88
_description = "Estate properties"
9+
_order = "id desc"
910

1011
name = fields.Char('Title', required=True)
1112
description = fields.Text()

estate/models/estate_property_offer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
class EstatePropertyOffer(models.Model):
88
_name = "estate.property.offer"
99
_description = "Estate property offer"
10+
_order = "price desc"
1011

1112
price = fields.Float()
1213
status = fields.Selection(copy=False, selection=[('accepted', 'Accepted'), ('refused', 'Refused')])
1314
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
1415
property_id = fields.Many2one("estate.property", string="Property", required=True)
16+
property_type_id = fields.Many2one("estate.property.type", string="Property Type",
17+
related="property_id.property_type_id", store=True)
1518
validity = fields.Integer(string="Validity (days)", default=7)
1619
date_deadline = fields.Date(string="Deadline",
1720
compute="_compute_date_deadline",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import random
2+
13
from odoo import fields, models
24

35

46
class EstatePropertyTag(models.Model):
57
_name = "estate.property.tag"
68
_description = "Estate property tag"
9+
_order = "name"
10+
11+
def _get_default_color(self):
12+
return random.randint(0, 10)
713

814
name = fields.Char('Tag', required=True)
15+
color = fields.Integer(default=_get_default_color)
916

1017
_check_name = models.Constraint("UNIQUE(name)", "Tag name must be unique.")
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
from odoo import fields, models
1+
from odoo import api, fields, models
22

33

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

89
name = fields.Char('Type', required=True)
10+
sequence = fields.Integer('Sequence', default=1, help="Used to order types. Lower is better.")
11+
property_ids = fields.One2many("estate.property", "property_type_id", string="Properties")
12+
offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers")
13+
offer_count = fields.Integer(compute="_compute_offer_count")
914

1015
_check_name = models.Constraint("UNIQUE(name)", "Property type name must be unique.")
16+
17+
@api.depends("offer_ids")
18+
def _compute_offer_count(self):
19+
for record in self:
20+
record.offer_count = len(record.offer_ids)

estate/views/estate_property_offer_views.xml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
<odoo>
2+
<record id="estate_property_offer_action" model="ir.actions.act_window">
3+
<field name="name">Property Offers</field>
4+
<field name="res_model">estate.property.offer</field>
5+
<field name="view_mode">list,form</field>
6+
<field name="domain">[('property_type_id', '=', active_id)]</field>
7+
</record>
8+
29
<record id="estate_property_offer_view_list" model="ir.ui.view">
310
<field name="name">estate.property.offer.list</field>
411
<field name="model">estate.property.offer</field>
512
<field name="arch" type="xml">
6-
<list string="Offers">
13+
<list string="Offers" editable="bottom"
14+
decoration-danger="status=='refused'"
15+
decoration-success="status=='accepted'">
716
<field name="price"/>
817
<field name="partner_id"/>
918
<field name="validity"/>
1019
<field name="date_deadline"/>
11-
<button name="action_accept_offer" title="Accept" type="object" icon="fa-check"/>
12-
<button name="action_refuse_offer" title="Refuse" type="object" icon="fa-times"/>
13-
<field name="status"/>
20+
<button name="action_accept_offer" title="Accept" type="object" icon="fa-check" invisible="status"/>
21+
<button name="action_refuse_offer" title="Refuse" type="object" icon="fa-times" invisible="status"/>
1422
</list>
1523
</field>
1624
</record>

estate/views/estate_property_tag_views.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
<field name="view_mode">list,form</field>
66
</record>
77

8+
<record id="estate_property_tag_view_list" model="ir.ui.view">
9+
<field name="name">estate.property.tag.list</field>
10+
<field name="model">estate.property.tag</field>
11+
<field name="arch" type="xml">
12+
<list string="Tags" editable="top">
13+
<field name="name"/>
14+
</list>
15+
</field>
16+
</record>
17+
818
<record id="estate_property_tag_view_form" model="ir.ui.view">
919
<field name="name">estate.property.tag.form</field>
1020
<field name="model">estate.property.tag</field>

estate/views/estate_property_type_views.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,45 @@
55
<field name="view_mode">list,form</field>
66
</record>
77

8+
<record id="estate_property_type_view_list" model="ir.ui.view">
9+
<field name="name">estate.property.type.list</field>
10+
<field name="model">estate.property.type</field>
11+
<field name="arch" type="xml">
12+
<list string="Types">
13+
<field name="sequence" widget="handle"/>
14+
<field name="name"/>
15+
</list>
16+
</field>
17+
</record>
18+
819
<record id="estate_property_type_view_form" model="ir.ui.view">
920
<field name="name">estate.property.type.form</field>
1021
<field name="model">estate.property.type</field>
1122
<field name="arch" type="xml">
1223
<form string="Property type">
1324
<sheet>
25+
<div name="button_box" position="inside">
26+
<button class="oe_stat_button" type="action" name="estate.estate_property_offer_action"
27+
icon="fa-money" invisible="offer_count == 0">
28+
<field string="Offers" name="offer_count" widget="statinfo"/>
29+
</button>
30+
</div>
1431
<div class="oe_title">
1532
<h1 class="mb16">
1633
<field name="name"/>
1734
</h1>
1835
</div>
36+
<notebook>
37+
<page string="Properties">
38+
<field name="property_ids">
39+
<list delete="false">
40+
<field name="name"/>
41+
<field name="expected_price"/>
42+
<field name="state"/>
43+
</list>
44+
</field>
45+
</page>
46+
</notebook>
1947
</sheet>
2048
</form>
2149
</field>

estate/views/estate_property_views.xml

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
<field name="name">Properties</field>
44
<field name="res_model">estate.property</field>
55
<field name="view_mode">list,form</field>
6+
<field name="context">{'search_default_available': True}</field>
67
</record>
78

89
<record id="estate_property_view_list" model="ir.ui.view">
910
<field name="name">estate.property.list</field>
1011
<field name="model">estate.property</field>
1112
<field name="arch" type="xml">
12-
<list string="Properties">
13+
<list string="Properties"
14+
decoration-success="state in ('offer_received', 'offer_accepted')"
15+
decoration-bf="state=='offer_accepted'"
16+
decoration-muted="state=='sold'">
1317
<field name="name"/>
1418
<field name="property_type_id"/>
15-
<field name="tag_ids" widget="many2many_tags"/>
19+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
1620
<field name="postcode"/>
1721
<field name="bedrooms"/>
1822
<field name="living_area"/>
1923
<field name="expected_price"/>
2024
<field name="selling_price"/>
21-
<field name="date_availability"/>
25+
<field name="date_availability" optional="hide"/>
2226
</list>
2327
</field>
2428
</record>
@@ -32,7 +36,7 @@
3236
<field name="postcode"/>
3337
<field name="expected_price"/>
3438
<field name="bedrooms"/>
35-
<field name="living_area"/>
39+
<field name="living_area" filter_domain="[('living_area', '>=', self)]"/>
3640
<field name="facades"/>
3741
<field name="property_type_id"/>
3842
<filter name="available" string="Available"
@@ -48,8 +52,15 @@
4852
<field name="arch" type="xml">
4953
<form string="Property">
5054
<header>
51-
<button name="action_sold" type="object" string="Sold"/>
52-
<button name="action_cancel" type="object" string="Cancel"/>
55+
<button name="action_sold" type="object" string="Sold"
56+
invisible="state in ('offer_accepted', 'sold', 'cancelled')"/>
57+
<button name="action_sold" type="object" string="Sold" class="btn-primary"
58+
invisible="state != 'offer_accepted'"/>
59+
<button name="action_cancel" type="object" string="Cancel"
60+
invisible="state in ('sold', 'cancelled')"/>
61+
<field name="state" widget="statusbar"
62+
statusbar_visible="new,offer_received,offer_accepted,sold"
63+
options="{'clickable': '1'}"/>
5364
</header>
5465
<sheet>
5566
<div class="oe_title">
@@ -58,10 +69,9 @@
5869
</h1>
5970
</div>
6071
<group>
61-
<field name="tag_ids" widget="many2many_tags" class="mb16"/>
72+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}" class="mb16"/>
6273
<group>
63-
<field name="state"/>
64-
<field name="property_type_id"/>
74+
<field name="property_type_id" options="{'no_create': true, 'no_open': true}"/>
6575
<field name="postcode"/>
6676
<field name="date_availability"/>
6777
</group>
@@ -80,13 +90,13 @@
8090
<field name="facades"/>
8191
<field name="garage"/>
8292
<field name="garden"/>
83-
<field name="garden_area"/>
84-
<field name="garden_orientation"/>
93+
<field name="garden_area" invisible="not garden"/>
94+
<field name="garden_orientation" invisible="not garden"/>
8595
<field name="total_area"/>
8696
</group>
8797
</page>
8898
<page string="Offers">
89-
<field name="offer_ids"/>
99+
<field name="offer_ids" readonly="state in ('offer_accepted', 'sold', 'cancelled')"/>
90100
</page>
91101
<page string="Other info">
92102
<group>

0 commit comments

Comments
 (0)