Skip to content
Permalink
Browse files

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

  • Loading branch information...
Yenthe666 authored and Feyensv committed Feb 14, 2019
1 parent 04d0da8 commit c59da4b8008bb6ab756b7b6578699d20673ce98d
Showing with 18 additions and 18 deletions.
  1. +12 −12 doc/howtos/backend/exercise-calendar
  2. +6 −6 doc/howtos/backend/exercise-gantt
@@ -7,24 +7,24 @@ diff --git a/openacademy/models.py b/openacademy/models.py
+++ b/openacademy/models.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

+from datetime import timedelta
from odoo import models, fields, api, exceptions

class Course(models.Model):
@@ -57,6 +58,8 @@ class Session(models.Model):
attendee_ids = fields.Many2many('res.partner', string="Attendees")

taken_seats = fields.Float(string="Taken seats", compute='_taken_seats')
+ end_date = fields.Date(string="End Date", store=True,
+ compute='_get_end_date', inverse='_set_end_date')

@api.depends('seats', 'attendee_ids')
def _taken_seats(self):
@@ -83,6 +86,30 @@ class Session(models.Model):
},
}

+ @api.depends('start_date', 'duration')
+ def _get_end_date(self):
+ for r in self:
@@ -34,9 +34,9 @@ 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 +45,9 @@ 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):
@@ -58,7 +58,7 @@ diff --git a/openacademy/views/openacademy.xml b/openacademy/views/openacademy.x
@@ -125,11 +125,22 @@
</field>
</record>

+ <!-- calendar view -->
+ <record model="ir.ui.view" id="session_calendar_view">
+ <field name="name">session.calendar</field>
@@ -77,5 +77,5 @@ diff --git a/openacademy/views/openacademy.xml b/openacademy/views/openacademy.x
- <field name="view_mode">tree,form</field>
+ <field name="view_mode">tree,form,calendar</field>
</record>

<menuitem id="session_menu" name="Sessions"
@@ -8,17 +8,17 @@ diff --git a/openacademy/models.py b/openacademy/models.py
@@ -61,6 +61,9 @@ class Session(models.Model):
end_date = fields.Date(string="End Date", store=True,
compute='_get_end_date', inverse='_set_end_date')

+ hours = fields.Float(string="Duration in hours",
+ compute='_get_hours', inverse='_set_hours')
+
@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

r.duration = (r.end_date - r.start_date).days + 1

+ @api.depends('duration')
+ def _get_hours(self):
+ for r in self:
@@ -37,7 +37,7 @@ diff --git a/openacademy/views/openacademy.xml b/openacademy/views/openacademy.x
@@ -143,11 +143,23 @@
</field>
</record>

+ <record model="ir.ui.view" id="session_gantt_view">
+ <field name="name">session.gantt</field>
+ <field name="model">openacademy.session</field>
@@ -57,5 +57,5 @@ diff --git a/openacademy/views/openacademy.xml b/openacademy/views/openacademy.x
- <field name="view_mode">tree,form,calendar</field>
+ <field name="view_mode">tree,form,calendar,gantt</field>
</record>

<menuitem id="session_menu" name="Sessions"

0 comments on commit c59da4b

Please sign in to comment.
You can’t perform that action at this time.