Skip to content

Commit cc1dabd

Browse files
committed
[IMP] estate: formated code; add property offer model, views and form
1 parent a380279 commit cc1dabd

File tree

8 files changed

+120
-45
lines changed

8 files changed

+120
-45
lines changed

estate/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from . import models
1+
#!/usr/bin/env python3
2+
from . import models

estate/__manifest__.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
#!/usr/bin/env python3
12
{
2-
'name': "Real Estate",
3-
'version': '1.0',
4-
'depends': ['base'],
5-
'author': "danal",
6-
'category': 'Category',
7-
'application': True,
8-
'license': 'LGPL-3',
9-
'description': """
3+
"name": "Real Estate",
4+
"version": "1.0",
5+
"depends": ["base"],
6+
"author": "danal",
7+
"category": "Category",
8+
"application": True,
9+
"license": "LGPL-3",
10+
"description": """
1011
Description text
1112
""",
12-
'data': [
13-
'views/estate_property_views.xml',
14-
'views/estate_menus.xml',
15-
'security/ir.model.access.csv'
13+
"data": [
14+
"views/estate_property_views.xml",
15+
"views/estate_menus.xml",
16+
"security/ir.model.access.csv",
1617
],
17-
}
18+
}

estate/models/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
#!/usr/bin/env python3
12
from . import estate_property
23
from . import estate_property_type
34
from . import estate_property_tag
4-
from . import estate_property_offer
5+
from . import estate_property_offer

estate/models/estate_property.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from odoo import models, fields
2-
from odoo.tools import date_utils
1+
#!/usr/bin/env python3
2+
from dateutil.relativedelta import relativedelta
3+
4+
from odoo import api, models, fields
35

46

57
class EstateProperty(models.Model):
@@ -10,8 +12,7 @@ class EstateProperty(models.Model):
1012
description = fields.Text()
1113
postcode = fields.Char()
1214
date_avaliability = fields.Date(
13-
copy=False,
14-
default=date_utils.add(fields.Date.today(), month=2),
15+
copy=False, default=fields.Date.today() + relativedelta(month=3)
1516
)
1617
expected_price = fields.Float(required=True)
1718
selling_price = fields.Float(readonly=True, copy=False)
@@ -48,9 +49,30 @@ class EstateProperty(models.Model):
4849
property_type_id = fields.Many2one("estate.property.type", string="Property Type")
4950
customer = fields.Many2one("res.users", string="Customer", copy=False)
5051
salesperson = fields.Many2one(
51-
"res.partner",
52-
string="Salesperson",
53-
default =lambda self:self.env.user
52+
"res.partner", string="Salesperson", default=lambda self: self.env.user
5453
)
5554
tag_ids = fields.Many2many("estate.property.tag", string="Property Tags")
56-
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offer")
55+
offer_ids = fields.One2many("estate.property.offer", "property_id", string="Offer")
56+
total_area = fields.Integer(compute="_compute_area")
57+
best_price = fields.Integer(compute="_compute_highest")
58+
59+
@api.depends("living_area", "garden_area")
60+
def _compute_area(self):
61+
for record in self:
62+
record.total_area = record.living_area + record.garden_area
63+
64+
@api.depends("offer_ids.price")
65+
def _compute_highest(self):
66+
for record in self:
67+
if not record.mapped("offer_ids.price"):
68+
record.best_price = 0
69+
else:
70+
record.best_price = max(record.mapped("offer_ids.price"))
71+
72+
@api.onchange("garden")
73+
def _onchange_garden(self):
74+
if self.garden:
75+
self.garden_area = 10
76+
self.garden_orientation = "north"
77+
else:
78+
self.garden_area = 0

estate/models/estate_property_offer.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from odoo import models, fields
1+
from dateutil.relativedelta import relativedelta
2+
3+
from odoo import api, models, fields
24

35

46
class EstatePropertyOffer(models.Model):
@@ -11,3 +13,20 @@ class EstatePropertyOffer(models.Model):
1113
)
1214
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
1315
property_id = fields.Many2one("estate.property", string="Property", required=True)
16+
validity = fields.Integer(default=7)
17+
date_deadline = fields.Date(compute="_compute_deadline", inverse="_inverse_date")
18+
19+
@api.depends("validity")
20+
def _compute_deadline(self):
21+
for record in self:
22+
default_creation_date = record.create_date or fields.Date.today()
23+
record.date_deadline = (
24+
relativedelta(days=record.validity) + default_creation_date
25+
)
26+
27+
def _inverse_date(self):
28+
for record in self:
29+
default_creation_date = record.create_date or fields.Date.today()
30+
record.validity = (
31+
record.date_deadline - fields.Date.to_date(default_creation_date)
32+
).days

estate/models/estate_property_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
from odoo import models, fields
23

34

estate/views/estate_menus.xml

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
1+
<?xml version="1.0"?>
12
<odoo>
2-
<menuitem id="estate_menu_root"
3-
name="Estate Property"
4-
action="action_estate"/>
3+
<menuitem
4+
id="estate_menu_root"
5+
name="Estate Property"
6+
/>
57

6-
<menuitem id="estate_menu_configuration"
7-
name="Settings"
8-
parent="estate_menu_root"/>
8+
<menuitem
9+
id="estate_menu_property_advertisement"
10+
name="Advertisement"
11+
parent="estate_menu_root"
12+
sequence="1"
13+
/>
914

10-
<menuitem id="configuration_menu_property_types"
11-
name="Property Types"
12-
parent="estate_menu_configuration"
13-
action="action_estate_property_type"/>
15+
<menuitem
16+
id="estate_menu_property_advertisement_properties"
17+
name="Properties"
18+
parent="estate_menu_property_advertisement"
19+
action="action_estate"
20+
/>
1421

15-
<menuitem id="configuration_menu_property_tags"
16-
name="Property Tags"
17-
parent="estate_menu_configuration"
18-
action="action_estate_property_tag"/>
22+
<menuitem
23+
id="estate_menu_configuration"
24+
name="Settings"
25+
parent="estate_menu_root"
26+
/>
27+
28+
<menuitem
29+
id="configuration_menu_property_types"
30+
name="Property Types"
31+
parent="estate_menu_configuration"
32+
action="action_estate_property_type"
33+
/>
34+
35+
<menuitem
36+
id="configuration_menu_property_tags"
37+
name="Property Tags"
38+
parent="estate_menu_configuration"
39+
action="action_estate_property_tag"
40+
/>
1941
</odoo>

estate/views/estate_property_views.xml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0"?>
12
<odoo>
23
<record id="action_estate" model="ir.actions.act_window">
34
<field name="name">Properties</field>
@@ -55,18 +56,20 @@
5556
<field name="arch" type="xml">
5657
<form string="Property">
5758
<sheet>
58-
<group>
59+
<h1>
60+
<field name="name" string="Title"/>
61+
</h1>
62+
<group>
5963
<group>
60-
<field name="name" string="Title"/>
6164
<field name="tag_ids" widget="many2many_tags"/>
6265
<field name="postcode"/>
6366
<field name="date_avaliability" string="Avaliable From"/>
6467
</group>
6568
<group>
66-
<separator/>
6769
<field name="property_type_id"/>
6870
<field name="expected_price"/>
6971
<field name="selling_price"/>
72+
<field name="best_price" string="Best Offer"/>
7073
</group>
7174
</group>
7275
<notebook>
@@ -81,6 +84,7 @@
8184
<field name="garden"/>
8285
<field name="garden_area" string="Garden Area(sqm)"/>
8386
<field name="garden_orientation"/>
87+
<field name="total_area" string="Total Area(sqm)"/>
8488
</group>
8589
<group>
8690
<field name="active"/>
@@ -110,6 +114,8 @@
110114
<list string="Channel">
111115
<field name="price"/>
112116
<field name="partner_id"/>
117+
<field name="validity" string="Validity(days)"/>
118+
<field name="date_deadline"/>
113119
<field name="status"/>
114120
</list>
115121
</field>
@@ -121,10 +127,12 @@
121127
<field name="arch" type="xml">
122128
<form string="Property">
123129
<sheet>
124-
<group>
125-
<field name="price"/>
126-
<field name="partner_id"/>
127-
<field name="status"/>
130+
<group>
131+
<field name="price"/>
132+
<field name="partner_id"/>
133+
<field name="validity" string="Validity(days)"/>
134+
<field name="date_deadline"/>
135+
<field name="status"/>
128136
</group>
129137
</sheet>
130138
</form>

0 commit comments

Comments
 (0)