Skip to content

Commit e66f5d0

Browse files
committed
[IMP] estate: Ch 10
1 parent 791378e commit e66f5d0

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

estate/models/estate_property.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import date
33
from dateutil.relativedelta import relativedelta
44
from odoo.exceptions import UserError
5+
from odoo.tools import float_compare
56

67

78
class EstateProperty(models.Model):
@@ -14,8 +15,8 @@ class EstateProperty(models.Model):
1415
postcode = fields.Char()
1516
state = fields.Text()
1617
date_availability = fields.Date(copy=False, readonly=True, default=lambda self: date.today() + relativedelta(months=3))
17-
expected_price = fields.Float(required=True)
18-
selling_price = fields.Float(readonly=True, copy=False)
18+
expected_price = fields.Float("Expected Price", required=True)
19+
selling_price = fields.Float("Selling Price", readonly=True, copy=False)
1920
bedrooms = fields.Integer(default=2)
2021
living_area = fields.Integer(string='Living Area (m2)')
2122
facades = fields.Integer()
@@ -83,3 +84,17 @@ def _onchange_garden(self):
8384
else:
8485
self.garden_area = 0
8586
self.garden_orientation = False
87+
88+
_check_expected_price = models.Constraint(
89+
'CHECK(expected_price >= 0)', 'The expected price must be strictly positive.')
90+
91+
_check_selling_price = models.Constraint(
92+
'CHECK(selling_price > 0)', 'The selling price must be positive.')
93+
94+
@api.constrains('selling_price', 'expected_price')
95+
def _check_selling_price_expected_price(self):
96+
for record in self:
97+
if record.selling_price == 0:
98+
continue
99+
if float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=2) == -1:
100+
raise UserError("The selling price must be at least 90% of the expected price.")

estate/models/estate_property_offer.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
from dateutil.relativedelta import relativedelta
33
from odoo.exceptions import UserError
44

5+
56
class EstatePropertyOffer(models.Model):
67
_name = 'estate.property.offer'
78
_description = 'Estate Property Offer'
89

910
price = fields.Float(string='price', required=True)
10-
status = fields.Selection(selection=[('accepted', 'Accepted'),
11+
state = fields.Selection(selection=[('accepted', 'Accepted'),
1112
('refused', 'Refused')],
1213
string="Status",
1314
copy=False,
@@ -30,16 +31,16 @@ def _compute_date_deadline(self):
3031

3132
def action_accept(self):
3233
for offer in self:
33-
if offer.state != 'Refused':
34-
offer.state = 'Accepted'
34+
if offer.state != 'refused':
35+
offer.state = 'accepted'
3536
else:
3637
raise UserError("A refused offer cannot be accepted.")
3738
return True
3839

3940
def action_refuse(self):
4041
for offer in self:
41-
if offer.state != 'Accepted':
42-
offer.state = 'Refused'
42+
if offer.state != 'accepted':
43+
offer.state = 'refused'
4344
else:
4445
raise UserError("An accepted offer cannot be refused.")
45-
return True
46+
return True

estate/views/estate_property_views.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
</group>
5252
<group>
5353
<field name="expected_price"/>
54+
<field name="best_price"/>
5455
<field name="selling_price"/>
5556
</group>
5657
</group>
@@ -82,7 +83,7 @@
8283
<list>
8384
<field name="partner_id"/>
8485
<field name="price"/>
85-
<field name="status"/>
86+
<field name="state"/>
8687
<field name="validity"/>
8788
<field name="date_deadline"/>
8889
<button name="action_accept" type="object" icon="fa-check" title="Accept"/>
@@ -91,7 +92,7 @@
9192
<form>
9293
<field name="partner_id"/>
9394
<field name="price"/>
94-
<field name="status"/>
95+
<field name="state"/>
9596
<field name="validity"/>
9697
<field name="date_deadline"/>
9798
</form>

0 commit comments

Comments
 (0)