Skip to content

Commit db4a40c

Browse files
committed
[IMP] estate: added auto fields and smart defaults
Added total area and best offer calculation, linked offer validity and deadline dates setting any one will automatically set another, and default values for garden details will be automatically filled when garden is selected. These changes make data entry easier and reduce manual work. The total area and best offer are calculated automatically, so users don’t need to compute them. Offer validity and deadline are connected, meaning entering one will automatically fill the other, avoiding confusion. When a garden is selected, related fields like area and orientation are pre-filled with default values, helping users enter information faster and more consistently. chapter: 8(Computed Fields And Onchanges)
1 parent 80e776e commit db4a40c

7 files changed

Lines changed: 67 additions & 4 deletions

estate/__manifest__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"name": "estate",
33
"depends": ["base"],
44
"application": True,
5+
"author": "shrey patel",
6+
"license": "LGPL-3",
57
"data": [
68
"security/ir.model.access.csv",
79
"views/estate_property_type_views.xml",

estate/models/estate_property.py

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

33

44
class Estate(models.Model):
@@ -29,7 +29,7 @@ class Estate(models.Model):
2929
("west", "West"),
3030
],
3131
)
32-
active = fields.Boolean(string="State", default=True)
32+
active = fields.Boolean(string="Active", default=True)
3333
state = fields.Selection(
3434
string="State",
3535
selection=[
@@ -58,3 +58,24 @@ class Estate(models.Model):
5858
inverse_name="property_id",
5959
string="Offers",
6060
)
61+
total_area = fields.Integer(string="Total Area", compute="_compute_total_area")
62+
best_price = fields.Float(string="Best Offer", compute="_compute_best_price")
63+
64+
@api.depends("living_area", "garden_area")
65+
def _compute_total_area(self):
66+
for record in self:
67+
record.total_area = record.garden_area + record.living_area
68+
69+
@api.depends("offer_ids.price")
70+
def _compute_best_price(self):
71+
for record in self:
72+
record.best_price = max(record.offer_ids.mapped("price"), default=0)
73+
74+
@api.onchange("garden")
75+
def _onchange_garden(self):
76+
if self.garden:
77+
self.garden_orientation = "north"
78+
self.garden_area = 10
79+
else:
80+
self.garden_orientation = False
81+
self.garden_area = False

estate/models/estate_property_offer.py

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

33

44
class EstatePropertyOffer(models.Model):
55
_name = "estate.property_offer"
6-
price = fields.Char(string="Price")
6+
_description = "Offers received for property"
7+
price = fields.Float(string="Price")
78
status = fields.Selection(
89
selection=[("accepted", "Accepted"), ("refused", "Refused")],
910
string="Status",
@@ -15,3 +16,33 @@ class EstatePropertyOffer(models.Model):
1516
property_id = fields.Many2one(
1617
comodel_name="estate_property", string="Property", required=True
1718
)
19+
validity = fields.Integer(string="Validity (days)", default=7)
20+
date_deadline = fields.Date(
21+
string="Deadline",
22+
compute="_compute_date_deadline",
23+
inverse="_inverse_date_deadline",
24+
)
25+
26+
@api.depends("create_date", "validity")
27+
def _compute_date_deadline(self):
28+
for record in self:
29+
record.date_deadline = fields.Date.add(
30+
(
31+
record.create_date.date()
32+
if record.create_date
33+
else fields.Date.context_today(record)
34+
),
35+
days=record.validity,
36+
)
37+
38+
def _inverse_date_deadline(self):
39+
for record in self:
40+
if record.date_deadline:
41+
record.validity = (
42+
record.date_deadline
43+
- (
44+
record.create_date.date()
45+
if record.create_date
46+
else fields.Date.context_today(record)
47+
)
48+
).days

estate/models/estate_property_tag.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
class EstatePropertyTag(models.Model):
55
_name = "estate.property_tag"
6+
_description = "Tags for property"
67
name = fields.Char(string="name")

estate/models/estate_property_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
class EstatePropertyType(models.Model):
55
_name = "estate.property_type"
6+
_description = "Defines property type"
67
name = fields.Char(string="Property Type", required=True)

estate/views/estate_property_offer_views.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<list>
77
<field name="price"/>
88
<field name="partner_id"/>
9+
<field name="validity"/>
10+
<field name="date_deadline"/>
911
<field name="status"/>
1012
</list>
1113
</field>
@@ -19,6 +21,8 @@
1921
<group>
2022
<field name="price"/>
2123
<field name="partner_id"/>
24+
<field name="validity"/>
25+
<field name="date_deadline"/>
2226
<field name="status"/>
2327
</group>
2428
</form>

estate/views/estate_property_views.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
</group>
4545
<group>
4646
<field name="expected_price"/>
47+
<field name="best_price"/>
4748
<field name="selling_price"/>
4849
</group>
4950
</group>
@@ -58,6 +59,7 @@
5859
<field name="garden"/>
5960
<field name="garden_area" string="Garden Area (sqm)"/>
6061
<field name="garden_orientation"/>
62+
<field name="total_area" string="Total Area (sqm)"/>
6163
</group>
6264
</page>
6365
<page string="Offers">
@@ -96,3 +98,4 @@
9698
</field>
9799
</record>
98100
</odoo>
101+

0 commit comments

Comments
 (0)