Skip to content

Commit 8becf43

Browse files
committed
[IMP] estate: added buttons to manage state of property and offers
User can now click a Sold or Cancel button to change a property’s status instantly. The system also protects your data by making sure a house that is already sold cannot be canceled, and a canceled house cannot be sold. Additionally, individual offers now have Accept and Refuse buttons. When you accept an offer, the system automatically fills in the buyer's name and the final price on the main page, ensuring that only one offer can be finalized for a property. These buttons make user's work faster because the system does the typing for user, user don't have to copy and paste the buyer's name or the price. The rules keep records correct by making sure user don't click the wrong button by accident.
1 parent 3e66a6e commit 8becf43

4 files changed

Lines changed: 57 additions & 10 deletions

File tree

estate/models/estate_property.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from odoo import models, fields, api
2+
from odoo.exceptions import UserError
23

34

45
class Estate(models.Model):
@@ -79,3 +80,17 @@ def _onchange_garden(self):
7980
else:
8081
self.garden_orientation = False
8182
self.garden_area = False
83+
84+
def mark_property_sold(self):
85+
for record in self:
86+
if record.state == "cancelled":
87+
raise UserError("cancelled property can't be sold")
88+
record.state = "sold"
89+
return True
90+
91+
def mark_property_cancelled(self):
92+
for record in self:
93+
if record.state == "sold":
94+
raise UserError("sold property can't be canceled")
95+
record.state = "cancelled"
96+
return True

estate/models/estate_property_offer.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from odoo import models, fields, api
2+
from odoo.exceptions import UserError
23

34

45
class EstatePropertyOffer(models.Model):
@@ -46,3 +47,19 @@ def _inverse_date_deadline(self):
4647
else fields.Date.context_today(record)
4748
)
4849
).days
50+
51+
def accept_offer(self):
52+
for record in self:
53+
for offer in record.property_id.offer_ids:
54+
if offer.status == "accepted":
55+
raise UserError("offer is already accepted for the property")
56+
record.status = "accepted"
57+
record.property_id.buyer_id = record.partner_id
58+
record.property_id.selling_price = record.price
59+
60+
def refuse_offer(self):
61+
for record in self:
62+
if record.status == "accepted":
63+
record.property_id.buyer_id = False
64+
record.property_id.selling_price = False
65+
record.status = "refused"

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="accept_offer" title="accept" type="object" icon="fa-check"/>
12+
<button name="refuse_offer" title="refuse" type="object" icon="fa-times"/>
1113
<field name="status"/>
1214
</list>
1315
</field>

estate/views/estate_property_views.xml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
<field name="model">estate_property</field>
1111
<field name="arch" type="xml">
1212
<list>
13-
<field name="name" string="Title"/>
14-
<field name="postcode"/>
15-
<field name="bedrooms"/>
16-
<field name="living_area" string="Living Area (sqm)"/>
17-
<field name="expected_price"/>
18-
<field name="selling_price"/>
19-
<field name="date_available" string="Available From"/>
13+
<field name="name" string="Title"/>
14+
<field name="postcode"/>
15+
<field name="bedrooms"/>
16+
<field name="living_area" string="Living Area (sqm)"/>
17+
<field name="expected_price"/>
18+
<field name="selling_price"/>
19+
<field name="date_available" string="Available From"/>
2020
</list>
2121
</field>
2222
</record>
@@ -26,6 +26,10 @@
2626
<field name="model">estate_property</field>
2727
<field name="arch" type="xml">
2828
<form>
29+
<header>
30+
<button name="mark_property_sold" type="object" string="Sold" class="btn-link"/>
31+
<button name="mark_property_cancelled" type="object" string="Cancelled" class="btn-link"/>
32+
</header>
2933
<sheet>
3034
<div class="oe_title">
3135
<h1>
@@ -35,6 +39,7 @@
3539
<group>
3640
<field name="property_tag_ids" widget="many2many_tags"/>
3741
<group>
42+
<field name="state" string="Status"/>
3843
<field name="property_type_id"/>
3944
<field name="postcode"/>
4045
<field name="date_available" string="Available from"/>
@@ -58,8 +63,17 @@
5863
<field name="garden_orientation"/>
5964
<field name="total_area" string="Total Area (sqm)"/>
6065
</group>
61-
</page>
62-
</notebook>
66+
</page>
67+
<page string="Offers">
68+
<field name="offer_ids"/>
69+
</page>
70+
<page string="Other info">
71+
<group>
72+
<field name="buyer_id"/>
73+
<field name="salesman_id"/>
74+
</group>
75+
</page>
76+
</notebook>
6377
</sheet>
6478
</form>
6579
</field>
@@ -86,4 +100,3 @@
86100
</field>
87101
</record>
88102
</odoo>
89-

0 commit comments

Comments
 (0)