Skip to content

Commit 0a4e7af

Browse files
committed
[IMP] estate: sync offer validity and deadlines
To provide maximum flexibility during property negotiations, sales agents need the ability to define an offer's expiration either by a specific calendar date or a set number of days. By bidirectionally synchronizing the validity duration with the hard deadline date, the system prevents manual calculation errors and ensures agents can seamlessly negotiate using whichever metric the buyer prefers. This guarantees data consistency across the offer records regardless of which field the user manipulates on the interface. Chapter: Chapter 8: Computed Fields And Onchanges Task: [Insert Task Number]
1 parent c2e311c commit 0a4e7af

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

estate/models/estate_property.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class EstateProperty(models.Model):
1717
living_area = fields.Integer(string="Living Area(sqm)")
1818
facades = fields.Integer()
1919
garage = fields.Boolean()
20-
garden = fields.Boolean(string="Garden Area(sqm)")
21-
garden_area = fields.Integer()
20+
garden = fields.Boolean()
21+
garden_area = fields.Integer(string="Garden Area(sqm)")
2222
garden_orientation = fields.Selection(
2323
string="Garden Orientation",
2424
selection=[
@@ -60,3 +60,13 @@ def _compute_best_price(self):
6060
for records in self:
6161
prices = records.mapped("offer.price")
6262
records.best_price = max(prices) if prices else 0
63+
64+
@api.onchange("garden")
65+
def _on_change_garden(self):
66+
for records in self:
67+
if records.garden:
68+
records.garden_area = 10
69+
records.garden_orientation = "north"
70+
else:
71+
records.garden_area = False
72+
records.garden_orientation = False

estate/models/estate_property_offer.py

Lines changed: 16 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 EstatePropertyOffer(models.Model):
@@ -15,3 +15,18 @@ class EstatePropertyOffer(models.Model):
1515
)
1616
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
1717
property_id = fields.Many2one("estate.property", string="Property", required=True)
18+
validity = fields.Integer(default=7)
19+
date_deadline = fields.Date(compute="_compute_date_deadline", inverse="_inverse_date_deadline")
20+
21+
@api.depends("create_date","validity")
22+
def _compute_date_deadline(self):
23+
for records in self:
24+
base_date = records.create_date.date() if records.create_date else fields.Date.today()
25+
records.date_deadline = fields.Date.add(base_date,days=records.validity)
26+
27+
def _inverse_date_deadline(self):
28+
for records in self:
29+
base_date = records.create_date.date() if records.create_date else fields.Date.today()
30+
if records.date_deadline:
31+
records.validity = (records.date_deadline - base_date).days
32+

estate/views/estate_property_offer_views.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<list>
99
<field name="price" />
1010
<field name="partner_id" />
11+
<field name="validity" />
12+
<field name="date_deadline" />
1113
<field name="status" />
1214
</list>
1315
</field>
@@ -22,6 +24,8 @@
2224
<group>
2325
<field name="price" />
2426
<field name="partner_id" />
27+
<field name="validity" />
28+
<field name="date_deadline" />
2529
<field name="status" />
2630
</group>
2731
</sheet>

0 commit comments

Comments
 (0)