Skip to content

Commit 7ffb6fb

Browse files
committed
[IMP] estate: added sql constraints and python constraints, fixed offer view
[FIX] estate: code formatting and rename compute method Improved code readability by applying consistent formatting. Renamed compute method for best_price to follow naming conventions. changed discription position after name in manifest file.
1 parent 371178f commit 7ffb6fb

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

estate/__manifest__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env python3
22
{
33
"name": "Real Estate",
4+
"description": """
5+
Real Estate Module to Buy and Sell Your Real Estate with Ease.
6+
""",
47
"version": "1.0",
58
"depends": ["base"],
69
"author": "danal",
710
"category": "Category",
811
"application": True,
912
"license": "LGPL-3",
10-
"description": """
11-
Real Estate Module to Buy and Sell Your Real Estate with Ease.
12-
""",
1313
"data": [
1414
"security/ir.model.access.csv",
1515
"views/estate_property_views.xml",

estate/models/estate_property.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
#!/usr/bin/env python3
22
from dateutil.relativedelta import relativedelta
3+
from odoo.exceptions import ValidationError
34

45
from odoo import api, models, fields, exceptions
56

67

78
class EstateProperty(models.Model):
89
_name = "estate.property"
910
_description = "Estate Property"
11+
_check_expected_price = models.Constraint(
12+
"CHECK(expected_price > 0)", "A property expected price must be strictly positive."
13+
)
14+
_check_selling_price = models.Constraint(
15+
"CHECK(selling_price >= 0)", "A property selling price must be positive."
16+
)
1017

11-
name = fields.Char(required=True, default="Unknown")
18+
name = fields.Char(required=True)
1219
description = fields.Text()
1320
postcode = fields.Char()
1421
date_avaliability = fields.Date(
@@ -22,7 +29,6 @@ class EstateProperty(models.Model):
2229
garage = fields.Boolean()
2330
garden = fields.Boolean()
2431
garden_area = fields.Integer()
25-
last_seen = fields.Datetime("Last Seen", default=fields.Datetime.now)
2632
garden_orientation = fields.Selection(
2733
selection=[
2834
("north", "North"),
@@ -54,15 +60,15 @@ class EstateProperty(models.Model):
5460
tag_ids = fields.Many2many("estate.property.tag", string="Property Tags")
5561
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offer")
5662
total_area = fields.Integer(compute="_compute_area")
57-
best_price = fields.Integer(compute="_compute_highest")
63+
best_price = fields.Integer(compute="_compute_best_price")
5864

5965
@api.depends("living_area", "garden_area")
6066
def _compute_area(self):
6167
for record in self:
6268
record.total_area = record.living_area + record.garden_area
6369

6470
@api.depends("offer_ids.price")
65-
def _compute_highest(self):
71+
def _compute_best_price(self):
6672
for record in self:
6773
if not record.mapped("offer_ids.price"):
6874
record.best_price = 0
@@ -76,6 +82,7 @@ def _onchange_garden(self):
7682
self.garden_orientation = "north"
7783
else:
7884
self.garden_area = 0
85+
self.garden_orientation = None
7986

8087
def action_sold_property(self):
8188
for record in self:
@@ -92,3 +99,16 @@ def action_cancel_offer(self):
9299
else:
93100
record.state = "cancelled"
94101
return True
102+
103+
@api.constrains("selling_price", "expected_price")
104+
def _check_selling_price_persentage(self):
105+
for record in self:
106+
selling_price_persentage = (
107+
record.selling_price / record.expected_price
108+
) * 100
109+
if selling_price_persentage >= 90 or selling_price_persentage == 0:
110+
pass
111+
else:
112+
raise ValidationError(
113+
"The selling price cannot be lower than 90% of the expected price."
114+
)

estate/models/estate_property_offer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
class EstatePropertyOffer(models.Model):
77
_name = "estate.property.offer"
88
_description = "Estate Property Offer"
9+
_check_offer_price = models.Constraint(
10+
"CHECK(price > 0)", "An offer price must be strictly positive"
11+
)
912

1013
price = fields.Float()
1114
status = fields.Selection(
@@ -41,6 +44,5 @@ def action_accept(self):
4144
def action_refuse(self):
4245
for record in self:
4346
record.status = "refused"
44-
record.property_id.selling_price = 0.00
4547
record.property_id.customer = None
4648
return True

estate/models/estate_property_tag.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
class EstatePropertyTags(models.Model):
55
_name = "estate.property.tag"
66
_description = "Estate Property Tag"
7+
_check_tag_name = models.Constraint(
8+
"UNIQUE(name)", "A property tag name should be unique."
9+
)
710

811
name = fields.Char(required=True)

estate/models/estate_property_type.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
class EstatePropertyType(models.Model):
66
_name = "estate.property.type"
77
_description = "Estate Property Type"
8+
_check_type_name = models.Constraint(
9+
"UNIQUE(name)", "A property type name should be unique."
10+
)
811

912
name = fields.Char(required=True)

estate/views/estate_property_views.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@
118118
<field name="partner_id"/>
119119
<field name="validity" string="Validity(days)"/>
120120
<field name="date_deadline"/>
121-
<button name="action_accept" string="Accept" type="object" icon="fa-check"/>
122-
<button name="action_refuse" string="Refuse" type="object" icon="fa-times"/>
121+
<button name="action_accept" string="Accept" type="object" icon="fa-check" invisible="status in ('accepted', 'refused')"/>
122+
<button name="action_refuse" string="Refuse" type="object" icon="fa-times" invisible="status in ('accepted', 'refused')"/>
123123
<field name="status"/>
124124
</list>
125125
</field>

0 commit comments

Comments
 (0)