Skip to content

Commit 0d62e93

Browse files
committed
[IMP] estate: Added action buttons to manage property and offer status
Chapter 9 : Added Sold/Cancel buttons on properties. Added Accept/Refuse buttons on offers. Set selling price and buyer when an offer is accepted.
1 parent b048a7d commit 0d62e93

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

estate/models/estate_property.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dateutil.relativedelta import relativedelta
22
from datetime import date
33
from odoo import models, fields, api
4+
from odoo.exceptions import UserError
45

56

67
class EstateProperty(models.Model):
@@ -90,3 +91,19 @@ def _onchange_garden(self):
9091
else:
9192
self.garden_area = 0
9293
self.garden_orientation = None
94+
95+
def action_cancel(self):
96+
for rec in self:
97+
if rec.state == "sold":
98+
raise UserError("Sold properties cannot be cancelled.")
99+
else:
100+
rec.state = "cancelled"
101+
return True
102+
103+
def action_set_sold(self):
104+
for rec in self:
105+
if rec.state == "cancelled":
106+
raise UserError("Canceled properties cannot be sold.")
107+
else:
108+
rec.state = "sold"
109+
return True

estate/models/estate_property_offer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from dateutil.relativedelta import relativedelta
22
from odoo import models, fields, api
3+
from odoo.exceptions import UserError
34

45

56
class EstatePropertyOffer(models.Model):
@@ -41,3 +42,17 @@ def _inverse_date_deadline(self):
4142
for rec in self:
4243
create = rec.create_date or fields.Date.today()
4344
rec.validity = (rec.date_deadline - fields.Date.today(create)).days
45+
46+
def action_accept(self):
47+
for offer in self:
48+
if offer.property_id.buyer_id:
49+
raise UserError('Only one offer can be accepted for a property.')
50+
offer.status = 'accepted'
51+
offer.property_id.selling_price = offer.price
52+
offer.property_id.buyer_id = offer.partner_id
53+
return True
54+
55+
def action_refuse(self):
56+
for offer in self:
57+
offer.status = 'refused'
58+
return True

estate/views/estate_property_offer_views.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<field name="partner_id"/>
99
<field name="validity"/>
1010
<field name="date_deadline"/>
11+
<button name="action_accept" string="Accept" type="object" icon="fa-check"/>
12+
<button name="action_refuse" string="Refuse" type="object" icon="fa-close" />
1113
<field name="status"/>
1214
</list>
1315
</field>

estate/views/estate_property_views.xml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
<field name="model">estate.property</field>
2828
<field name="arch" type="xml">
2929
<form string="Properties">
30+
<haeder>
31+
<group col="2">
32+
<button type="object" name="action_cancel" string="Cancel"/>
33+
<button type="object" name="action_set_sold" string="Sold"/>
34+
</group>
35+
</haeder>
3036
<sheet>
3137
<h1>
3238
<field name="name" nolabel="True"/>
@@ -76,24 +82,6 @@
7682

7783
<page string="Offers">
7884
<field name="offer_ids">
79-
<list editable="bottom">
80-
<field name="price"/>
81-
<field name="partner_id"/>
82-
<field name="validity"/>
83-
<field name="date_deadline"/>
84-
<field name="status"/>
85-
</list>
86-
<form>
87-
<sheet>
88-
<group>
89-
<field name="price"/>
90-
<field name="partner_id"/>
91-
<field name="validity"/>
92-
<field name="date_deadline"/>
93-
<field name="status"/>
94-
</group>
95-
</sheet>
96-
</form>
9785
</field>
9886
</page>
9987
</notebook>

0 commit comments

Comments
 (0)