Skip to content

Commit fcaef25

Browse files
committed
[ADD] estate: add unit tests for property business logic
Introduced new unit tests in the estate module covering key business processes: Prevent offer creation on sold properties., Disallow marking properties as sold without an accepted offer., Ensure garden area and orientation fields reset appropriately when garden is unchecked. These tests improve the reliability and maintainability of the estate workflow.
1 parent db8e46e commit fcaef25

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

estate/models/estate_property.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ def _onchange_garden_status(self):
131131
def action_sell_property(self):
132132
# dictionary for the property status
133133
property_sell_status_dict = {"new": True, "sold": True, "cancelled": False}
134-
135134
for record in self:
135+
if self.state != "offer_accepted":
136+
raise UserError("Property has no offer yet!!!")
136137
if property_sell_status_dict[record.status]:
137138
record.status = "sold"
138139
record.state = "sold"

estate/models/estate_property_offer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ def create(self, vals):
9797
value.get("property_id")
9898
)
9999
for property_data in property_details:
100+
if property_data.state == "sold":
101+
raise UserError("Cannot create offer for sold property!!!")
100102
offers_list = property_data.mapped("offer_ids.price")
101103
max_offer = max(offers_list, default=0)
102104
comparison_result = float_compare(

estate/tests/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from . import test_estate_property

estate/tests/test_estate_property.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
from odoo.tests.common import TransactionCase
2+
from odoo.tests import tagged, Form
3+
from odoo.exceptions import UserError
4+
5+
6+
@tagged("post_install", "-at_install")
7+
class TestEstateProperty(TransactionCase):
8+
@classmethod
9+
def setUpClass(cls):
10+
super().setUpClass()
11+
cls.property_type = cls.env["estate.property.type"].create(
12+
{"name": "House Test Type"}
13+
)
14+
15+
cls.properties = cls.env["estate.property"].create(
16+
[
17+
{
18+
"name": "Sale Test Property",
19+
"description": "Test Description",
20+
"expected_price": 100000,
21+
"living_area": 50,
22+
"property_type_id": cls.property_type.id,
23+
},
24+
{
25+
"name": "Garden Test Property",
26+
"description": "Test Description Garden",
27+
"expected_price": 200000,
28+
"living_area": 100,
29+
"property_type_id": cls.property_type.id,
30+
},
31+
]
32+
)
33+
34+
cls.offers = cls.env["estate.property.offer"].create(
35+
[
36+
{
37+
"partner_id": cls.env.ref("base.res_partner_2").id,
38+
"price": 110000,
39+
"property_id": cls.properties[0].id,
40+
"validity": 7,
41+
},
42+
{
43+
"partner_id": cls.env.ref("base.res_partner_12").id,
44+
"price": 130000,
45+
"property_id": cls.properties[0].id,
46+
"validity": 7,
47+
},
48+
{
49+
"partner_id": cls.env.ref("base.res_partner_2").id,
50+
"price": 150000,
51+
"property_id": cls.properties[0].id,
52+
"validity": 7,
53+
},
54+
]
55+
)
56+
57+
def test_sell_property_without_accepted_offer(self):
58+
with self.assertRaises(UserError):
59+
self.properties[0].action_sell_property()
60+
61+
def test_sold_property_cannot_create_offer(self):
62+
self.properties[0].write({"state": "offer_accepted"})
63+
self.properties[0].action_sell_property()
64+
with self.assertRaises(UserError):
65+
self.env["estate.property.offer"].create(
66+
[
67+
{
68+
"partner_id": self.env.ref("base.res_partner_2").id,
69+
"price": 110000,
70+
"property_id": self.properties[0].id,
71+
"validity": 7,
72+
},
73+
]
74+
)
75+
76+
def test_garden_toggle(self):
77+
with Form(self.properties[1]) as form:
78+
form.garden = True
79+
self.assertEqual(form.garden_area, 10, "Garden area should be reset to 10")
80+
self.assertEqual(
81+
form.garden_orientation,
82+
"north",
83+
"Garden orientation should be reset to north",
84+
)
85+
form.garden = False
86+
self.assertEqual(form.garden_area, 0, "Garden area should be reset to 0")
87+
self.assertEqual(
88+
form.garden_orientation,
89+
False,
90+
"Garden orientation should be reset to False",
91+
)

0 commit comments

Comments
 (0)