Skip to content

Commit 5d4a3ff

Browse files
committed
[IMP] estate: add actions
1 parent 9b190ce commit 5d4a3ff

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

estate/models/estate_property.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import models, fields, api
1+
from odoo import models, fields, api, exceptions
22

33

44
class EstateProperty(models.Model):
@@ -52,4 +52,20 @@ def _onchange_garden(self):
5252
self.garden_orientation = None
5353
else:
5454
self.garden_area = 10
55-
self.garden_orientation = 'north'
55+
self.garden_orientation = 'north'
56+
57+
def action_cancel_property(self):
58+
for record in self:
59+
if record.state == 'sold':
60+
raise exceptions.UserError('Sold properties cannot be cancelled')
61+
else:
62+
record.state = 'cancelled'
63+
return True
64+
65+
def action_sold_property(self):
66+
for record in self:
67+
if record.state == 'cancelled':
68+
raise exceptions.UserError('Cancelled properties cannot be sold')
69+
else:
70+
record.state = 'sold'
71+
return True

estate/models/estate_property_offer.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import models, fields ,api
1+
from odoo import models, fields ,api, exceptions
22

33

44
class EstatePropertyOffer(models.Model):
@@ -8,8 +8,9 @@ class EstatePropertyOffer(models.Model):
88
price = fields.Float('Price')
99
status = fields.Selection(
1010
string='Status',
11+
default='new',
1112
copy=False,
12-
selection=[('accepted', 'Accepted'), ('refused', 'Refused')])
13+
selection=[('accepted', 'Accepted'), ('refused', 'Refused'), ('new', 'New')])
1314
partner_id = fields.Many2one('res.partner', string='Buyer', required=True)
1415
property_id = fields.Many2one('estate.property', string='Estate Property', required=True)
1516
validity = fields.Integer('Validity', default=7)
@@ -23,3 +24,19 @@ def _compute_date_deadline(self):
2324
def _inverse_date_deadline(self):
2425
for record in self:
2526
record.validity = (record.date_deadline - record.create_date).days
27+
28+
def action_accept_offer(self):
29+
if any(record.status == 'accepted' for record in self.property_id.offer_ids):
30+
raise exceptions.UserError('An offer is already accepted for this property')
31+
for record in self:
32+
record.status = 'accepted'
33+
record.property_id.buyer_id = record.partner_id
34+
record.property_id.selling_price = record.price
35+
return True
36+
37+
def action_refuse_offer(self):
38+
for record in self:
39+
if record.status == 'accepted':
40+
raise exceptions.UserError('You cant refuse an already accepted offer')
41+
record.status = 'refused'
42+
return True

estate/views/estate_property_offer_views.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
<field name="arch" type="xml">
2323
<list string="Channel">
2424
<field name="price" />
25-
<field name="status" />
2625
<field name="partner_id" />
2726
<field name="validity" />
2827
<field name="date_deadline" />
28+
<button name="action_accept_offer" string="Accept" type="object" icon="fa-check"/>
29+
<button name="action_refuse_offer" string="Refuse" type="object" icon="fa-times"/>
30+
<field name="status" />
2931
</list>
3032
</field>
3133
</record>

estate/views/estate_property_views.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<field name="model">estate.property</field>
2727
<field name="arch" type="xml">
2828
<form string="Estate Property">
29+
<header>
30+
<button name="action_sold_property" type="object" string="Sold" />
31+
<button name="action_cancel_property" type="object" string="Cancel" />
32+
</header>
2933
<sheet>
3034
<div class="oe_title">
3135
<h1 class="mb32">
@@ -41,7 +45,7 @@
4145
</group>
4246
<group>
4347
<field name="expected_price" />
44-
<field name="best_price"/>
48+
<field name="best_price" />
4549
<field name="selling_price" />
4650
</group>
4751
</group>
@@ -110,4 +114,4 @@
110114
</p>
111115
</field>
112116
</record>
113-
</odoo>
117+
</odoo>

0 commit comments

Comments
 (0)