Skip to content

Commit d33c5b0

Browse files
author
SurryaT10
committed
[IMP] Added computed fields - total_area and best_offer
total_area field is based on the size of both garden_area and living_area best_offer field is based on the max price among the list of offers Also added validity and deadline for the offers as a computed and inverse function impacting each other.
1 parent f337b30 commit d33c5b0

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

estate/models/estate.py

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

33

44
class Estate(models.Model):
@@ -32,3 +32,24 @@ class Estate(models.Model):
3232
salesperson_id = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user)
3333
tag_ids = fields.Many2many('estate.property.tag', string="Tags")
3434
offer_ids = fields.One2many('estate.property.offer', 'property_id', string="Offers")
35+
total_area = fields.Integer('Total Area (sqm)', compute='_compute_total_area')
36+
best_price = fields.Float("Best Offer", compute='_compute_best_price')
37+
38+
@api.depends('living_area', 'garden_area')
39+
def _compute_total_area(self):
40+
for record in self:
41+
record.total_area = record.living_area + record.garden_area
42+
43+
@api.depends('offer_ids.price')
44+
def _compute_best_price(self):
45+
for record in self:
46+
record.best_price = max(record.offer_ids.mapped('price'))
47+
48+
@api.onchange("garden")
49+
def _onchange_garden(self):
50+
if self.garden:
51+
self.garden_area = 10
52+
self.garden_orientation = 'north'
53+
else:
54+
self.garden_area = 0
55+
self.garden_orientation = False

estate/models/offer.py

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

33

44
class Offer(models.Model):
@@ -12,3 +12,16 @@ class Offer(models.Model):
1212
copy=False)
1313
partner_id = fields.Many2one('res.partner', string="Partner", required=True)
1414
property_id = fields.Many2one('estate.property', string="Property", required=True)
15+
validity = fields.Integer('Validity (days)', default=7)
16+
date_deadline = fields.Date("Deadline", compute='_compute_date_deadline', inverse="_inverse_date_deadline")
17+
18+
@api.depends('validity', 'create_date')
19+
def _compute_date_deadline(self):
20+
for record in self:
21+
create_date = record.create_date if record.create_date else fields.Date.today()
22+
record.date_deadline = fields.Date.add(create_date, days=record.validity)
23+
24+
def _inverse_date_deadline(self):
25+
for record in self:
26+
create_date = record.create_date if record.create_date else fields.Date.today()
27+
record.validity = (record.date_deadline - create_date.date()).days

estate/views/estate_property_views.xml

Lines changed: 5 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"/>
6061
<field name="garden_orientation"/>
62+
<field name="total_area"/>
6163
</group>
6264
</page>
6365
<page string="Offers">
@@ -66,6 +68,9 @@
6668
<field name="price"/>
6769
<field name="status"/>
6870
<field name="partner_id"/>
71+
<field name="validity"/>
72+
<field name="date_deadline"/>
73+
<field name="status"/>
6974
</list>
7075
</field>
7176
</page>

0 commit comments

Comments
 (0)