diff --git a/odex25_ensan/odex_takaful/models/donation_details_lines.py b/odex25_ensan/odex_takaful/models/donation_details_lines.py
index 4c4410522..6e23d1321 100644
--- a/odex25_ensan/odex_takaful/models/donation_details_lines.py
+++ b/odex25_ensan/odex_takaful/models/donation_details_lines.py
@@ -101,30 +101,52 @@ class DonationsDetailsLines(models.Model):
ages = fields.Integer(compute='_compute_get_age_range' , store=True)
waiting_date = fields.Date(
string="تاريخ الانتظار",
- compute="_compute_dates",
- store=True
)
- replace_date = fields.Date(
- string="تاريخ الاستبدال",
- compute="_compute_dates",
- store=True
- )
+ period_display = fields.Char(
+ string="Period",
+ compute="_compute_period_display" )
- @api.depends('state')
+ @api.depends('end_date', 'waiting_date')
+ def _compute_period_display(self):
+ today = date.today()
+ print('Hiiiii')
+ for rec in self:
+
+ # pick whichever date is set
+ if rec.state == 'replace' :
+ base_date = rec.end_date
+ elif rec.state == 'waiting':
+ base_date = rec.waiting_date
+ else:
+ base_date = False
+ print('Base >>> ' , base_date)
+ if base_date:
+ print('rec.waiting_date >>> ' , rec.waiting_date)
+ delta = relativedelta(today, base_date)
+ print('rec.delta >>> ' , str(delta))
+ # build human-readable string
+ if delta.years > 0:
+ rec.period_display = f"{delta.years} year(s)"
+ elif delta.months > 0:
+ rec.period_display = f"{delta.months} month(s)"
+ elif delta.days > 0:
+ rec.period_display = f"{delta.days} day(s)"
+ else:
+ rec.period_display = "Today"
+ else:
+ rec.period_display = "No date"
+
+
+
+ @api.constrains('state')
def _compute_dates(self):
"""Automatically set waiting_date or replace_date based on state."""
for rec in self:
if rec.state == 'waiting':
- print(date.today())
rec.waiting_date = date.today()
- rec.replace_date = False
- elif rec.state == 'replace':
- rec.replace_date = date.today()
- rec.waiting_date = False
else:
rec.waiting_date = False
- rec.replace_date = False
# cheque_number = fields.Integer(string="Cheque Number")
diff --git a/odex25_ensan/odex_takaful/views/donations_details_lines.xml b/odex25_ensan/odex_takaful/views/donations_details_lines.xml
index 1268e2518..82b8ea3b1 100644
--- a/odex25_ensan/odex_takaful/views/donations_details_lines.xml
+++ b/odex25_ensan/odex_takaful/views/donations_details_lines.xml
@@ -86,7 +86,6 @@
-
-
+
+
@@ -354,6 +354,98 @@
+
+ donations.details.lines.view.tree.waiting
+ donations.details.lines
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ donations.details.lines.view.tree.replace
+ donations.details.lines
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Donations Details Lines
donations.details.lines
@@ -368,6 +460,9 @@
tree,form
[('state', '=', 'waiting')]
+
{'create': False, 'delete': False}
@@ -376,6 +471,9 @@
donations.details.lines
tree,form
[('state', '=', 'replace')]
+
{'create': False, 'delete': False}