Skip to content

Commit d4b4165

Browse files
committed
[IMP] estate: added onchange method in the estate property model
1) Define _onchange_garden() to automatically set default garden_area and garden_orientation when the garden is enabled. 2) Clear these fields when the garden is disabled. 3) Add a warning notification when the garden checkbox is checked.
1 parent 41768c1 commit d4b4165

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

estate/models/estate_property.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class EstateProperty(models.Model):
1414
expected_price = fields.Float(string="Expected Price", required=True)
1515
selling_price = fields.Float(string="Selling Price", copy=False)
1616
bedrooms = fields.Integer(default=2)
17-
living_area = fields.Integer(string="Living Area (spm)")
17+
living_area = fields.Float(string="Living Area (spm)")
1818
facades = fields.Integer()
1919
garage = fields.Boolean()
2020
garden = fields.Boolean()
21-
garden_area = fields.Integer(string="Garden Area (spm)")
21+
garden_area = fields.Float(string="Garden Area (spm)")
2222
total_area = fields.Float(string="Total Area (sqm)", compute="_computed_total_area")
2323
garden_orientation = fields.Selection([
2424
('north', "North"),
@@ -48,13 +48,29 @@ def _computed_total_area(self):
4848

4949
@api.depends("offer_ids.price")
5050
def _computed_best_offer(self):
51-
for rec in self:
52-
prices = rec.offer_ids.mapped("price")
53-
rec.best_price = max(prices) if prices else 0.0
51+
prices = self.offer_ids.mapped("price")
52+
self.best_price = max(prices) if prices else 0.0
5453

5554
def _search_best_offer(self, operator, value):
5655
return [
5756
'&',
5857
('offer_ids.price', '>', 10000),
5958
('offer_ids.price', operator, value)
6059
]
60+
61+
@api.onchange("garden")
62+
def _onchange_garden(self):
63+
if self.garden:
64+
self.garden_area = 10
65+
self.garden_orientation = 'north'
66+
67+
return {
68+
'warning': {
69+
'title': "Garden Enabled",
70+
'message': "Default area set to 10 and orientation north",
71+
'type': "notification"
72+
}
73+
}
74+
else:
75+
self.garden_area = 0
76+
self.garden_orientation = False

0 commit comments

Comments
 (0)