Skip to content

Commit 658e49e

Browse files
committed
[IMP] estate: added accept and refuse offer buttons
1 parent 1120d88 commit 658e49e

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

estate/models/estate_property.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from odoo import api, fields, models
2+
from odoo.exceptions import UserError
23
from dateutil.relativedelta import relativedelta
34

45

@@ -7,7 +8,7 @@ class EstateProperty(models.Model):
78
_description = "Estate Property discription"
89

910
name = fields.Char('name', required=True)
10-
description = fields.Text('description', compute="_compute_description")
11+
description = fields.Text('description')
1112
postcode = fields.Char('postcode')
1213
availability_date = fields.Date(
1314
'availabilty date', copy=False, default=fields.Date.today() + relativedelta(months=3))
@@ -48,21 +49,11 @@ def _compute_total_area(self):
4849
for record in self:
4950
record.total_area = record.living_area + record.garden_area
5051

51-
@api.depends("buyer_id")
52-
def _compute_description(self):
53-
for record in self:
54-
record.description = "Description for buyer %s" % record.buyer_id.name
55-
5652
@api.depends("offer_ids")
5753
def _compute_best_offer(self):
58-
try:
59-
for record in self:
60-
if len(record.offer_ids) > 0:
61-
record.best_offer = max(record.offer_ids.mapped("price"))
62-
else:
63-
record.best_offer = 0.0
64-
except Exception as e:
65-
print(e)
54+
for record in self:
55+
record.best_offer = max(record.offer_ids.mapped(
56+
"price")) if record.offer_ids else 0.0
6657

6758
@api.onchange("garden")
6859
def _onchange_garden(self):
@@ -72,3 +63,19 @@ def _onchange_garden(self):
7263
else:
7364
self.garden_area = 0
7465
self.garden_orientation = None
66+
67+
def action_sell(self):
68+
for record in self:
69+
if record.state == "cancelled":
70+
raise UserError("You can't sell a cancelled property")
71+
record.state = "sold"
72+
73+
return True
74+
75+
def action_cancel(self):
76+
for record in self:
77+
if record.state == "sold":
78+
raise UserError("You can't cancel a sold property")
79+
record.state = "cancelled"
80+
81+
return True

estate/models/estate_property_offer.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from odoo import api, models, fields
2+
from odoo.exceptions import UserError
23
from dateutil.relativedelta import relativedelta
34

45

@@ -17,18 +18,31 @@ class EstatePropertyOffer(models.Model):
1718
date_deadline = fields.Date(
1819
compute="_compute_date_deadline", inverse="_inverse_date_deadline")
1920

20-
@api.depends("validity")
21+
@api.depends("validity", "create_date")
2122
def _compute_date_deadline(self):
2223
for record in self:
23-
start_date = fields.Date.today()
24-
if record.create_date:
25-
start_date = record.create_date
24+
start_date = record.create_date.date() if record.create_date else fields.Date.today()
2625
record.date_deadline = start_date + \
2726
relativedelta(days=record.validity)
2827

2928
def _inverse_date_deadline(self):
3029
for record in self:
31-
start_date = fields.Date.today()
32-
if record.create_date:
33-
start_date = record.create_date
34-
record.validity = (record.date_deadline - fields.Date.today()).days
30+
start_date = record.create_date.date() if record.create_date else fields.Date.today()
31+
record.validity = (record.date_deadline - start_date).days
32+
33+
def action_accept(self):
34+
for record in self:
35+
if record.property_id.buyer_id:
36+
raise UserError("You already accepted an offer")
37+
if record.status == "refused":
38+
raise UserError("You already refused this offer")
39+
record.status = "accepted"
40+
record.property_id.selling_price = record.price
41+
record.property_id.buyer_id = record.partner_id
42+
43+
44+
def action_refuse(self):
45+
for record in self:
46+
if record.status == "accepted":
47+
raise UserError("You already accepted this offer")
48+
record.status = "refused"

estate/views/estate_property_offer_views.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
<field name="arch" type="xml">
66
<list string="properties offer list">
77
<field name="price"/>
8-
<field name="status"/>
98
<field name="validity"/>
109
<field name="date_deadline"/>
1110
<field name="partner_id"/>
11+
<button name="action_accept" string = "accept" type="object" icon="fa-check"/>
12+
<button name="action_refuse" string = "refuse" type="object" icon="fa-times"/>
13+
<field name="status"/>
1214
</list>
1315
</field>
1416
</record>

estate/views/estate_property_views.xml

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<field name="model">estate.property</field>
2727
<field name="arch" type="xml">
2828
<form string="properties from">
29+
<header>
30+
<button name="action_sell" type="object" string="Mark as Sold"/>
31+
<button name="action_cancel" type="object" string="Cancel"/>
32+
</header>
2933
<sheet>
3034
<h1>
3135
<field name="name"/>

0 commit comments

Comments
 (0)