Skip to content

Commit a6a5755

Browse files
committed
[IMP] Estate: Create kanban view for estate proprety model
[FIX] Refactor [FIX] Correct style
1 parent 32e2724 commit a6a5755

File tree

6 files changed

+77
-40
lines changed

6 files changed

+77
-40
lines changed

estate/models/estate_property.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ class EstateProperty(models.Model):
99
_description = "Real estate propreties"
1010
_order = "id desc"
1111

12-
_check_expected_price = models.Constraint(
13-
'CHECK(expected_price > 0)',
14-
'Expected price must be strictly positive.',
15-
)
16-
_check_selling_price = models.Constraint(
17-
'CHECK(selling_price >= 0)',
18-
'Selling price must be positive.',
19-
)
2012
name = fields.Char(required=True)
2113
description = fields.Text()
2214
postcode = fields.Char()
@@ -42,6 +34,15 @@ class EstateProperty(models.Model):
4234
total_area = fields.Float(compute="_compute_total_area", readonly=True, copy=False)
4335
best_price = fields.Float(compute="_get_best_price", readonly=True, copy=False)
4436

37+
_check_expected_price = models.Constraint(
38+
'CHECK(expected_price > 0)',
39+
'Expected price must be strictly positive.',
40+
)
41+
_check_selling_price = models.Constraint(
42+
'CHECK(selling_price >= 0)',
43+
'Selling price must be positive.',
44+
)
45+
4546
@api.depends('living_area', 'garden_area')
4647
def _compute_total_area(self):
4748
for record in self:
@@ -55,6 +56,12 @@ def _get_best_price(self):
5556
else:
5657
record.best_price = 0
5758

59+
@api.constrains('selling_price', 'expected_price')
60+
def _check_selling_price(self):
61+
self.ensure_one()
62+
if self.buyer_id and float_compare(self.expected_price, 0.9 * self.selling_price, 0) > 0:
63+
raise ValidationError("The selling price cannot be lower than 90% of the expected price.")
64+
5865
@api.onchange('garden')
5966
def _onchange_garden(self):
6067
self.ensure_one()
@@ -65,6 +72,11 @@ def _onchange_garden(self):
6572
self.garden_area = 0
6673
self.garden_orientation = None
6774

75+
@api.ondelete(at_uninstall=False)
76+
def _unlink_if_not_new_or_cancelled(self):
77+
if any(record.state in ['new', 'cancelled'] for record in self):
78+
raise UserError("Can't delete a property which has a state of new or cancelled!")
79+
6880
def action_set_sold(self):
6981
self.ensure_one()
7082
if self.state == 'cancelled':
@@ -78,14 +90,3 @@ def action_set_cancelled(self):
7890
raise UserError("Sold property cannot be cancelled")
7991
self.state = 'cancelled'
8092
return 1
81-
82-
@api.constrains('selling_price', 'expected_price')
83-
def _check_selling_price(self):
84-
self.ensure_one()
85-
if self.buyer_id and float_compare(self.expected_price, 0.9 * self.selling_price, 0) > 0:
86-
raise ValidationError("The selling price cannot be lower than 90% of the expected price.")
87-
88-
@api.ondelete(at_uninstall=False)
89-
def _unlink_if_not_new_or_cancelled(self):
90-
if any(record.state in ['new', 'cancelled'] for record in self):
91-
raise UserError("Can't delete a property which has a state of new or cancelled!")

estate/models/estate_property_offer.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ class EstatePropertyOffer(models.Model):
99
_description = "Offers for propreties"
1010
_order = "price desc"
1111

12-
_check_price = models.Constraint(
13-
'CHECK(price > 0)',
14-
'Offer price must be strictly positive.',
15-
)
1612
price = fields.Float(required=True)
1713
status = fields.Selection(selection=[('accepted', 'Accepted'), ('refused', 'Refused')], copy=False)
1814
partner_id = fields.Many2one('res.partner', required=True)
@@ -22,6 +18,11 @@ class EstatePropertyOffer(models.Model):
2218
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline")
2319
property_type_id = fields.Many2one(related="property_id.type_id")
2420

21+
_check_price = models.Constraint(
22+
'CHECK(price > 0)',
23+
'Offer price must be strictly positive.',
24+
)
25+
2526
@api.depends('validity', 'create_date')
2627
def _compute_date_deadline(self):
2728
for record in self:
@@ -31,6 +32,16 @@ def _inverse_date_deadline(self):
3132
for record in self:
3233
record.validity = (record.date_deadline - record.create_date).days
3334

35+
@api.model
36+
def create(self, vals):
37+
for val in vals:
38+
created_property = self.env['estate.property'].browse(val['property_id'])
39+
if any(float_compare(val['price'], offer.price, 0) < 0 for offer in created_property.offer_ids):
40+
raise ValidationError("A bigger offer already exists")
41+
if created_property.state == 'new':
42+
created_property.state = 'received'
43+
return super().create(vals)
44+
3445
def action_accept_offer(self):
3546
self.ensure_one()
3647
self.status = 'accepted'
@@ -42,13 +53,3 @@ def action_refuse_offer(self):
4253
for record in self:
4354
record.status = 'refused'
4455
return 1
45-
46-
@api.model
47-
def create(self, vals):
48-
for val in vals:
49-
created_property = self.env['estate.property'].browse(val['property_id'])
50-
if any(float_compare(val['price'], offer.price, 0) < 0 for offer in created_property.offer_ids):
51-
raise ValidationError("A bigger offer already exists")
52-
if created_property.state == 'new':
53-
created_property.state = 'received'
54-
return super().create(vals)

estate/models/estate_property_tag.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ class EstatePropertyTag(models.Model):
66
_description = "Define the tags of the property"
77
_order = "name"
88

9+
name = fields.Char(required=True)
10+
color = fields.Integer(default=1)
11+
912
_check_unique_tag = models.Constraint(
1013
'UNIQUE(name)',
1114
'Tag already exists.',
1215
)
13-
name = fields.Char(required=True)
14-
color = fields.Integer(default=1)

estate/models/estate_property_type.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ class EstatePropertyType(models.Model):
66
_description = "Define the type of the property"
77
_order = "sequence, name"
88

9-
_check_unique_type = models.Constraint(
10-
'UNIQUE(name)',
11-
'Type already exists.',
12-
)
139
name = fields.Char(required=True)
1410
sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.")
1511
property_ids = fields.One2many("estate.property", "type_id")
@@ -20,3 +16,8 @@ class EstatePropertyType(models.Model):
2016
def _compute_offer_count(self):
2117
for record in self:
2218
record.offer_count = len(record.offer_ids)
19+
20+
_check_unique_type = models.Constraint(
21+
'UNIQUE(name)',
22+
'Type already exists.',
23+
)

estate/views/estate_property_views.xml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<record id="estate_property_model_action" model="ir.actions.act_window">
44
<field name="name">Properties</field>
55
<field name="res_model">estate.property</field>
6-
<field name="view_mode">list,form</field>
6+
<field name="view_mode">list,form,kanban</field>
77
<field name="context">{'search_default_available': True}</field>
88
</record>
99

@@ -80,6 +80,38 @@
8080
</field>
8181
</record>
8282

83+
<record id="estate_property_view_kanban" model="ir.ui.view">
84+
<field name="name">estate.property.kanban</field>
85+
<field name="model">estate.property</field>
86+
<field name="arch" type="xml">
87+
<kanban default_group_by="type_id" records_draggable="false">
88+
<field name="state"/>
89+
<templates>
90+
<t t-name="card">
91+
<h2>
92+
<field name="name"/>
93+
</h2>
94+
<div>
95+
Expected price:
96+
<field name="expected_price"/>
97+
</div>
98+
<div t-if="record.state.raw_value == 'received'">
99+
Offer received:
100+
<field name="best_price"/>
101+
</div>
102+
<div t-if="record.state.raw_value == 'accepted'">
103+
Selled for:
104+
<field name="selling_price"/>
105+
</div>
106+
<div>
107+
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': true}"/>
108+
</div>
109+
</t>
110+
</templates>
111+
</kanban>
112+
</field>
113+
</record>
114+
83115
<record id="estate_property_search" model="ir.ui.view">
84116
<field name="name">estate.property.search</field>
85117
<field name="model">estate.property</field>

estate_account/models/estate_property.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ def action_set_sold(self):
2222
})
2323
],
2424
})
25+
return 1

0 commit comments

Comments
 (0)