Skip to content

Commit 1ca46c5

Browse files
committed
[FIX] estate: code style fixes
- Cleaned up code to meet linting and CI style standards.
1 parent b7a71f9 commit 1ca46c5

File tree

6 files changed

+105
-96
lines changed

6 files changed

+105
-96
lines changed

estate/models/estate_property.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from odoo import fields, models, api
22
from odoo.exceptions import UserError, ValidationError
3+
from dateutil.relativedelta import relativedelta
4+
from datetime import date
35
from odoo.tools.float_utils import float_compare
46

57

@@ -10,7 +12,11 @@ class EstateProperty(models.Model):
1012
name = fields.Char(string="Name")
1113
description = fields.Text(string="Description")
1214
postcode = fields.Text(string="Postcode")
13-
date_availability = fields.Date(string="Date Availability")
15+
date_availability = fields.Date(
16+
string="Date Availability",
17+
copy=False,
18+
default=lambda self: date.today() + relativedelta(months=3),
19+
)
1420
expected_price = fields.Float(string="Expected Price")
1521
selling_price = fields.Integer(string="Selling Price")
1622
bedrooms = fields.Integer(string="Bedrooms")
@@ -19,6 +25,7 @@ class EstateProperty(models.Model):
1925
garage = fields.Boolean(string="Garage")
2026
garden = fields.Boolean(string="Garden")
2127
garden_area = fields.Integer(string="Garden Area")
28+
2229
garden_orientation = fields.Selection(
2330
string="Type",
2431
selection=[
@@ -36,9 +43,10 @@ class EstateProperty(models.Model):
3643
("new", "New"),
3744
("offer_received", "Offer Received "),
3845
("offer_accepted", "Offer Accepted"),
39-
("Cancelled", "Cancelled"),
46+
("sold", "Sold"),
47+
("cancelled", "Cancelled"),
4048
],
41-
string="State",
49+
string="Status",
4250
default="new",
4351
copy=False,
4452
)

estate/models/estate_property_offer.py

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
2-
3-
4-
5-
# offers model that will offer us the offers
6-
1+
# offers model that will offer us the offers
72

83

94
from odoo import fields, models, api
@@ -14,95 +9,106 @@
149

1510

1611
class EstatePropertyOffer(models.Model):
17-
_name = 'estate.property.offer'
18-
_description = 'Offer model for the properties of real estate'
12+
_name = "estate.property.offer"
13+
_description = "Offer model for the properties of real estate"
1914
price = fields.Float()
2015
status = fields.Selection(
21-
selection=[('accepted', 'Accepted'), ('refused', 'Refused ')],
22-
string='Status',
23-
copy = False
16+
selection=[("accepted", "Accepted"), ("refused", "Refused ")],
17+
string="Status",
18+
copy=False,
2419
)
2520

26-
partner_id = fields.Many2one('res.partner', string = 'Partner')
21+
partner_id = fields.Many2one("res.partner", string="Partner")
22+
23+
property_id = fields.Many2one("estate.property", string="Property")
2724

28-
property_id = fields.Many2one('estate.property', string ='Property')
25+
property_type_id = fields.Many2one(
26+
"estate.property.type",
27+
related="property_id.property_type_id",
28+
store=True,
29+
readonly=False,
30+
)
2931

30-
property_type_id = fields.Many2one("estate.property.type", related="property_id.property_type_id",store=True,readonly=False)
31-
32-
validity = fields.Integer(default= 7)
32+
validity = fields.Integer(default=7)
3333

34-
date_deadline = fields.Date(compute = '_compute_offer_deadline', inverse = '_deadline_update')
34+
date_deadline = fields.Date(
35+
compute="_compute_offer_deadline", inverse="_deadline_update"
36+
)
3537

36-
3738
# constrains of sql
3839

39-
_sql_constraints = [('check_price', 'CHECK(price > 0)', 'Offered price must be strictly positive')
40+
_sql_constraints = [
41+
("check_price", "CHECK(price > 0)", "Offered price must be strictly positive")
4042
]
41-
42-
# order in which data is fetched
43-
44-
_order = "price desc"
4543

44+
# order in which data is fetched
4645

46+
_order = "price desc"
4747

4848
# deadline will be computed based upon the validity date
49-
@api.depends('validity')
49+
@api.depends("validity")
5050
def _compute_offer_deadline(self):
5151
for offer in self:
5252
if not offer.create_date:
53-
offer.date_deadline = datetime.now() + relativedelta(days=(offer.validity or 0))
53+
offer.date_deadline = datetime.now() + relativedelta(
54+
days=(offer.validity or 0)
55+
)
5456
return
5557

56-
offer.date_deadline = offer.create_date + relativedelta(days=(offer.validity or 0))
57-
58+
offer.date_deadline = offer.create_date + relativedelta(
59+
days=(offer.validity or 0)
60+
)
5861

5962
# deadline date can also be changed and once this is saved validity will be updated
6063
def _deadline_update(self):
6164
for offer in self:
62-
offer.validity = (offer.date_deadline - (offer.create_date or datetime.now()).date()).days
63-
65+
offer.validity = (
66+
offer.date_deadline - (offer.create_date or datetime.now()).date()
67+
).days
6468

65-
# action for the accepting the offer
69+
# action for the accepting the offer
6670
def action_offer_confirm(self):
6771
for record in self:
68-
# since saling price is only updated when offer is accepted therefore it validates if offer
72+
# since saling price is only updated when offer is accepted therefore it validates if offer
6973
# is already accepted than warning
7074

71-
if record.property_id.selling_price > 0 :
72-
raise UserError('Offer price already accepted for the property')
75+
if record.property_id.selling_price > 0:
76+
raise UserError("Offer price already accepted for the property")
7377

74-
record.status = 'accepted'
78+
record.status = "accepted"
7579
record.property_id.selling_price = self.price
7680
record.property_id.partner_id = record.partner_id
77-
record.property_id.state = 'offer_accepted'
81+
record.property_id.state = "offer_accepted"
7882

7983
# action for the refusal of the status
8084
def action_offer_refuse(self):
81-
8285
for record in self:
83-
if (record.status == 'accepted'):
86+
if record.status == "accepted":
8487
record.property_id.selling_price = 0
85-
record.property_id.partner_id = ''
86-
record.status = 'refused'
88+
record.property_id.partner_id = ""
89+
record.status = "refused"
8790

88-
89-
9091
# now in case of offer creation CRUD
91-
# self will be a proxy object ,
92-
# property_id feilds is available in vals
92+
# self will be a proxy object ,
93+
# property_id feilds is available in vals
9394
@api.model_create_multi
9495
def create(self, vals):
95-
9696
# will check the offer value and does property has other offers which are max thw\an this one
97-
for value in vals:
98-
property_details = self.env['estate.property'].browse(value.get('property_id'))
97+
for value in vals:
98+
property_details = self.env["estate.property"].browse(
99+
value.get("property_id")
100+
)
99101
for property_data in property_details:
100102
offers_list = property_data.mapped("offer_ids.price")
101103
max_offer = max(offers_list, default=0)
102-
comparison_result = float_compare(value.get('price'),max_offer, precision_digits=2)
103-
104-
if comparison_result == -1 :
105-
raise UserError('Offer with a lower amount than an existing offer')
104+
comparison_result = float_compare(
105+
value.get("price"), max_offer, precision_digits=2
106+
)
107+
108+
if comparison_result == -1:
109+
raise UserError("Offer with a lower amount than an existing offer")
110+
111+
if property_data.state == "new":
112+
property_data.state = "offer_received"
106113

107114
return super().create(vals)
108-

estate/models/estate_property_tag.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
2-
31
# the tag model will be here
42

53

6-
74
from odoo import fields, models
85

96

10-
117
class EstatePropertyTag(models.Model):
128
_name = "estate.property.tag"
139
_description = "Tag model for the estate properties"
1410
name = fields.Char(required=True)
1511
color = fields.Integer(default=1)
16-
_sql_constraints = [('check_uniquness', ' UNIQUE(name)', 'Tag name must be unique')]
12+
_sql_constraints = [("check_uniquness", " UNIQUE(name)", "Tag name must be unique")]
1713

1814
# order on which data will be fetched
1915
_order = "name desc"

estate/models/estate_property_type.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
from odoo import fields, models, api
22

3-
# Property type model for properties
3+
4+
# Property type model for properties
45
# prpoerties can be of type house, penthouse, etc.
56
class EstatePropertyType(models.Model):
6-
_name = "estate.property.type"
7-
_description = "Type of properties of estate model"
8-
name = fields.Char(required=True)
9-
10-
property_ids = fields.One2many('estate.property', 'property_type_id')
11-
12-
offer_ids = fields.One2many("estate.property.offer", "property_type_id", "Offer For Property Type")
13-
14-
offer_count = fields.Integer(compute = "_compute_offer_count")
15-
sequence = fields.Integer('Sequence', default=1)
16-
17-
# sql constrains :::
7+
_name = "estate.property.type"
8+
_description = "Type of properties of estate model"
9+
name = fields.Char(required=True)
1810

19-
_sql_constraints = [('check_uniquness', ' UNIQUE(name)', 'Type of property name must be unique')]
11+
property_ids = fields.One2many("estate.property", "property_type_id")
2012

21-
# order on which data will be fetched
13+
offer_ids = fields.One2many(
14+
"estate.property.offer", "property_type_id", "Offer For Property Type"
15+
)
2216

23-
_order = "sequence, name desc"
17+
offer_count = fields.Integer(compute="_compute_offer_count")
18+
sequence = fields.Integer("Sequence", default=1)
2419

20+
# sql constrains :::
2521

26-
@api.depends("offer_ids")
22+
_sql_constraints = [
23+
("check_uniquness", " UNIQUE(name)", "Type of property name must be unique")
24+
]
2725

28-
def _compute_offer_count(self):
29-
for data in self:
30-
data.offer_count = len(data.offer_ids)
31-
26+
# order on which data will be fetched
3227

28+
_order = "sequence, name desc"
3329

30+
@api.depends("offer_ids")
31+
def _compute_offer_count(self):
32+
for data in self:
33+
data.offer_count = len(data.offer_ids)

estate/models/inherited_res_users.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
2-
3-
# This model inherits from res.users model
1+
# This model inherits from res.users model
42

53
from odoo import models, fields
64

5+
76
class InheritedResUsers(models.Model):
8-
_inherit = 'res.users'
9-
property_ids = fields.One2many('estate.property', 'user_id', "Estate Property",
10-
domain=[('state', 'in', ['new','offer_received'])]
7+
_inherit = "res.users"
8+
property_ids = fields.One2many(
9+
"estate.property",
10+
"user_id",
11+
"Estate Property",
12+
domain=[("state", "in", ["new", "offer_received"])],
1113
)
12-

estate_account/__manifest__.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
2-
'name': 'Real Estate Invoicing',
3-
'category': 'All',
4-
'application': True,
5-
'installable': True,
6-
'depends' : ['base','account', 'estate'],
7-
'data': [
8-
9-
]
10-
}
2+
"name": "Real Estate Invoicing",
3+
"category": "All",
4+
"application": True,
5+
"installable": True,
6+
"depends": ["base", "account", "estate"],
7+
"data": [],
8+
}

0 commit comments

Comments
 (0)