Skip to content

Commit e9da80b

Browse files
author
joyep
committed
[ADD] estate: Chapter 9 - add buttons and correspoding actions
Implement action methods for property status and offer status
1 parent 4521556 commit e9da80b

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

estate/models/estate_property.py

Lines changed: 14 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 dateutil.relativedelta import relativedelta
34

45

@@ -82,3 +83,16 @@ def _onchange_garden(self):
8283
self.garden_area = 10
8384
if not self.garden_orientation:
8485
self.garden_orientation = "north"
86+
87+
# action methods and other business logic
88+
def action_set_sold(self):
89+
for record in self:
90+
if record.status == "canceled":
91+
raise UserError("A cancelled property cannot be set as sold.")
92+
record.status = "sold"
93+
94+
def action_set_canceled(self):
95+
for record in self:
96+
if record.status == "sold":
97+
raise UserError("A sold property cannot be cancelled.")
98+
record.status = "canceled"

estate/models/estate_property_offer.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,25 @@ def _inverse_date_deadline(self):
3535
offer.validity = (offer.date_deadline - offer.create_date.date()).days
3636
elif offer.date_deadline: # Fallback if create_date is not set
3737
offer.validity = (offer.date_deadline - fields.Date.today()).days
38+
39+
def action_accept_offer(self):
40+
for offer in self:
41+
offer.status = "accepted"
42+
# Refuse other offers for the same property
43+
other_offers = self.search(
44+
[
45+
("property_id", "=", offer.property_id.id),
46+
("id", "!=", offer.id),
47+
]
48+
)
49+
other_offers.write({"status": "refused"})
50+
# Update the property status
51+
offer.property_id.status = "offer_accepted"
52+
offer.property_id.selling_price = offer.price
53+
offer.property_id.partner_id = offer.partner_id
54+
return True
55+
56+
def action_refuse_offer(self):
57+
for offer in self:
58+
offer.status = "refused"
59+
return True

estate/views/estate_property_views.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
<field name="arch" type="xml">
3131
<form string="Property">
3232
<sheet>
33+
<header>
34+
<button name="action_set_sold" type="object" string="Sold" class="btn-primary"/>
35+
<button name="action_set_canceled" type="object" string="Cancel" class="btn-secondary"/>
36+
</header>
3337
<div class="oe_title">
3438
<h1>
3539
<field name="name"/>
@@ -38,6 +42,7 @@
3842
</div>
3943
<group>
4044
<group>
45+
<field name="status" string="Status"/>
4146
<field name="property_type_id" string="Property Type"/>
4247
<field name="postcode" string="Postcode"/>
4348
<field name="date_availability" string="Available From"/>
@@ -70,6 +75,8 @@
7075
<field name="partner_id" string="Partner"/>
7176
<field name="validity" string="Validity (days)"/>
7277
<field name="date_deadline" string="Deadline"/>
78+
<button name="action_accept_offer" type="object" icon="fa-check"/>
79+
<button name="action_refuse_offer" type="object" icon="fa-times"/>
7380
<field name="status" string="Status"/>
7481
</list>
7582
<form string="Offer">

0 commit comments

Comments
 (0)