Skip to content

Commit bc4a208

Browse files
Property Error Bugfix
1 parent 5f65b3c commit bc4a208

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

estate/models/estate_property_offer.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from odoo import api, fields, models, exceptions
1+
"""Odoo modules"""
22
from dateutil.relativedelta import relativedelta
3+
from odoo import api, fields, models, exceptions
34

45
class EstatePropertyOffer(models.Model):
6+
'''Offer for an estate property'''
57
_name = "estate.property.offer"
68
_description = "Offer for a property"
79
_order = "price desc"
@@ -18,57 +20,58 @@ class EstatePropertyOffer(models.Model):
1820
validity = fields.Float(default = 7, string = "Validity")
1921
property_type_id = fields.Many2one(related="property_id.property_type_id")
2022

21-
23+
2224

2325
_sql_constraints = [('check_price', 'CHECK(price > 0)', 'The price must be strictly positive.')]
2426

2527

2628

2729
@api.model
28-
def create(self, vals):
29-
30-
self.env['estate.property'].browse(vals['property_id']).state = 'offer_received'
30+
def create(self, vals_list):
31+
'''Change property state and add price warning on creation'''
32+
self.env['estate.property'].browse(vals_list['property_id']).state = 'offer_received'
3133

3234
if self.env['estate.property'].browse(vals['property_id']).offer_ids:
3335
if vals['price'] < min(self.env['estate.property'].browse(vals['property_id']).offer_ids.mapped('price')):
3436
raise exceptions.UserError("You are trying to create the lowest offer")
3537

36-
return super().create(vals)
38+
return super().create(vals_list)
3739

3840
@api.depends("validity")
3941
def _compute_date_deadline(self):
4042
for record in self:
41-
if (record.create_date):
43+
if record.create_date:
4244
record.date_deadline = record.create_date + relativedelta(days = record.validity)
4345
else:
4446
record.date_deadline = fields.Date.today() + relativedelta(days = record.validity)
4547

4648
@api.depends("date_deadline")
4749
def _inverse_date_deadline(self):
4850
for record in self:
49-
if (record.create_date):
51+
if record.create_date:
5052
record.validity = relativedelta(record.date_deadline , record.create_date).days
5153
else:
5254
record.validity = relativedelta(record.date_deadline, fields.Date.today()).days
5355

5456

5557

5658
def accept_offer(self):
59+
'''Accept an offer'''
5760
for record in self:
5861
for offer_id in record.property_id.offer_ids:
5962
if offer_id.status == 'accepted':
6063
raise exceptions.UserError("Another offer is already accepted")
61-
return True
6264

6365
record.status = 'accepted'
6466
record.property_id.buyer_id = record.partner_id
6567
record.property_id.selling_price = record.price
6668

6769
return True
68-
70+
6971
def refuse_offer(self):
72+
'''Refuse an offer'''
7073
for record in self:
71-
if (record.status == 'accepted'):
74+
if record.status == 'accepted':
7275
record.property_id.buyer_id = False
7376
record.property_id.selling_price = 0
7477

0 commit comments

Comments
 (0)