Skip to content

Commit d623609

Browse files
committed
[FIX] estate: use context_today to avoid timezone issues
- use context_today to avoid timezone issues - also inline the reference date calculation for clarity and remove the corresponding function
1 parent 27c446d commit d623609

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

estate/models/estate_property_offer.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ class EstatePropertyOffer(models.Model):
2929
@api.depends("create_date", "validity")
3030
def _compute_deadline(self) -> None:
3131
for record in self:
32-
record.date_deadline = _get_reference_date(record) + relativedelta(days=record.validity)
32+
ref_date = fields.Date.context_today(self) if not record.create_date else record.create_date.date()
33+
record.date_deadline = ref_date + relativedelta(days=record.validity)
3334

3435
def _inverse_deadline(self) -> None:
3536
for record in self:
36-
record.validity = (record.date_deadline - _get_reference_date(record)).days
37+
ref_date = fields.Date.context_today(self) if not record.create_date else record.create_date.date()
38+
record.validity = (record.date_deadline - ref_date).days
3739

3840
# CRUD overrides
3941
@api.model
@@ -70,7 +72,3 @@ def action_refuse(self) -> bool:
7072
"CHECK(price > 0)",
7173
"An offer's price must be strictly greater than 0.",
7274
)
73-
74-
75-
def _get_reference_date(offer: EstatePropertyOffer) -> date:
76-
return fields.Date.today() if not offer.create_date else offer.create_date.date()

0 commit comments

Comments
 (0)