Skip to content

Commit db7d901

Browse files
committed
[IMP] estate: implement chapter 10 & 11
1 parent 11ab1a4 commit db7d901

8 files changed

+89
-53
lines changed

Diff for: estate/models/property.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
from dateutil.relativedelta import relativedelta
22

33
from odoo import models, fields, api
4-
from odoo.exceptions import UserError
4+
from odoo.exceptions import UserError, ValidationError
5+
from odoo.tools import float_is_zero, float_compare
56

67

78
class Property(models.Model):
89
_name = 'estate.property'
910
_description = 'Property'
11+
_sql_constraints = [
12+
('check_expected_price', 'CHECK(expected_price > 0)', 'The Expected Price must be positive.'),
13+
('check_selling_price', 'CHECK(selling_price >= 0)', 'The Selling Price must be positive.'),
14+
('check_bedrooms', 'CHECK(bedrooms >= 0)', 'The number of bedrooms must be positive.'),
15+
('check_living_area', 'CHECK(living_area > 0)', 'The living area must be positive.'),
16+
('check_facades', 'CHECK(facades > 0)', 'The number of facades must be positive.'),
17+
('check_name_unique', 'UNIQUE(name)', 'The Property name must be unique.')
18+
]
19+
_order = 'id desc'
1020

1121
name = fields.Char(string='Title', required=True)
1222
description = fields.Text()
@@ -65,6 +75,14 @@ def _onchange_garden(self):
6575
self.garden_orientation = None
6676
self.garden_area = 0
6777

78+
@api.constrains('selling_price', 'expected_price')
79+
def _check_date_end(self):
80+
for record in self:
81+
if not float_is_zero(record.selling_price, precision_digits=2) and float_compare(record.selling_price,
82+
0.9 * record.expected_price,
83+
precision_digits=2) >= 0:
84+
raise ValidationError("The selling price must not be below 90% of the expected price.")
85+
6886
def action_sold(self):
6987
for record in self:
7088
if record.state in ['sold', 'canceled']:

Diff for: estate/models/property_offer.py

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
class PropertyOffer(models.Model):
77
_name = 'estate.property.offer'
88
_description = 'Property Offer'
9+
_sql_constraints = [
10+
('check_offer_price', 'CHECK(price > 0)', 'The Offer Price must be positive.'),
11+
('check_validity', 'CHECK(validity >= 0)', 'The Offer Validity must be positive.'),
12+
]
13+
_order = 'price desc'
914

1015
state = fields.Selection([
1116
('received', 'Received'),
@@ -19,6 +24,7 @@ class PropertyOffer(models.Model):
1924
validity = fields.Integer(string='Validity (days)', default=7)
2025
deadline_date = fields.Date(string='Deadline Date', compute='_compute_deadline_date',
2126
inverse='_inverse_deadline_date')
27+
property_type_id = fields.Many2one('estate.property.type', related='property_id.property_type_id')
2228

2329
@api.depends('validity', 'deadline_date', 'create_date')
2430
def _compute_deadline_date(self):

Diff for: estate/models/property_tag.py

+5
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
class PropertyTag(models.Model):
55
_name = 'estate.property.tag'
66
_description = 'Property Tag'
7+
_sql_constraints = [
8+
('check_name_unique', 'UNIQUE(name)', 'The Tag name must be unique.')
9+
]
10+
_order = 'name asc'
711

812
name = fields.Char(string='Tag', required=True)
13+
color = fields.Integer(string='Color')

Diff for: estate/models/property_type.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
from odoo import models, fields
1+
from odoo import models, fields, api
22

33

44
class PropertyType(models.Model):
55
_name = 'estate.property.type'
66
_description = 'Property Type'
7+
_sql_constraints = [
8+
('check_name_unique', 'UNIQUE(name)', 'The type name must be unique.')
9+
]
10+
_order = 'sequence asc, name asc'
711

812
name = fields.Char(string='Title', required=True)
13+
sequence = fields.Integer('Sequence', default=1)
14+
property_ids = fields.One2many('estate.property', 'property_type_id')
15+
offer_ids = fields.One2many('estate.property.offer', 'property_type_id')
16+
offer_count = fields.Integer(compute='_compute_offer_count')
17+
18+
@api.depends('offer_ids')
19+
def _compute_offer_count(self):
20+
for record in self:
21+
record.offer_count = len(record.offer_ids)

Diff for: estate/views/estate_property_offer_views.xml

+6-25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<field name="name">estate.property.offer.list</field>
55
<field name="model">estate.property.offer</field>
66
<field name="arch" type="xml">
7-
<list string="Property offers">
7+
<list string="Property offers" editable="bottom">
88
<field name="price" optional="show"/>
99
<field name="partner_id"/>
1010
<field name="deadline_date" optional="show"/>
@@ -22,29 +22,10 @@
2222
</field>
2323
</record>
2424

25-
<record id="estate_property_offer_view_form" model="ir.ui.view">
26-
<field name="name">estate.property.offer.form</field>
27-
<field name="model">estate.property.offer</field>
28-
<field name="arch" type="xml">
29-
<form string="Property offers">
30-
<header>
31-
<button name="action_accept" invisible="state in ['accepted', 'refused']" string="Accept"
32-
type="object" class="btn-primary"/>
33-
<button name="action_refuse" invisible="state in ['accepted', 'refused']" string="Refuse"
34-
type="object"/>
35-
<button name="action_reset" invisible="state not in ['accepted', 'refused']" string="Reset"
36-
type="object"/>
37-
</header>
38-
<sheet>
39-
<group>
40-
<field name="price"/>
41-
<field name="partner_id"/>
42-
<field name="deadline_date"/>
43-
<field name="validity"/>
44-
<field name="state"/>
45-
</group>
46-
</sheet>
47-
</form>
48-
</field>
25+
<record id="estate_property_offer_action" model="ir.actions.act_window">
26+
<field name="name">Property Types</field>
27+
<field name="res_model">estate.property.offer</field>
28+
<field name="domain">[('property_type_id', '=', active_id)]</field>
29+
<field name="view_mode">list</field>
4930
</record>
5031
</odoo>

Diff for: estate/views/estate_property_tag_views.xml

+2-18
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,12 @@
44
<field name="name">estate.property.tag.list</field>
55
<field name="model">estate.property.tag</field>
66
<field name="arch" type="xml">
7-
<list string="Property tags">
7+
<list string="Property tags" editable="bottom">
88
<field name="name"/>
99
</list>
1010
</field>
1111
</record>
1212

13-
<record id="estate_property_tag_view_form" model="ir.ui.view">
14-
<field name="name">estate.property.tag.form</field>
15-
<field name="model">estate.property.tag</field>
16-
<field name="arch" type="xml">
17-
<form string="Property tags">
18-
<sheet>
19-
<div class="oe_title">
20-
<h1>
21-
<field name="name"/>
22-
</h1>
23-
</div>
24-
</sheet>
25-
</form>
26-
</field>
27-
</record>
28-
2913
<record id="estate_property_tag_view_filter" model="ir.ui.view">
3014
<field name="name">estate.property.tag.list.select</field>
3115
<field name="model">estate.property.tag</field>
@@ -39,6 +23,6 @@
3923
<record id="estate_property_tag_action" model="ir.actions.act_window">
4024
<field name="name">Property tags</field>
4125
<field name="res_model">estate.property.tag</field>
42-
<field name="view_mode">list,form</field>
26+
<field name="view_mode">list</field>
4327
</record>
4428
</odoo>

Diff for: estate/views/estate_property_type_views.xml

+27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<field name="model">estate.property.type</field>
66
<field name="arch" type="xml">
77
<list string="Property Types">
8+
<field name="sequence" widget="handle"/>
89
<field name="name"/>
910
</list>
1011
</field>
@@ -16,11 +17,37 @@
1617
<field name="arch" type="xml">
1718
<form string="Property Types">
1819
<sheet>
20+
<div class="oe_button_box" name="button_box">
21+
<button class="oe_stat_button" type="action" name="estate.estate_property_offer_action"
22+
icon="fa-envelope">
23+
<field string="Offers" name="offer_count" widget="statinfo"/>
24+
</button>
25+
</div>
1926
<div class="oe_title">
2027
<h1>
2128
<field name="name"/>
2229
</h1>
2330
</div>
31+
<notebook>
32+
<page string="Properties">
33+
<field name="property_ids">
34+
<list>
35+
<field name="name"/>
36+
<field name="postcode" optional="hide"/>
37+
<field name="bedrooms" optional="hide"/>
38+
<field name="living_area" optional="hide"/>
39+
<field name="expected_price" optional="show"/>
40+
<field name="selling_price" optional="hide"/>
41+
<field name="date_availability" optional="hide"/>
42+
<field name="state" widget="badge"
43+
decoration-info="state == 'offer_received'"
44+
decoration-success="state in ['sold', 'offer_accepted']"
45+
decoration-danger="state == 'canceled'"
46+
optional="show"/>
47+
</list>
48+
</field>
49+
</page>
50+
</notebook>
2451
</sheet>
2552
</form>
2653
</field>

Diff for: estate/views/estate_property_views.xml

+10-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<field name="name"/>
99
<field name="property_type_id" optional="show"/>
1010
<field name="postcode" optional="show"/>
11+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}" optional="show"/>
1112
<field name="bedrooms" optional="hide"/>
1213
<field name="living_area" optional="hide"/>
1314
<field name="expected_price" optional="show"/>
@@ -43,11 +44,11 @@
4344
</h1>
4445
</div>
4546
<div class="mb-3">
46-
<field name="tag_ids" widget="many2many_tags"/>
47+
<field name="tag_ids" widget="form.many2many_tags" options="{'color_field': 'color'}"/>
4748
</div>
4849
<group>
4950
<group>
50-
<field name="property_type_id"/>
51+
<field name="property_type_id" can_create="False" can_write="False"/>
5152
<field name="postcode"/>
5253
<field name="date_availability"/>
5354
</group>
@@ -66,8 +67,8 @@
6667
<field name="facades"/>
6768
<field name="garage"/>
6869
<field name="garden"/>
69-
<field name="garden_area"/>
70-
<field name="garden_orientation"/>
70+
<field name="garden_area" invisible="not garden"/>
71+
<field name="garden_orientation" invisible="not garden"/>
7172
<field name="total_area"/>
7273
</group>
7374
</page>
@@ -94,10 +95,10 @@
9495
<search string="Search Property">
9596
<field name="name"/>
9697
<field name="postcode"/>
97-
<field name="expected_price"/>
98-
<field name="bedrooms"/>
99-
<field name="living_area"/>
100-
<field name="facades"/>
98+
<field name="expected_price" filter_domain="[('living_area', '>=', self)]"/>
99+
<field name="bedrooms" filter_domain="[('living_area', '>=', self)]"/>
100+
<field name="living_area" filter_domain="[('living_area', '>=', self)]"/>
101+
<field name="facades" filter_domain="[('living_area', '>=', self)]"/>
101102

102103
<filter name="available" string="Available"
103104
domain="[('date_availability', '&lt;=', context_today().strftime('%Y-%m-%d'))]"/>
@@ -115,5 +116,6 @@
115116
<field name="name">Properties</field>
116117
<field name="res_model">estate.property</field>
117118
<field name="view_mode">list,form</field>
119+
<field name="context">{'search_default_available': True}</field>
118120
</record>
119121
</odoo>

0 commit comments

Comments
 (0)