Skip to content

Commit 6efe63a

Browse files
committed
[IMP] Estate: Improve security and added actions in the properties form.\nSecurity:' prohibit: duplicate tags and negative prices'\n Actions: 'added visuals for properties state,linked status of offer to state of properties, added action to accept/refuse offer, added action to sold/cancel propertie
1 parent c5e1685 commit 6efe63a

File tree

5 files changed

+83
-3
lines changed

5 files changed

+83
-3
lines changed

estate/models/estate_property.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dateutil.relativedelta import relativedelta
2-
from odoo import api, fields, models
2+
from odoo import api, exceptions, fields, models
33

44

55
class Estate(models.Model):
@@ -44,11 +44,28 @@ class Estate(models.Model):
4444
readonly=True,
4545
)
4646

47+
_sql_constraints = [
48+
('expected_price', 'CHECK(expected_price >= 0 )',
49+
'A price should always be possitive'),
50+
('selling_price', 'CHECK(selling_price >= 0 )',
51+
'A price should always be possitive')
52+
]
53+
4754
@api.depends('living_area', 'garden_area')
4855
def _compute_total_area(self):
4956
for record in self:
5057
record.total_area = record.living_area + record.garden_area
5158

59+
@api.onchange('offer_ids')
60+
def _onchange_status(self):
61+
for record in self:
62+
if record.state not in ['offer accepted', 'sold', 'cancelled']:
63+
all_status = record.offer_ids.mapped('status')
64+
new_state = 'new'
65+
if all_status:
66+
new_state = 'offer received'
67+
record.state = new_state
68+
5269
@api.depends('offer_ids')
5370
def _compute_best_offer(self):
5471
for record in self:
@@ -58,3 +75,25 @@ def _compute_best_offer(self):
5875
else:
5976
record.best_offer = 0
6077

78+
@api.onchange('garden')
79+
def _onchange_garden(self):
80+
if self.garden:
81+
self.garden_area = 10
82+
self.garden_orientation = 'north'
83+
else:
84+
self.garden_area = 0
85+
self.garden_orientation = ''
86+
87+
def action_property_sold(self):
88+
for record in self:
89+
if record.state == 'cancelled':
90+
raise exceptions.UserError('property already cancelled')
91+
record.state = 'sold'
92+
93+
def action_property_cancelled(self):
94+
for record in self:
95+
if record.state == 'sold':
96+
raise exceptions.UserError('property already sold')
97+
record.state = 'cancelled'
98+
99+

estate/models/estate_property_offer.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dateutil.relativedelta import relativedelta
2-
from odoo import api, fields, models
2+
from odoo import api, exceptions, fields, models
33

44

55
class EstateOffer(models.Model):
@@ -22,6 +22,11 @@ class EstateOffer(models.Model):
2222
default='pending',
2323
)
2424

25+
_sql_constraints = [
26+
('price', 'CHECK(price >= 0 )',
27+
'A price should always be possitive')
28+
]
29+
2530
@api.depends('create_date', 'validity')
2631
def _compute_date_deadline(self):
2732
for record in self:
@@ -34,3 +39,26 @@ def _compute_date_deadline(self):
3439
def _inverse_date(self):
3540
for record in self:
3641
record.validity = (record.date_deadline - fields.Date.today()).days
42+
43+
def action_accept_offer(self):
44+
for record in self:
45+
if record.property_id.state not in ['sold', 'cancelled']:
46+
for offer in record.property_id.offer_ids:
47+
offer.status = 'refused'
48+
record.status = 'accepted'
49+
record.property_id.selling_price = record.price
50+
record.property_id.state = 'offer accepted'
51+
else:
52+
raise exceptions.UserError('property already cancelled')
53+
return True
54+
55+
def action_refuse_offer(self):
56+
for record in self:
57+
if record.property_id.state not in ['sold', 'cancelled']:
58+
if record.status == 'accepted':
59+
record.property_id.selling_price = 0
60+
record.property_id.state = 'offer received'
61+
else:
62+
raise exceptions.UserError('property already sold or cancelled')
63+
record.status = 'refused'
64+
return True

estate/models/estate_property_tag.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ class EstateTags(models.Model):
66
_description = 'It allows to create a new property tag'
77

88
name = fields.Char(required=True)
9+
10+
_sql_constraints = [
11+
(
12+
'unique_tag_by_estate_property', 'UNIQUE(name)',
13+
'Only one name by tag')
14+
]

estate/view/estate_property_offer_views.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<field name="partner_id"/>
99
<field name="price"/>
1010
<field name="status"/>
11+
<button name="action_accept_offer" title="allows to accept an offer" type="object" class="fa fa-check"/>
12+
<button name="action_refuse_offer" title="allows to refuse an offer" type="object" class="fa fa-times"/>
1113
</list>
1214
</field>
1315
</record>

estate/view/estate_property_views.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
<field name="model">estate.property</field>
2121
<field name="arch" type="xml">
2222
<form string="Estate">
23+
<header>
24+
<button name="action_property_sold" type="object" string="SOLD"/>
25+
<button name="action_property_cancelled" type="object" string="CANCELLED"/>
26+
<field name="state" widget="statusbar" statusbar_visible="new,offer received,offer accepted,sold" options="{'clickable': 1}"/>
27+
</header>
2328
<sheet>
2429
<h1 class="oe_title">
2530
<field name="name"/>
@@ -76,7 +81,7 @@
7681
<field name="arch" type="xml">
7782
<search string="Search Estates">
7883
<field name="name"/>
79-
<filter string="Available" name="available" domain="[('state', '!=', 'sold' ), ('state', '!=', 'cancelled'), ('state', '!=', 'offer_accepted')]"/>
84+
<filter string="Available" name="available" domain="[('state', 'not in', ['sold','cancelled','offer_accepted'] )]"/>
8085
<filter string="Garage" name="garage" domain="[('garage', '!=', True )]"/>
8186
<group expand="True" string="Group By">
8287
<filter string="Poscode" name="postcode" context="{'group_by':'postcode'}"/>

0 commit comments

Comments
 (0)