Skip to content

Commit e1f7fc8

Browse files
committed
[IMP] estate: define actions & buttons
Added 'Cancel' and 'Sold' buttons to the estate.property model. A sold property cannot be cancelled, and a cancelled property cannot be marked as sold. Used Odoo Exceptions to show error messages for invalid actions.
1 parent 38e1079 commit e1f7fc8

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

estate/models/estate_property.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dateutil.relativedelta import relativedelta
22

33
from odoo import api, fields, models
4+
from odoo.exceptions import UserError
45

56

67
class EstateProperty(models.Model):
@@ -74,3 +75,17 @@ def _onchange_garden(self):
7475
else:
7576
self.garden_area = 0
7677
self.garden_orientation = False
78+
79+
def set_property_cancelled(self):
80+
for rec in self:
81+
if rec.state == 'cancelled':
82+
raise UserError("Sold property can not be cancelled.")
83+
rec.state = 'cancelled'
84+
return True
85+
86+
def set_property_sold(self):
87+
for rec in self:
88+
if rec.state == 'cancelled':
89+
raise UserError("Cancelled properties can not be sold.")
90+
rec.state = 'sold'
91+
return True

estate/views/estate_property_views.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
<field name="model">estate.property</field>
66
<field name="arch" type="xml">
77
<form string="Properties">
8+
<header>
9+
<button name="set_property_sold" type="object">Sold</button>
10+
<button name="set_property_cancelled" type="object">Cancel</button>
11+
</header>
812
<sheet>
913
<h1><field name="name"/></h1>
1014
<h4><field name='property_tag_ids' widget='many2many_tags'/></h4>
1115
<group>
1216
<group>
17+
<field name="state" string="Status"/>
1318
<field name='property_type_id'/>
1419
<field name="postcode"/>
1520
<field name="date_availability"/>
@@ -81,7 +86,7 @@
8186
<field name='date_availability'/>
8287
<field name='total_area'/>
8388
<field name='best_price'/>
84-
<filter string="Available" name="avilable" domain="[('state','in',['new','offer_received'])]"/>
89+
<filter string="Available" name="available" domain="[('state','in',['new','offer_received'])]"/>
8590
<filter string="Postcode" name="group_by_postcode" context="{'group_by':'postcode'}"/>
8691
</search>
8792
</field>

0 commit comments

Comments
 (0)