Skip to content

Commit f711a73

Browse files
committed
[ADD] Kanban view
1 parent bff8fa0 commit f711a73

File tree

11 files changed

+92
-35
lines changed

11 files changed

+92
-35
lines changed

awesome_dashboard/estate Model 2/Model 2/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

awesome_dashboard/estate Model 2/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

awesome_dashboard/estate Model 2/__manifest__.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

estate/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
# -*- coding: utf-8 -*-
2+
3+
14
from . import models

estate/__manifest__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
'category': 'Real Estate',
44
'version': '19.0.1.0',
55
'author': 'Hazei',
6-
'license': 'LGPL-3',
76
'summary': 'Real Estate Management Tutorial',
87
'depends': [
98
'base',
109
],
1110
'data': [
1211
'security/ir.model.access.csv',
13-
'views/estate_property_views.xml',
14-
'views/estate_property_type.xml',
15-
'views/estate_property_tags_view.xml',
1612
'views/estate_property_offer_view.xml',
17-
'views/menu_views.xml',
13+
'views/estate_property_tags_view.xml',
14+
'views/estate_property_type.xml',
15+
'views/estate_property_views.xml',
1816
'views/res_users_views.xml',
17+
'views/menu_views.xml',
1918
],
2019
'application': True,
20+
'license': 'LGPL-3',
2121
}

estate/models/estate_property.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@
88

99

1010
class EstateProperty(models.Model):
11+
# ---------------------------------------- Private Attributes ---------------------------------
12+
1113
_name = "estate.property"
1214
_description = "Real Estate Property"
1315
_order = "id desc"
1416

17+
_check_expected_price = models.Constraint(
18+
'CHECK(expected_price >= 0)', 'The expected price must be strictly positive.')
19+
20+
_check_selling_price = models.Constraint(
21+
'CHECK(selling_price > 0)', 'The selling price must be positive.')
22+
23+
# ---------------------------------------- Fields Declaration ---------------------------------
24+
1525
name = fields.Char(string="Title", required=True)
1626
property_type = fields.Selection(
1727
string='Property Type',
@@ -53,11 +63,17 @@ class EstateProperty(models.Model):
5363
total_area = fields.Integer(string='Total Area(m2)', compute='_compute_total_area', store=True)
5464
best_price = fields.Float(string='Best Offer', compute='_compute_best_price', store=True)
5565

56-
_check_expected_price = models.Constraint(
57-
'CHECK(expected_price >= 0)', 'The expected price must be strictly positive.')
66+
@api.depends('living_area', 'garden_area')
67+
def _compute_total_area(self):
68+
for property in self:
69+
property.total_area = property.living_area + property.garden_area
5870

59-
_check_selling_price = models.Constraint(
60-
'CHECK(selling_price > 0)', 'The selling price must be positive.')
71+
@api.depends('offer_ids.price')
72+
def _compute_best_price(self):
73+
for record in self:
74+
record.best_price = max(record.offer_ids.mapped('price')) if record.offer_ids else 0
75+
76+
# ----------------------------------- Constrains and Onchanges --------------------------------
6177

6278
@api.constrains('selling_price', 'expected_price')
6379
def _check_selling_price_expected_price(self):
@@ -67,15 +83,6 @@ def _check_selling_price_expected_price(self):
6783
if float_compare(record.selling_price, 0.9 * record.expected_price, precision_digits=2) == -1:
6884
raise UserError("The selling price must be at least 90% of the expected price.")
6985

70-
@api.depends('living_area', 'garden_area')
71-
def _compute_total_area(self):
72-
for property in self:
73-
property.total_area = property.living_area + property.garden_area
74-
75-
@api.depends('offer_ids.price')
76-
def _compute_best_price(self):
77-
for record in self:
78-
record.best_price = max(record.offer_ids.mapped('price')) if record.offer_ids else 0
7986

8087
@api.onchange('garden')
8188
def _onchange_garden(self):
@@ -96,11 +103,15 @@ def _onchange_offers(self):
96103
if not has_offers and not any(offer.status == 'accepted' for offer in record.offer_ids) and record.state in ('offer_received',):
97104
record.state = 'offer_receive'
98105

106+
# ------------------------------------------ CRUD Methods -------------------------------------
107+
99108
@api.ondelete(at_uninstall=False)
100109
def _if_new_or_canceled(self):
101110
if not set(self.mapped("state")) <= {"new", "canceled"}:
102111
raise UserError("Only new and canceled properties can be deleted.")
103112

113+
# ---------------------------------------- Action Methods -------------------------------------
114+
104115
def action_set_sold(self):
105116
print(self.state)
106117
if self.state == "cancelled":

estate/models/estate_property_offer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66

77

88
class EstatePropertyOffer(models.Model):
9+
10+
# ---------------------------------------- Private Attributes ---------------------------------
11+
912
_name = 'estate.property.offer'
1013
_description = 'Estate Property Offer'
1114
_order = 'price desc'
1215

16+
# --------------------------------------- Fields Declaration ----------------------------------
17+
1318
price = fields.Float(string='price', required=True)
1419
status = fields.Selection(selection=[('accepted', 'Accepted'),
1520
('refused', 'Refused')],
@@ -23,12 +28,16 @@ class EstatePropertyOffer(models.Model):
2328
date_deadline = fields.Date(string='Deadline', compute='_compute_date_deadline', store=True)
2429
property_type_id = fields.Many2one("estate.property.type", related="property_id.property_type_id", store=True, string="Property Type")
2530

31+
# ---------------------------------------- Compute methods ------------------------------------
32+
2633
@api.depends('validity', 'create_date')
2734
def _compute_date_deadline(self):
2835
for offer in self:
2936
if not offer.create_date:
3037
offer.date_deadline = fields.Date.today() + relativedelta(days=offer.validity)
3138

39+
# ------------------------------------------ CRUD Methods -------------------------------------
40+
3241
@api.model_create_multi
3342
def create(self, vals_list):
3443
for vals in vals_list:
@@ -50,6 +59,8 @@ def create(self, vals_list):
5059

5160
return new_offers
5261

62+
# ---------------------------------------- Action Methods -------------------------------------
63+
5364
def action_accept(self):
5465
print("Accepting offer...")
5566
for offer in self:

estate/models/estate_property_tags.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33

44
class PropertyTypeTags(models.Model):
5+
6+
# ---------------------------------------- Private Attributes ---------------------------------
57
_name = 'estate.property.tags'
68
_description = 'Estate Property Tags'
79
_order = 'name'
810

11+
# --------------------------------------- Fields Declaration ----------------------------------
12+
913
name = fields.Char(required=True)
1014
color = fields.Integer()

estate/models/estate_property_type.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33

44
class PropertyType(models.Model):
5+
6+
# ---------------------------------------- Private Attributes ---------------------------------
7+
58
_name = 'estate.property.type'
69
_description = 'Estate Property Type'
710
_order = 'sequence, name'
811

12+
# --------------------------------------- Fields Declaration ----------------------------------
13+
914
name = fields.Char(required=True)
1015
property_ids = fields.One2many('estate.property', 'property_type_id', string='Properties')
1116
sequence = fields.Integer(string="Sequence", default=10)
1217
offer_ids = fields.One2many("estate.property.offer", "property_type_id", string="Offers")
1318
offer_count = fields.Integer(string="Offer Count", compute="_compute_offer_count")
1419

20+
# ---------------------------------------- Compute methods ------------------------------------
21+
1522
@api.depends("offer_ids")
1623
def _compute_offer_count(self):
1724
for record in self:

estate/views/estate_property_views.xml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,38 @@
9393
</form>
9494
</field>
9595
</record>
96-
96+
<record id="estate_property_view_kanban" model="ir.ui.view">
97+
<field name="name">estate.property.kanban</field>
98+
<field name="model">estate.property</field>
99+
<field name="arch" type="xml">
100+
<kanban default_group_by="property_type_id" records_draggable="false">
101+
<field name="state"/>
102+
<field name="offer_ids"/>
103+
<field name="selling_price"/>
104+
<field name="tags_ids"/>
105+
<field name="name"/>
106+
<field name="expected_price"/>
107+
<field name="best_price"/>
108+
<templates>
109+
<t t-name="card">
110+
<div class="oe_kanban_global_click">
111+
<div class="col-12">
112+
<field name="name"/>
113+
</div>
114+
<div class="col-12">
115+
<span>Expected price: </span>
116+
<field name="expected_price"/>
117+
</div>
118+
<div t-if="record.offer_ids" class="col-12">
119+
<span>Best Price: </span>
120+
<field name="best_price"/>
121+
</div>
122+
</div>
123+
</t>
124+
</templates>
125+
</kanban>
126+
</field>
127+
</record>
97128
<record id="estate_property_view_search" model="ir.ui.view">
98129
<field name="name">estate.property.views.search</field>
99130
<field name="model">estate.property</field>
@@ -110,4 +141,4 @@
110141
</search>
111142
</field>
112143
</record>
113-
</odoo>
144+
</odoo>

0 commit comments

Comments
 (0)