Skip to content

Commit e61da11

Browse files
committed
[REF] estate: Chapter 15
1 parent cfe3d45 commit e61da11

11 files changed

+64
-39
lines changed

estate/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'views/estate_property_offer_views.xml',
1414
'views/estate_property_types_views.xml',
1515
'views/estate_property_tags_views.xml',
16-
'views/estate_salesman_view.xml',
16+
'views/res_user_views.xml',
1717
'views/estate_menus.xml',
1818
],
1919
'author': 'Odoo S.A.',

estate/models/estate_property.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ class EstateProperty(models.Model):
55
_name = 'estate.property'
66
_description = 'Estate properties'
77
_order = 'id desc'
8-
_check_name = models.Constraint('UNIQUE(name)', 'Property name must be unique')
9-
_check_expected_price = models.Constraint('CHECK(expected_price > 0)', 'Expected price must be positive')
10-
_check_selling_price = models.Constraint('CHECK(selling_price >= 0)', 'Selling price cannot be negative')
11-
_check_bedrooms = models.Constraint('CHECK(bedrooms >= 0)', 'Bedrooms cannot be negative')
12-
_check_living_area = models.Constraint('CHECK(living_area >= 0)', 'Living area cannot be negative')
13-
_check_facades = models.Constraint('CHECK(facades >= 0)', 'Facades cannot be negative')
14-
_check_garden_area = models.Constraint('CHECK(garden_area >= 0)', 'Garden area cannot be negative')
158

169
name = fields.Char('Name', required=True)
1710
description = fields.Char('Description')
@@ -43,11 +36,13 @@ class EstateProperty(models.Model):
4336
total_area = fields.Integer('Total Area', compute='_compute_total_area')
4437
best_price = fields.Float('Best Offer', compute='_compute_best_price')
4538

46-
@api.constrains('selling_price')
47-
def _check_selling_price_within_range(self):
48-
for record in self:
49-
if not tools.float_utils.float_is_zero(record.selling_price, 2) and record.selling_price < 0.9 * record.expected_price:
50-
raise exceptions.ValidationError('Selling price cannot be lower than 90% of the expected price')
39+
_check_name = models.Constraint('UNIQUE(name)', 'Property name must be unique')
40+
_check_expected_price = models.Constraint('CHECK(expected_price > 0)', 'Expected price must be positive')
41+
_check_selling_price = models.Constraint('CHECK(selling_price >= 0)', 'Selling price cannot be negative')
42+
_check_bedrooms = models.Constraint('CHECK(bedrooms >= 0)', 'Bedrooms cannot be negative')
43+
_check_living_area = models.Constraint('CHECK(living_area >= 0)', 'Living area cannot be negative')
44+
_check_facades = models.Constraint('CHECK(facades >= 0)', 'Facades cannot be negative')
45+
_check_garden_area = models.Constraint('CHECK(garden_area >= 0)', 'Garden area cannot be negative')
5146

5247
@api.depends('garden_area', 'living_area')
5348
def _compute_total_area(self):
@@ -65,6 +60,12 @@ def _onchange_garden(self):
6560
record.garden_area = (10 if record.garden else 0)
6661
record.garden_orientation = ('north' if record.garden else None)
6762

63+
@api.constrains('selling_price')
64+
def _check_selling_price(self):
65+
for record in self:
66+
if not tools.float_utils.float_is_zero(record.selling_price, 2) and record.selling_price < 0.9 * record.expected_price:
67+
raise exceptions.ValidationError('Selling price cannot be lower than 90% of the expected price')
68+
6869
@api.ondelete(at_uninstall=False)
6970
def _property_delete(self):
7071
if self.state != 'new' and self.state != 'cancelled':

estate/models/estate_property_offer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class EstatePropertyOffer(models.Model):
55
_name = 'estate.property.offer'
66
_description = 'An offer placed on some property'
77
_order = 'price desc'
8-
_check_price = models.Constraint('CHECK(price > 0)', 'Price must be positive')
98

109
price = fields.Float('Price')
1110
status = fields.Selection(
@@ -19,6 +18,8 @@ class EstatePropertyOffer(models.Model):
1918
date_deadline = fields.Date('Deadline', compute='_compute_deadline', inverse='_compute_validity')
2019
property_type_id = fields.Many2one('estate.property.type', related='property_id.property_type_id', store=True)
2120

21+
_check_price = models.Constraint('CHECK(price > 0)', 'Price must be positive')
22+
2223
@api.depends('validity')
2324
def _compute_deadline(self):
2425
for record in self:

estate/models/estate_property_tag.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class EstatePropertyTag(models.Model):
55
_name = 'estate.property.tag'
66
_description = 'Real estate property tags'
77
_order = 'name'
8-
_check_name = models.Constraint('UNIQUE(name)', 'Tag name must be unique')
98

109
name = fields.Char('Name', required=True)
1110
color = fields.Integer('Color')
11+
12+
_check_name = models.Constraint('UNIQUE(name)', 'Tag name must be unique')

estate/models/estate_property_type.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ class EstatePropertyType(models.Model):
55
_name = 'estate.property.type'
66
_description = 'The types available for properties/real estates'
77
_order = 'name'
8-
_check_name = models.Constraint('UNIQUE(name)', 'Property type name must be unique')
98

109
name = fields.Char('Name', required=True)
1110
sequence = fields.Integer('Sequence', default=1)
1211
property_ids = fields.One2many('estate.property', 'property_type_id')
1312
offer_ids = fields.One2many('estate.property.offer', 'property_type_id')
1413
offer_count = fields.Integer(string='Offers Count', compute='_compute_offer_count')
1514

15+
_check_name = models.Constraint('UNIQUE(name)', 'Property type name must be unique')
16+
1617
@api.depends('offer_ids')
1718
def _compute_offer_count(self):
1819
for record in self:

estate/views/estate_menus.xml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
<odoo>
2-
<menuitem id='estate_menu_root' name='Real Estate'>
3-
<menuitem id='estate_menu_advertisements' name='Advertisements'>
4-
<menuitem id='estate_advertisements_listings' name='Properties' action='estate_property_action'/>
5-
</menuitem>
6-
<menuitem id='estate_menu_settings' name='Settings'>
7-
<menuitem id='estate_property_types' name='Property Types' action='estate_property_types_action'/>
8-
<menuitem id='estate_property_tags' name='Property Tags' action='estate_property_tag_action'/>
9-
</menuitem>
10-
</menuitem>
2+
<menuitem
3+
id='estate_property_menu_root'
4+
name='Real Estate'
5+
/>
6+
<menuitem
7+
id='estate_property_menu_advertisements'
8+
name='Advertisements'
9+
parent='estate_property_menu_root'
10+
/>
11+
<menuitem
12+
id='estate_property_menu_properties'
13+
name='Properties'
14+
parent='estate_property_menu_advertisements'
15+
action='estate_property_action'
16+
/>
17+
<menuitem
18+
id='estate_property_menu_settings'
19+
name='Settings'
20+
parent='estate_property_menu_root'
21+
/>
22+
<menuitem
23+
id='estate_property_menu_types'
24+
name='Property Types'
25+
parent='estate_property_menu_settings'
26+
action='estate_property_types_action'
27+
/>
28+
<menuitem
29+
id='estate_property_menu_tags'
30+
name='Property Tags'
31+
parent='estate_property_menu_settings'
32+
action='estate_property_tag_action'
33+
/>
1134
</odoo>

estate/views/estate_property_offer_views.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<odoo>
2-
<record id='estate_list_offer_view' model='ir.ui.view'>
2+
<record id='estate_property_offer_view_list' model='ir.ui.view'>
33
<field name='name'>real.estate.offer.list</field>
44
<field name='model'>estate.property.offer</field>
55
<field name='arch' type='xml'>
@@ -8,14 +8,13 @@
88
<field name='partner_id'/>
99
<field name='validity'/>
1010
<field name='date_deadline'/>
11-
<button name='accept_offer' type='object' class='fa fa-check' invisible='status'/>
12-
<button name='reject_offer' type='object' class='oi oi-close' invisible='status'/>
13-
<field name='status' column_invisible='True'/>
11+
<button name='accept_offer' title='Accept Offer' type='object' icon='fa-check' invisible='status'/>
12+
<button name='reject_offer' title='Reject Offer' type='object' icon='oi-close' invisible='status'/>
1413
</list>
1514
</field>
1615
</record>
1716

18-
<record id='estate_form_offer_view' model='ir.ui.view'>
17+
<record id='estate_property_offer_view_form' model='ir.ui.view'>
1918
<field name='name'>real.estate.offer.form</field>
2019
<field name='model'>estate.property.offer</field>
2120
<field name='arch' type='xml'>
@@ -26,7 +25,6 @@
2625
<field name='partner_id'/>
2726
<field name='validity'/>
2827
<field name='date_deadline'/>
29-
<field name='status' invisible='True'/>
3028
</group>
3129
</sheet>
3230
</form>

estate/views/estate_property_tags_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<odoo>
2-
<record id='estate_property_tag_list' model='ir.ui.view'>
2+
<record id='estate_property_tag_view_list' model='ir.ui.view'>
33
<field name='name'>Real Estate Tags</field>
44
<field name='model'>estate.property.tag</field>
55
<field name='arch' type='xml'>

estate/views/estate_property_types_views.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<odoo>
2-
<record id='estate_property_types_list' model='ir.ui.view'>
2+
<record id='estate_property_types_view_list' model='ir.ui.view'>
33
<field name='name'>Real Estate Types</field>
44
<field name='model'>estate.property.type</field>
55
<field name='arch' type='xml'>
@@ -10,14 +10,14 @@
1010
</field>
1111
</record>
1212

13-
<record id='estate_property_types_form' model='ir.ui.view'>
13+
<record id='estate_property_types_view_form' model='ir.ui.view'>
1414
<field name='name'>Real Estate Types</field>
1515
<field name='model'>estate.property.type</field>
1616
<field name='arch' type='xml'>
1717
<form>
1818
<sheet>
1919
<div class="oe_button_box" name="button_box">
20-
<button type='action' name='%(estate_property_offer_action)d' class='oe_stat_button' icon='fa-money'>
20+
<button name='%(estate_property_offer_action)d' type='action' class='oe_stat_button' icon='fa-money'>
2121
<div class='o_stat_info'>
2222
<field name='offer_count' class='o_stat_value'/>
2323
<span class='o_stat_text'>Offers</span>

estate/views/estate_property_views.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<odoo>
2-
<record id='estate_list_view' model='ir.ui.view'>
2+
<record id='estate_property_view_list' model='ir.ui.view'>
33
<field name='name'>real.estate.list</field>
44
<field name='model'>estate.property</field>
55
<field name='arch' type='xml'>
@@ -15,7 +15,7 @@
1515
</field>
1616
</record>
1717

18-
<record id='estate_form_view' model='ir.ui.view'>
18+
<record id='estate_property_view_form' model='ir.ui.view'>
1919
<field name='name'>real.estate.form</field>
2020
<field name='model'>estate.property</field>
2121
<field name='arch' type='xml'>
@@ -75,7 +75,7 @@
7575
</field>
7676
</record>
7777

78-
<record id='estate_kanban_view' model='ir.ui.view'>
78+
<record id='estate_property_view_kanban' model='ir.ui.view'>
7979
<field name='name'>real.estate.kanban</field>
8080
<field name='model'>estate.property</field>
8181
<field name='arch' type='xml'>
@@ -103,7 +103,7 @@
103103
</field>
104104
</record>
105105

106-
<record id='estate_search' model='ir.ui.view'>
106+
<record id='estate_property_view_search' model='ir.ui.view'>
107107
<field name='name'>real.estate.search</field>
108108
<field name='model'>estate.property</field>
109109
<field name='arch' type='xml'>

0 commit comments

Comments
 (0)