Skip to content

Commit 5499b35

Browse files
committed
[FIX] estate: chapter 9 (actions)
1 parent f1335d4 commit 5499b35

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed

estate/__manifest__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
""",
1010
'data': [
1111
'security/ir.model.access.csv',
12-
1312
'views/estate_property_views.xml',
1413
'views/estate_property_type_views.xml',
1514
'views/estate_property_tag_views.xml',

estate/models/estate_property.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Part of Odoo. See LICENSE file for full copyright and licensing details.
22

33
from odoo import fields, models, api, exceptions
4-
from datetime import timedelta
54

65

76
class EstateProperty(models.Model):
@@ -12,7 +11,7 @@ class EstateProperty(models.Model):
1211
active = fields.Boolean('Active', default=True)
1312
description = fields.Text('Description')
1413
postcode = fields.Char('Postcode')
15-
date_availability = fields.Date('Available From', copy=False, default=fields.Datetime.now() + timedelta(days=90))
14+
date_availability = fields.Date('Available From', copy=False, default=fields.Date.add(fields.Date.today(), months=3))
1615
expected_price = fields.Float('Expected Price', required=True)
1716
selling_price = fields.Float('Selling Price', readonly=True, copy=False)
1817
bedrooms = fields.Integer('Bedrooms', default=2)
@@ -44,6 +43,16 @@ class EstateProperty(models.Model):
4443
total_area = fields.Integer('Total Area (sqm)', compute='_compute_total_area')
4544
best_offer = fields.Float('Best Offer', compute='_compute_best_offer')
4645

46+
_check_expected_price = models.Constraint(
47+
'CHECK(expected_price > 0)',
48+
'The expected price must be strictly positive',
49+
)
50+
51+
_check_selling_price = models.Constraint(
52+
'CHECK(selling_price >= 0)',
53+
'The selling price must be positive',
54+
)
55+
4756
@api.depends('garden_area', 'living_area')
4857
def _compute_total_area(self):
4958
for record in self:
@@ -68,16 +77,16 @@ def _onchange_garden(self):
6877

6978
def property_sold(self):
7079
for record in self:
71-
if self.state != 'cancelled':
72-
self.state = 'sold'
80+
if record.state != 'cancelled':
81+
record.state = 'sold'
7382
else:
7483
raise exceptions.UserError("Sold properties cannot be cancelled.")
7584
return True
7685

7786
def property_cancelled(self):
7887
for record in self:
79-
if self.state != 'sold':
80-
self.state = 'cancelled'
88+
if record.state != 'sold':
89+
record.state = 'cancelled'
8190
else:
8291
raise exceptions.UserError("Cancelled properties cannot be sold.")
8392
return True

estate/models/estate_property_offer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class EstatePropertyOffer(models.Model):
1616
validity = fields.Integer(string='Validity (days)', default=7)
1717
date_deadline = fields.Date(string='Deadline', compute='_compute_deadline', inverse='_inverse_deadline')
1818

19+
_check_price = models.Constraint(
20+
'CHECK(price > 0)',
21+
'The offer price must be strictly positive',
22+
)
23+
1924
@api.depends('validity')
2025
def _compute_deadline(self):
2126
for record in self:

estate/models/estate_property_tag.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ class EstatePropertyTag(models.Model):
88
_description = 'Estate Property Tag'
99

1010
name = fields.Char(string='Property Tag', required=True)
11+
12+
_tag_name_uniq = models.Constraint(
13+
'unique(name)',
14+
"The property tag name must be unique",
15+
)

estate/models/estate_property_type.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ class EstatePropertyType(models.Model):
88
_description = 'Estate Property Type'
99

1010
name = fields.Char(string='Property Type', required=True)
11+
12+
_type_name_uniq = models.Constraint(
13+
'unique(name)',
14+
"The property type name must be unique",
15+
)

estate/views/estate_menus.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
id="properties_menu"
88
name="Properties"
99
parent="estate_menu_root"
10-
action="estate.estate_property_action"
10+
action="estate_property_action"
1111
sequence="1"/>
1212
<menuitem
1313
id="settings_menu"
@@ -18,12 +18,12 @@
1818
id="properties_type_menu"
1919
name="Property Types"
2020
parent="settings_menu"
21-
action="estate.estate_property_type_action"
21+
action="estate_property_type_action"
2222
sequence="1"/>
2323
<menuitem
2424
id="properties_tag_menu"
2525
name="Property Tags"
2626
parent="settings_menu"
27-
action="estate.estate_property_tag_action"
27+
action="estate_property_tag_action"
2828
sequence="2"/>
2929
</odoo>

0 commit comments

Comments
 (0)