Skip to content

Commit 19e64f1

Browse files
committed
[ADD] unittest property selling + garden fields reset
[FIX] runbot style issues
1 parent b624327 commit 19e64f1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

estate/models/estate_property.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ def _onchange_garden(self):
103103
self.garden_orientation = "north"
104104
self.garden_area = 10
105105

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")
111+
106112
@api.constrains('selling_price', 'expected_price')
107113
def _check_date_end(self):
108114
for record in self:

estate/tests/test_estate_property.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class EstateTestCase(TransactionCase):
88

99
@classmethod
1010
def setUpClass(cls):
11-
super(EstateTestCase, cls).setUpClass()
11+
super().setUpClass()
1212

1313
cls.properties = cls.env['estate.property'].create({"name": "Test house", "expected_price": 240000})
1414
cls.partner = cls.env['res.partner'].create({"name": "Partner"})
@@ -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)