Skip to content

Commit 70679b7

Browse files
committed
[FIX] estate & estate_account: Fixed all the comments on PR
1 parent f03f46b commit 70679b7

File tree

5 files changed

+42
-41
lines changed

5 files changed

+42
-41
lines changed

estate/models/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
from . import estate_property, estate_property_type, estate_property_tag, estate_property_offer, users
1+
from . import estate_property
2+
from . import estate_property_type
3+
from . import estate_property_tag
4+
from . import estate_property_offer
5+
from . import users

estate/models/estate_property.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,20 @@ class EstateProperty(models.Model):
5454

5555
@api.constrains('selling_price', 'expected_price')
5656
def _check_prices_difference(self):
57-
for record in self:
58-
if record.buyer_id and float_compare(record.selling_price, 0.9 * record.expected_price, 5) == -1:
57+
for estate in self:
58+
if estate.buyer_id and float_compare(estate.selling_price, 0.9 * estate.expected_price, 5) == -1:
5959
raise UserError(_("Selling price cannot be lower than 90% of the expected price!"))
6060

6161
@api.depends('garden_area', 'living_area')
6262
def _compute_total_area(self):
63-
for record in self:
64-
record.total_area = record.garden_area + record.living_area
63+
for estate in self:
64+
estate.total_area = estate.garden_area + estate.living_area
6565

6666
@api.depends('offer_ids.price')
6767
def _compute_best_price(self):
68-
for record in self:
69-
prices = record.offer_ids.mapped('price')
70-
71-
record.best_price = max(prices) if len(prices) > 0 else 0
68+
for estate in self:
69+
prices = estate.offer_ids.mapped('price')
70+
estate.best_price = max(prices, default=0)
7271

7372
@api.onchange('garden')
7473
def _onchange_garden(self):
@@ -80,29 +79,29 @@ def _onchange_garden(self):
8079
self.garden_orientation = ''
8180

8281
def action_cancel(self):
83-
for record in self:
84-
if record.state == 'cancelled':
82+
for estate in self:
83+
if estate.state == 'cancelled':
8584
raise UserError(_("Property already cancelled!"))
86-
elif record.state == 'sold':
85+
elif estate.state == 'sold':
8786
raise UserError(_("A sold property cannot be cancelled!"))
8887
else:
89-
self.state = 'cancelled'
88+
estate.state = 'cancelled'
9089

9190
return True
9291

9392
def action_sold(self):
94-
for record in self:
95-
if record.state == 'sold':
93+
for estate in self:
94+
if estate.state == 'sold':
9695
raise UserError(_("Property already sold!"))
97-
elif record.state == 'cancelled':
96+
elif estate.state == 'cancelled':
9897
raise UserError(_("A cancelled property cannot be sold!"))
9998
else:
100-
self.state = 'sold'
99+
estate.state = 'sold'
101100

102101
return True
103102

104103
@api.ondelete(at_uninstall=False)
105104
def prevent_deletion(self):
106-
for record in self:
107-
if record.state != 'new' and record.state != 'cancelled':
105+
for estate in self:
106+
if estate.state not in ['new', 'cancelled']:
108107
raise UserError(_("You can only delete new or cancelled properties!"))

estate/models/estate_property_offer.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class EstatePropertyOffer(models.Model):
2222
property_id = fields.Many2one('estate.property', string="Property", required=True)
2323
validity = fields.Integer(string="Validity", default=7)
2424
date_deadline = fields.Date(compute='_compute_date_deadline', inverse='_inverse_date_deadline', string="Date Deadline")
25-
create_date = fields.Date(default=lambda self: fields.Datetime.now())
26-
property_type_id = fields.Many2one(related="property_id.property_type_id")
25+
create_date = fields.Date(default=lambda self: fields.Datetime.now(), string="Create Date")
26+
property_type_id = fields.Many2one(related="property_id.property_type_id", string="Property Type ID")
2727

2828
_sql_constraints = [
2929
('check_offer_price', 'CHECK(price > 0)',
@@ -32,14 +32,13 @@ class EstatePropertyOffer(models.Model):
3232

3333
@api.depends('validity', 'create_date')
3434
def _compute_date_deadline(self):
35-
for record in self:
36-
record.date_deadline = record.create_date + timedelta(days=record.validity)
35+
for offer in self:
36+
offer.date_deadline = offer.create_date + timedelta(days=offer.validity)
3737

3838
def _inverse_date_deadline(self):
39-
for record in self:
40-
delta = record.date_deadline - record.create_date
41-
42-
record.validity = delta.days
39+
for offer in self:
40+
delta = offer.date_deadline - offer.create_date
41+
offer.validity = delta.days
4342

4443
def action_confirm(self):
4544
self.ensure_one()
@@ -62,13 +61,13 @@ def action_confirm(self):
6261
return True
6362

6463
def action_refuse(self):
65-
for record in self:
66-
if record.status == 'refused':
64+
for offer in self:
65+
if offer.status == 'refused':
6766
raise UserError(_("Offer already refused!"))
68-
elif record.status == 'accepted':
67+
elif offer.status == 'accepted':
6968
raise UserError(_("Can't refuse an accepted offer!"))
7069
else:
71-
record.status = 'refused'
70+
offer.status = 'refused'
7271

7372
return True
7473

estate/models/estate_property_type.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class EstatePropertyType(models.Model):
88
_order = 'name'
99

1010
name = fields.Char(string="Name", required=True)
11-
property_ids = fields.One2many('estate.property', 'property_type_id')
11+
property_ids = fields.One2many('estate.property', 'property_type_id', string="Property Ids")
1212
sequence = fields.Integer(string='Sequence')
13-
offer_ids = One2many('estate.property.offer', 'property_type_id')
13+
offer_ids = One2many('estate.property.offer', 'property_type_id', string="Offer Ids")
1414
offer_count = fields.Integer(compute="_compute_offer_count", string="Offer Count")
1515

1616
_sql_constraints = [
@@ -19,5 +19,5 @@ class EstatePropertyType(models.Model):
1919

2020
@api.depends('offer_ids')
2121
def _compute_offer_count(self):
22-
for record in self:
23-
record.offer_count = len(record.offer_ids)
22+
for type in self:
23+
type.offer_count = len(type.offer_ids)

estate_account/models/estate_property.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ class InheritedEstateProperty(models.Model):
66

77
def action_sold(self):
88
invoices = []
9-
for record in self:
10-
journal = self.env['account.journal'].search([('type', '=', 'sale')])
11-
9+
journal = self.env['account.journal'].search([('type', '=', 'sale')], limit=1)
10+
for estate in self:
1211
invoice = {
13-
'partner_id': record.buyer_id.id,
12+
'partner_id': estate.buyer_id.id,
1413
'move_type': 'out_invoice',
1514
'journal_id': journal.id,
1615
'line_ids': [
1716
Command.create(
1817
{
19-
'name': record.name,
18+
'name': estate.name,
2019
'quantity': 1,
21-
'price_unit': 0.06 * record.selling_price,
20+
'price_unit': 0.06 * estate.selling_price,
2221
}
2322
),
2423
Command.create(

0 commit comments

Comments
 (0)