Skip to content

Commit d62d928

Browse files
committed
[ADD] estate: Add property and offer action buttons with smart restrictions
- Property page now has Cancel and Sold buttons for quick status updates - Cancelled properties cannot be marked sold and vice versa - Offer page includes Accept and Refuse buttons for better offer handling - Accepting an offer sets the buyer and selling price automatically - Ensures only one offer can be accepted per property
1 parent 94c5b92 commit d62d928

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

estate/models/estate_property.py

Lines changed: 22 additions & 1 deletion
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
from datetime import timedelta
34

45
class EstateProperty(models.Model):
@@ -91,4 +92,24 @@ def _onchange_garden(self):
9192
property.garden_orientation = 'north'
9293
else:
9394
property.garden_area = 0
94-
property.garden_orientation = False
95+
property.garden_orientation = False
96+
97+
def action_set_sold(self):
98+
for property in self:
99+
if property.selling_price > 0.0 and property.state != "cancelled":
100+
property.state = 'sold'
101+
elif property.state == "cancelled":
102+
raise UserError("A cancelled property cannot be sold.")
103+
elif property.state == "new" or property.state == "offer received":
104+
raise UserError("This property must have an accepted offer before it can be sold.")
105+
elif property.state == "sold":
106+
raise UserError("This property is already sold.")
107+
108+
def action_set_cancelled(self):
109+
for property in self:
110+
if property.state != "cancelled" and property.state != "sold":
111+
property.state = 'cancelled'
112+
elif property.state == "cancelled":
113+
raise UserError("This property is already cancelled.")
114+
elif property.state == "sold":
115+
raise UserError("A sold property cannot be cancelled.")

estate/models/estate_property_offer.py

Lines changed: 26 additions & 1 deletion
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
from datetime import timedelta
34

45
class EstatePropertyOffer(models.Model):
@@ -49,4 +50,28 @@ def _inverse_date_deadline(self):
4950
# base_date = fields.Date.to_date(offer.create_date) if offer.create_date else fields.Date.context_today(offer)
5051
# offer.validity = (offer.date_deadline - base_date).days
5152
# else:
52-
# offer.validity = 0
53+
# offer.validity = 0
54+
55+
def action_set_accepted(self):
56+
for offer in self:
57+
if offer.property_id.selling_price == 0.0:
58+
offer.status = 'accepted'
59+
offer.property_id.state = 'offer accepted'
60+
offer.property_id.selling_price = offer.price
61+
offer.property_id.buyer_id = offer.partner_id
62+
63+
other_offers = offer.property_id.offer_ids - offer
64+
65+
other_offers.write({'status': 'refused'})
66+
else:
67+
raise UserError("One offer is already accepted for this property.")
68+
69+
def action_set_refused(self):
70+
for offer in self:
71+
if offer.status == 'accepted':
72+
offer.status = 'refused'
73+
offer.property_id.state = 'offer received'
74+
offer.property_id.buyer_id = False
75+
offer.property_id.selling_price = 0.0
76+
else:
77+
raise UserError("This offer is not accepted, so it cannot be refused.")

estate/views/estate_property_offer_views.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<field name="status"/>
1111
<field name="partner_id"/>
1212
<field name="validity"/>
13+
<button name="action_set_accepted" string="Accepted" type="object" icon="fa-check"/>
14+
<button name="action_set_refused" string="Refused" type="object" icon="fa-times"/>
1315
<field name="date_deadline"/>
1416
</list>
1517
</field>

estate/views/estate_property_views.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<field name="model">estate.property</field>
3737
<field name="arch" type="xml">
3838
<form string="estate_property_form">
39+
<header>
40+
<button name="action_set_sold" string="Sold" type="object"/>
41+
<button name="action_set_cancelled" string="Cancelled" type="object"/>
42+
</header>
3943
<sheet>
4044
<h1>
4145
<field name="name"/>
@@ -100,6 +104,7 @@
100104
<field name="bedrooms"/>
101105
<field name="living_area"/>
102106
<field name="facades"/>
107+
<field name="property_type_id"/>
103108
<filter name="Available" domain="['|', ('state', '=', 'new'),('state', '=', 'offer received')]"/>
104109
<group expand="0" string="Groupe BY">
105110
<filter name="postcode" context="{'group_by':'postcode'}"/>

0 commit comments

Comments
 (0)