diff --git a/models/event.py b/models/event.py
index 96144b5..07a3b51 100644
--- a/models/event.py
+++ b/models/event.py
@@ -2,6 +2,7 @@
""" Event module """
+from datetime import datetime
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
@@ -15,17 +16,39 @@ class Event(models.Model):
manager_id = fields.Many2one('coworking.coworker', 'Manager', index=True,
domain="[('coworker_type', 'in', ['staffer', 'member'])]")
date_start = fields.Datetime(default=fields.Date.context_today, required=True)
+ starts_this_week = fields.Integer(compute='_compute_starts_this_week',
+ search='_search_starts_this_week')
date_end = fields.Datetime(required=True)
duration = fields.Float(compute='_compute_duration')
description = fields.Text()
statut = fields.Selection([('draft', 'Draft'),
('confirmed', 'Confirmed'),
- ('canceled', 'Canceled')], default='draft')
+ ('canceled', 'Canceled')], default='canceled')
participants_ids = fields.Many2many('coworking.coworker', string='Subscribers')
participants_count = fields.Integer('Number of participants',
compute='_compute_participants_count')
+ participants_count2 = fields.Integer('Number of participants #2',
+ compute='_compute_participants_count')
+
+ @api.depends('date_start')
+ def _compute_starts_this_week(self):
+ """ Computes is event starts this week """
+ for event in self:
+ date_start = fields.Datetime.from_string(event.date_start)
+ week_start = date_start.isocalendar()[1]
+ event.starts_this_week = (datetime.now().isocalendar()[1] == week_start)
+
+ def _search_starts_this_week(self, operator, value):
+ """ Searches function for starts_this_week """
+ res_ids = []
+ for event in self.search([]):
+ date_start = fields.Datetime.from_string(event.date_start)
+ week_start = date_start.isocalendar()[1]
+ if datetime.now().isocalendar()[1] == week_start:
+ res_ids.append(event.id)
+ return [('id', 'in', res_ids)]
@api.depends('participants_ids')
def _compute_participants_count(self):
diff --git a/views/event_menu.xml b/views/event_menu.xml
index 41e46ac..ed894a7 100644
--- a/views/event_menu.xml
+++ b/views/event_menu.xml
@@ -4,7 +4,8 @@
+ res_model="coworking.event" view_mode="tree,form"
+ context="{'search_default_status_confirmed': True, 'search_default_status_draft': True}" />
diff --git a/views/event_views.xml b/views/event_views.xml
index 4346b9e..53e9b9e 100644
--- a/views/event_views.xml
+++ b/views/event_views.xml
@@ -16,6 +16,7 @@
+
@@ -50,30 +51,30 @@
-
+
-
-
-
+
+
+
+
-
+
-
+
+
+
-
-
-
-
-