[FIX] doc: replace from_string methods to native datetime calls

closes odoo/odoo#31093
This commit is contained in:
Yenthe666
2019-02-25 15:14:09 +00:00
committed by Xavier Morel
parent aa5de574aa
commit cc0e654876
4 changed files with 8 additions and 11 deletions
+3 -6
View File
@@ -21,7 +21,7 @@ diff --git a/openacademy/models.py b/openacademy/models.py
@api.depends('seats', 'attendee_ids')
def _taken_seats(self):
@@ -83,6 +86,30 @@ class Session(models.Model):
@@ -83,6 +86,27 @@ class Session(models.Model):
},
}
@@ -34,9 +34,8 @@ diff --git a/openacademy/models.py b/openacademy/models.py
+
+ # Add duration to start_date, but: Monday + 5 days = Saturday, so
+ # subtract one second to get on Friday instead
+ start = fields.Datetime.from_string(r.start_date)
+ duration = timedelta(days=r.duration, seconds=-1)
+ r.end_date = start + duration
+ r.end_date = r.start_date + duration
+
+ def _set_end_date(self):
+ for r in self:
@@ -45,9 +44,7 @@ diff --git a/openacademy/models.py b/openacademy/models.py
+
+ # Compute the difference between dates, but: Friday - Monday = 4 days,
+ # so add one day to get 5 days instead
+ start_date = fields.Datetime.from_string(r.start_date)
+ end_date = fields.Datetime.from_string(r.end_date)
+ r.duration = (end_date - start_date).days + 1
+ r.duration = (r.end_date - r.start_date).days + 1
+
@api.constrains('instructor_id', 'attendee_ids')
def _check_instructor_not_in_attendees(self):
+3 -3
View File
@@ -15,9 +15,9 @@ diff --git a/openacademy/models.py b/openacademy/models.py
@api.depends('seats', 'attendee_ids')
def _taken_seats(self):
for r in self:
@@ -110,6 +113,15 @@ class Session(models.Model):
end_date = fields.Datetime.from_string(r.end_date)
r.duration = (end_date - start_date).days + 1
@@ -107,6 +110,15 @@ class Session(models.Model):
# so add one day to get 5 days instead
r.duration = (r.end_date - r.start_date).days + 1
+ @api.depends('duration')
+ def _get_hours(self):
+1 -1
View File
@@ -15,7 +15,7 @@ diff --git a/openacademy/models.py b/openacademy/models.py
@api.depends('seats', 'attendee_ids')
def _taken_seats(self):
for r in self:
@@ -122,6 +125,11 @@ class Session(models.Model):
@@ -119,6 +122,11 @@ class Session(models.Model):
for r in self:
r.duration = r.hours / 24
+1 -1
View File
@@ -48,7 +48,7 @@ diff --git a/openacademy/models.py b/openacademy/models.py
},
}
@@ -135,4 +135,4 @@ class Session(models.Model):
@@ -132,4 +132,4 @@ class Session(models.Model):
def _check_instructor_not_in_attendees(self):
for r in self:
if r.instructor_id and r.instructor_id in r.attendee_ids: