Skip to content

Commit b0836be

Browse files
committed
[IMP] estate: implement offer acceptance and refusal actions, and add property sold/canceled state management
1 parent 4299479 commit b0836be

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

estate/models/estate_property.py

Lines changed: 17 additions & 2 deletions
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

34

45
class EstateProperty(models.Model):
@@ -39,7 +40,7 @@ class EstateProperty(models.Model):
3940
('offer_received', 'Offer Received'),
4041
('offer_accepted', 'Offer Accepted'),
4142
('sold', 'Sold'),
42-
('cancelled', 'Cancelled'),
43+
('canceled', 'Canceled'),
4344
],
4445
required=True,
4546
copy=False,
@@ -77,4 +78,18 @@ def _onchange_garden(self):
7778
self.garden_orientation = 'north'
7879
else:
7980
self.garden_area = 0
80-
self.garden_orientation = ''
81+
self.garden_orientation = False
82+
83+
def action_set_property_as_sold(self):
84+
for property in self:
85+
if property.state == 'canceled':
86+
raise UserError('Canceled properties cannot be sold.')
87+
property.state = 'sold'
88+
return True
89+
90+
def action_set_property_as_canceled(self):
91+
for property in self:
92+
if property.state == 'sold':
93+
raise UserError('Sold properties cannot be canceled.')
94+
property.state = 'canceled'
95+
return True

estate/models/estate_property_offer.py

Lines changed: 18 additions & 0 deletions
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 odoo.tools import date_utils
34

45

@@ -34,3 +35,20 @@ def _inverse_date_deadline(self):
3435
offer.validity = (
3536
offer.date_deadline - (offer.create_date.date() or fields.Date.today())
3637
).days
38+
39+
def action_accept(self):
40+
for offer in self:
41+
other_offers = offer.property_id.offer_ids - offer
42+
if any(other_offers.filtered(lambda o: o.status == 'accepted')):
43+
raise UserError('An offer has already been accepted.')
44+
45+
offer.status = 'accepted'
46+
offer.property_id.state = 'offer_accepted'
47+
offer.property_id.buyer = offer.partner_id
48+
offer.property_id.selling_price = offer.price
49+
return True
50+
51+
def action_refuse(self):
52+
for offer in self:
53+
offer.status = 'refused'
54+
return True

estate/views/estate_property_offer_views.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
<field name="partner_id" />
2828
<field name="validity" />
2929
<field name="date_deadline" />
30+
<button name="action_accept" type="object" icon="fa-check" title="Accept" />
31+
<button name="action_refuse" type="object" icon="fa-times" title="Refuse" />
3032
<field name="status" />
3133
</list>
3234
</field>

estate/views/estate_property_views.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
<field name="model">estate.property</field>
2626
<field name="arch" type="xml">
2727
<form string="Property">
28+
<header>
29+
<button name='action_set_property_as_sold' type='object' string='Sold' />
30+
<button name='action_set_property_as_canceled' type='object' string='Cancel' />
31+
</header>
2832
<sheet>
2933
<div class="oe_title mb-4">
3034
<h1>

0 commit comments

Comments
 (0)