Skip to content

Commit 063346e

Browse files
committed
[ADD] unittest property selling + garden fields reset
1 parent 6cc6856 commit 063346e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

estate/models/estate_property.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ def _onchange_garden(self):
102102
if not self.garden:
103103
self.garden_orientation = "north"
104104
self.garden_area = 10
105+
106+
@api.constrains("state")
107+
def _check_offers_state(self):
108+
self.ensure_one()
109+
if self.state == 'sold' and not [offer for offer in self.offer_ids if offer.status=='accepted']:
110+
raise exceptions.UserError("You cannot sold a property without accepted offer")
105111

106112
@api.constrains('selling_price', 'expected_price')
107113
def _check_date_end(self):

estate/tests/test_estate_property.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,29 @@ def test_offer_creation(self):
2020

2121
with self.assertRaises(UserError):
2222
self.env['estate.property.offer'].create({"price": 240000, "partner_id": self.partner.id, "property_id": self.properties.id})
23+
24+
def test_property_selling(self):
25+
"""Test that the property cannot be sold if no accepted offer."""
26+
with self.assertRaises(UserError):
27+
self.properties.state = 'sold'
28+
29+
self.env['estate.property.offer'].create({"price": 240000, "partner_id": self.partner.id, "property_id": self.properties.id, 'status': 'accepted'})
30+
self.properties.state = 'sold'
31+
32+
def test_garden_fields_reset(self):
33+
estate_property_form = Form(self.env['estate.property'].with_context({"name": "Test garden", "expected_price": 320000}))
34+
35+
estate_property_form.garden = True
36+
estate_property_form.garden_orientation = 'east'
37+
estate_property_form.garden_area = 120
38+
39+
self.assertEqual(estate_property_form.garden_orientation, "east")
40+
self.assertEqual(estate_property_form.garden_area, 120)
41+
42+
estate_property_form.garden = False
43+
self.assertEqual(estate_property_form.garden_orientation, "north")
44+
self.assertEqual(estate_property_form.garden_area, 10)
45+
46+
estate_property_form.garden = True
47+
self.assertEqual(estate_property_form.garden_orientation, "north")
48+
self.assertEqual(estate_property_form.garden_area, 10)

0 commit comments

Comments
 (0)