Skip to content

Commit 4f1abfa

Browse files
[CLN] estate: code cleanup to match Ruff
1 parent c2f889b commit 4f1abfa

File tree

6 files changed

+55
-63
lines changed

6 files changed

+55
-63
lines changed

estate/__init__.py

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

estate/__manifest__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
{
32
'name':"estate",
43
'description':"test",
@@ -16,4 +15,4 @@
1615
'views/estate_menu_views.xml',
1716
'security/ir.model.access.csv']
1817

19-
}
18+
}

estate/models/estate_property.py

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,70 @@
11
from dateutil.relativedelta import relativedelta
22
from odoo import fields, models,api,exceptions
3-
from odoo.tools.float_utils import float_compare, float_is_zero;
4-
from odoo.exceptions import ValidationError;
3+
from odoo.tools.float_utils import float_compare, float_is_zero
4+
from odoo.exceptions import ValidationError
55

66

77
class EstateProperty(models.Model):
88
_name = "estate.property"
99
_description = "Property"
1010
_order = "id desc"
1111

12-
_positif_expected_price = models.Constraint("CHECK (expected_price > 0)","A price can't be negatif");
13-
_positif_selling_price = models.Constraint("CHECK (selling_price > 0)","A price can't be negatif");
12+
_positif_expected_price = models.Constraint("CHECK (expected_price > 0)", "A price can't be negatif")
13+
_positif_selling_price = models.Constraint("CHECK (selling_price > 0)", "A price can't be negatif")
1414

15-
state = fields.Selection(selection = [("New","New"), ("Offer_Received","Offer Received") ,("Offer_Accepted","Offer Accepted"), ("Sold","Sold"), ("Cancelled","Cancelled")])
16-
active = fields.Boolean('Active',default=True)
17-
name = fields.Char(required=True,default="Unkown")
15+
state = fields.Selection(selection=[("New", "New"), ("Offer_Received", "Offer Received"), ("Offer_Accepted", "Offer Accepted"), ("Sold", "Sold"), ("Cancelled", "Cancelled")])
16+
active = fields.Boolean('Active', default=True)
17+
name = fields.Char(required=True, default="Unkown")
1818
description = fields.Text()
1919
postcode = fields.Char()
20-
date_availability = fields.Date("Available From",copy=False,default= fields.Datetime.today() + relativedelta(months=3))
21-
last_seen= fields.Date("Last Seen", default=fields.Datetime.now)
20+
date_availability = fields.Date("Available From", copy=False, default=fields.Datetime.today() + relativedelta(months=3))
21+
last_seen = fields.Date("Last Seen", default=fields.Datetime.now)
2222
expected_price = fields.Float(required=True)
23-
selling_price = fields.Float(readonly=True,copy=False)
24-
best_price = fields.Float(string="Best Price",compute="_get_best_price")
23+
selling_price = fields.Float(readonly=True, copy=False)
24+
best_price = fields.Float(string="Best Price", compute="_get_best_price")
2525
bedrooms = fields.Integer(default=2)
2626
living_area = fields.Integer()
2727
facades = fields.Integer()
2828
garage = fields.Boolean()
2929
garden = fields.Boolean()
3030
garden_area = fields.Integer()
31-
garden_orientation = fields.Selection(selection=[('North','North'),('South','South'),('East','East'),('West','West')])
32-
total_area = fields.Float(compute="_get_total_area",string="Total Area");
33-
property_type_id = fields.Many2one("estate.property.type",string="Type")
34-
buyer_id = fields.Many2one("res.partner",string="Buyer")
35-
seller_id = fields.Many2one("res.users",default=lambda self : self.env.user,string="Seller")
36-
tag_ids = fields.Many2many("estate.property.tag",string="Tags")
37-
offer_ids = fields.One2many("estate.property.offer","property_id",string="Offers")
31+
garden_orientation = fields.Selection(selection=[('North', 'North'), ('South', 'South'), ('East', 'East'), ('West', 'West')])
32+
total_area = fields.Float(compute="_get_total_area", string="Total Area")
33+
property_type_id = fields.Many2one("estate.property.type", string="Type")
34+
buyer_id = fields.Many2one("res.partner", string="Buyer")
35+
seller_id = fields.Many2one("res.users", default=lambda self : self.env.user,string="Seller")
36+
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
37+
offer_ids = fields.One2many("estate.property.offer", "property_id",string="Offers")
3838

3939
def sell_property(self):
4040
for record in self:
41-
if(record.state == "Cancelled"):
41+
if (record.state == "Cancelled"):
4242
raise exceptions.UserError("Can't sell cancelled property.")
4343
record.state = "Sold"
4444
return True
45-
45+
4646
def cancel_property(self):
4747
for record in self:
48-
if(record.state == "Sold"):
48+
if (record.state == "Sold"):
4949
raise exceptions.UserError("Can't cancel sold property.")
5050
record.state = "Cancelled"
5151
return True
5252

53-
@api.depends('living_area','garden_area')
53+
@api.depends('living_area', 'garden_area')
5454
def _get_total_area(self):
5555
for record in self:
56-
record.total_area = record.garden_area + record.living_area;
57-
56+
record.total_area = record.garden_area + record.living_area
5857

5958
@api.depends('offer_ids')
6059
def _get_best_price(self):
6160
for record in self:
62-
max:int = 0
63-
64-
if(len(record.offer_ids)==0):
61+
max: int = 0
62+
if (len(record.offer_ids) == 0):
6563
record.best_price = 0
6664
continue
67-
65+
6866
for offer in record.offer_ids:
69-
if(offer.price >= max):
67+
if (offer.price >= max):
7068
max = offer.price
7169
record.best_price = max
7270

@@ -75,10 +73,11 @@ def _garden_pre_fill(self):
7573
self.garden_area = 10 if self.garden else 0
7674
self.garden_orientation = 'North' if self.garden else ''
7775

78-
@api.constrains('selling_price','expected_price')
76+
@api.constrains('selling_price', 'expected_price')
7977
def _check_prices(self):
80-
for record in self:
81-
if float_is_zero(record.selling_price,2):
82-
continue;
83-
if(float_compare(record.selling_price,record.expected_price*.8,2) == -1):
84-
raise ValidationError(f"Selling price is too low {record.selling_price}");
78+
for record in self:
79+
if float_is_zero(record.selling_price, 2):
80+
continue
81+
if (float_compare(record.selling_price, record.expected_price * 0.8, 2) == -1):
82+
raise ValidationError(f"Selling price is too low {record.selling_price}")
83+

estate/models/estate_property_offer.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,33 @@ class EstatePropertyOffer(models.Model):
1111
_postif_price = models.Constraint("CHECK (price > 0)", "A price can't be negatif")
1212

1313
price = fields.Float(string="Price")
14-
status = fields.Selection(copy=False,selection = [("Accepted","Accepted"),("Refused","Refused")])
15-
partner_id = fields.Many2one('res.partner',required=True)
14+
status = fields.Selection(copy=False, selection = [("Accepted", "Accepted"), ("Refused", "Refused")])
15+
partner_id = fields.Many2one('res.partner', required=True)
1616
property_id = fields.Many2one('estate.property', required=True)
17-
validity = fields.Integer(string="Validity Duration",default=7)
18-
date_deadline = fields.Date(string="Deadline",compute="_get_date_deadline",inverse="_set_date_deadline")
17+
validity = fields.Integer(string="Validity Duration", default=7)
18+
date_deadline = fields.Date(string="Deadline", compute="_get_date_deadline", inverse="_set_date_deadline")
1919

2020
def accept_offer(self):
2121
for record in self:
22-
if(record.property_id.selling_price == 0):
23-
record.status = "Accepted";
24-
print(type(record.property_id.seller_id))
25-
print(type(record.partner_id))
26-
record.property_id.buyer_id = record.partner_id;
27-
record.property_id.selling_price = record.price;
28-
29-
return True;
30-
22+
if (record.property_id.selling_price == 0):
23+
record.status = "Accepted"
24+
record.property_id.buyer_id = record.partner_id
25+
record.property_id.selling_price = record.price
26+
return True
27+
3128
def refused_offer(self):
3229
for record in self:
33-
record.status = "Refused";
34-
return True;
35-
30+
record.status = "Refused"
31+
return True
3632

3733
@api.depends("validity")
3834
def _get_date_deadline(self):
3935
for record in self:
40-
if(isinstance(record.create_date,bool)):
36+
if (isinstance(record.create_date,bool)):
4137
record.date_deadline = fields.Datetime.now() + relativedelta(days=record.validity)
4238
return
4339
record.date_deadline = record.create_date + relativedelta(days=record.validity)
4440

4541
def _set_date_deadline(self):
4642
for record in self:
47-
record.validity = (datetime.combine(record.date_deadline,time()) - record.create_date).days
43+
record.validity = (datetime.combine(record.date_deadline, time()) - record.create_date).days

estate/models/estate_property_tag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ class EstatePropertyTag(models.Model):
66
_description = "Property Tag"
77
_order = "name asc"
88

9-
_unique_tag = models.UniqueIndex("(name)","Tag name must be unique in database")
9+
_unique_tag = models.UniqueIndex("(name)", "Tag name must be unique in database")
1010

11-
name = fields.Char(required=True)
11+
name = fields.Char(required=True)

estate/models/estate_property_type.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ class EstatePropertyType(models.Model):
66
_description = "Property Type"
77
_order = "sequence, name asc"
88

9-
_unique_type = models.UniqueIndex("(name)","Property type name must be unique in database")
9+
_unique_type = models.UniqueIndex("(name)", "Property type name must be unique in database")
1010

1111
name = fields.Char(required=True)
12-
property_ids = fields.One2many("estate.property","property_type_id")
13-
sequence = fields.Integer('Sequence',default=1,help="use to order the list inside the type view")
14-
15-
12+
property_ids = fields.One2many("estate.property", "property_type_id")
13+
sequence = fields.Integer('Sequence', default=1, help="use to order the list inside the type view")

0 commit comments

Comments
 (0)