Skip to content

Commit eec8651

Browse files
committed
[IMP] estate: code style fixes
- Cleaned up code to meet linting and CI style standards.
1 parent 54ed146 commit eec8651

File tree

9 files changed

+191
-191
lines changed

9 files changed

+191
-191
lines changed

estate/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
from . import models
1+
from . import models

estate/__manifest__.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{
2-
'name': 'Real Estate',
3-
'category': 'Tutorials/RealEstate',
4-
'application': True,
5-
'installable': True,
6-
'data': [
7-
'views/estate_property_views.xml',
8-
'views/estate_property_tag_views.xml',
9-
'views/estate_property_offer_views.xml',
10-
'views/estate_property_type_views.xml',
11-
'views/estate_menus.xml',
12-
'views/inherit_res_users_view.xml',
13-
'security/ir.model.access.csv'
14-
15-
]
16-
}
2+
"name": "Real Estate",
3+
"category": "Tutorials/RealEstate",
4+
"application": True,
5+
"installable": True,
6+
"data": [
7+
"views/estate_property_views.xml",
8+
"views/estate_property_tag_views.xml",
9+
"views/estate_property_offer_views.xml",
10+
"views/estate_property_type_views.xml",
11+
"views/estate_menus.xml",
12+
"views/inherit_res_users_view.xml",
13+
"security/ir.model.access.csv",
14+
],
15+
}

estate/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from . import estate_property_type
33
from . import estate_property_tag
44
from . import estate_property_offer
5-
from . import inherited_res_users
5+
from . import inherited_res_users

estate/models/estate_property.py

Lines changed: 81 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from odoo import fields, models, api
32
from dateutil.relativedelta import relativedelta
43
from datetime import date
@@ -8,76 +7,96 @@
87

98

109
class EstateProperty(models.Model):
11-
1210
_name = "estate.property"
1311
_description = "Estate Model"
1412

1513
name = fields.Char()
16-
description= fields.Text()
14+
description = fields.Text()
1715
postcode = fields.Text()
18-
date_availability = fields.Date(copy=False, default= lambda self:date.today() + relativedelta(months=3))
16+
date_availability = fields.Date(
17+
copy=False, default=lambda self: date.today() + relativedelta(months=3)
18+
)
1919
expected_price = fields.Float()
2020
selling_price = fields.Integer(readonly=True, copy=False)
2121
bedrooms = fields.Integer(default=2)
2222
living_area = fields.Integer()
2323
facades = fields.Integer()
2424
garage = fields.Boolean()
25-
garden = fields.Boolean()
26-
garden_area = fields.Integer()
25+
garden = fields.Boolean()
26+
garden_area = fields.Integer()
2727
garden_orientation = fields.Selection(
28-
string='Type',
29-
selection=[('north', 'North'), ('south', 'South'),('east', 'East'),('west', 'West')],
30-
)
28+
string="Type",
29+
selection=[
30+
("north", "North"),
31+
("south", "South"),
32+
("east", "East"),
33+
("west", "West"),
34+
],
35+
)
3136

3237
active = fields.Boolean(default=True)
3338

3439
state = fields.Selection(
3540
selection=[
36-
('new', 'New'), ('offer_received', 'Offer Received '),
37-
('offer_accepted', 'Offer Accepted'), ('sold','Sold'),
38-
('cancelled' ,'Cancelled')],
39-
string='Status',
40-
default = 'new',
41-
copy = False
41+
("new", "New"),
42+
("offer_received", "Offer Received "),
43+
("offer_accepted", "Offer Accepted"),
44+
("sold", "Sold"),
45+
("cancelled", "Cancelled"),
46+
],
47+
string="Status",
48+
default="new",
49+
copy=False,
4250
)
4351

4452
# property will have Many to one relation with property type since many properties can belong to one property type
4553

46-
property_type_id = fields.Many2one("estate.property.type", "Property Type")
47-
48-
user_id = fields.Many2one('res.users', string='Salesperson', copy=False, default=lambda self: self.env.user)
49-
50-
partner_id = fields.Many2one('res.partner', string='Buyer', copy=False, )
51-
52-
53-
tag_ids = fields.Many2many("estate.property.tag", string = "Tags")
54+
property_type_id = fields.Many2one("estate.property.type", "Property Type")
5455

56+
user_id = fields.Many2one(
57+
"res.users",
58+
string="Salesperson",
59+
copy=False,
60+
default=lambda self: self.env.user,
61+
)
5562

56-
offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers")
63+
partner_id = fields.Many2one(
64+
"res.partner",
65+
string="Buyer",
66+
copy=False,
67+
)
5768

69+
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
5870

59-
total_area = fields.Integer(compute = "_compute_total_property_area")
71+
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offers")
6072

73+
total_area = fields.Integer(compute="_compute_total_property_area")
6174

62-
best_price = fields.Integer(compute = "_best_property_offer")
75+
best_price = fields.Integer(compute="_best_property_offer")
6376

64-
status = fields.Char(default='new')
77+
status = fields.Char(default="new")
6578

6679
_order = "id desc"
6780

68-
69-
_sql_constraints = [('check_expected_price', 'CHECK(expected_price > 0)', 'Expected price must be strictly positive'),
70-
('check_selling_price', 'CHECK(selling_price >= 0)', 'Selling price should be positive')
81+
_sql_constraints = [
82+
(
83+
"check_expected_price",
84+
"CHECK(expected_price > 0)",
85+
"Expected price must be strictly positive",
86+
),
87+
(
88+
"check_selling_price",
89+
"CHECK(selling_price >= 0)",
90+
"Selling price should be positive",
91+
),
7192
]
72-
7393

7494
@api.depends("garden_area", "living_area")
7595
def _compute_total_property_area(self):
7696
for area in self:
7797
self.total_area = self.garden_area + self.living_area
7898

79-
80-
@api.depends('offer_ids.price')
99+
@api.depends("offer_ids.price")
81100
def _best_property_offer(self):
82101
for record in self:
83102
offers_list = record.mapped("offer_ids.price")
@@ -86,88 +105,70 @@ def _best_property_offer(self):
86105
return
87106
self.best_price = 0
88107

89-
90-
91-
92108
# on change of garden status , update gardern area and its orientation
93109

94-
@api.onchange('garden')
110+
@api.onchange("garden")
95111
def _onchange_garden_status(self):
96112
if self.garden:
97113
self.garden_area = 10
98-
self.garden_orientation = 'north'
114+
self.garden_orientation = "north"
99115
return
100116
self.garden_area = 0
101-
self.garden_orientation = ''
102-
117+
self.garden_orientation = ""
103118

104-
# acts when property is sold
119+
# acts when property is sold
105120
# In case property is cancelled it cannot be sold
106121
def action_sell_property(self):
107-
108-
# dictionary for the property status
109-
property_sell_status_dict = {
110-
'new' : True,
111-
'sold': True,
112-
'cancelled': False
113-
}
122+
# dictionary for the property status
123+
property_sell_status_dict = {"new": True, "sold": True, "cancelled": False}
114124

115125
for record in self:
116126
print("the object on sell action", record.read())
117127
if property_sell_status_dict[record.status]:
118-
record.status = 'sold'
119-
record.state = 'sold'
128+
record.status = "sold"
129+
record.state = "sold"
120130
return
121-
raise UserError('Cancelled property cannot be sold.')
122-
131+
raise UserError("Cancelled property cannot be sold.")
123132

124133
# action in case of cancel property button
125-
# If property is sold than Cannot be cancelled
134+
# If property is sold than Cannot be cancelled
126135

127136
def action_cancel_property_selling(self):
128137
property_cancel_status_dict = {
129-
'new' : True,
130-
'cancelled': True,
131-
'sold': False,
138+
"new": True,
139+
"cancelled": True,
140+
"sold": False,
132141
}
133142
for record in self:
134143
if property_cancel_status_dict[record.status]:
135-
record.status = 'cancelled'
136-
return
137-
raise UserError('Sold property cannot be cancelled.')
138-
139-
140-
141-
# constrains for the selling price
144+
record.status = "cancelled"
145+
return
146+
raise UserError("Sold property cannot be cancelled.")
142147

143-
@api.constrains('selling_price', 'expected_price')
148+
# constrains for the selling price
144149

150+
@api.constrains("selling_price", "expected_price")
145151
def _check_selling_price(self):
146-
147152
for data in self:
148153
# if call will come after selling price change than it will allow updated price to work
149-
if data.selling_price <= 0 :
154+
if data.selling_price <= 0:
150155
return
151156

152-
price_float_ratio = (data.selling_price/self.expected_price)
153-
ratio_diffrence = float_compare(price_float_ratio,0.9, precision_digits=2)
154-
if ratio_diffrence == -1 :
157+
price_float_ratio = data.selling_price / self.expected_price
158+
ratio_diffrence = float_compare(price_float_ratio, 0.9, precision_digits=2)
159+
if ratio_diffrence == -1:
155160
data.selling_price = 0
156-
raise ValidationError('The selling price cannot be lower than 90% of the expected price')
161+
raise ValidationError(
162+
"The selling price cannot be lower than 90% of the expected price"
163+
)
157164
return
158-
159-
160165

161166
# delete opration for the process
162167

163-
164168
@api.ondelete(at_uninstall=False)
165169
def _unlink_if_state_new_or_cancelled(self):
166170
for data in self:
167-
if not bool(self.state == 'new' or self.state == 'cancelled') :
168-
raise UserError("Can't delete property which is not in new or cancelled state!")
169-
170-
171-
172-
173-
171+
if not bool(self.state == "new" or self.state == "cancelled"):
172+
raise UserError(
173+
"Can't delete property which is not in new or cancelled state!"
174+
)

0 commit comments

Comments
 (0)