diff --git a/golem_member/models/golem_member.py b/golem_member/models/golem_member.py
index a7560c6..4fae876 100644
--- a/golem_member/models/golem_member.py
+++ b/golem_member/models/golem_member.py
@@ -47,10 +47,7 @@ class GolemMember(models.Model):
@api.depends('season_ids')
def _compute_is_current(self):
""" Checks if member is active for current season """
- today = fields.Date.context_today(self)
+ domain = [('is_default', '=', True)]
+ default_season = self.env['golem.season'].search(domain)
for member in self:
- is_current = False
- for s in member.season_ids:
- if s.date_start <= today <= s.date_end:
- is_current = True
- member.is_current = is_current
+ member.is_current = default_season in member.season_ids
diff --git a/golem_member/views/golem_member_view.xml b/golem_member/views/golem_member_view.xml
index aa80783..f2d2eb2 100644
--- a/golem_member/views/golem_member_view.xml
+++ b/golem_member/views/golem_member_view.xml
@@ -133,7 +133,7 @@ along with this program. If not, see .
-
.
name="GOLEM Members"
res_model="golem.member"
view_mode="kanban,tree,form,graph"
- context="{'search_default_season_current': True}" />
+ context="{'search_default_season_default': True}" />
kanban
diff --git a/golem_season/models/golem_season.py b/golem_season/models/golem_season.py
index d1796c9..3466618 100644
--- a/golem_season/models/golem_season.py
+++ b/golem_season/models/golem_season.py
@@ -27,6 +27,7 @@ class GolemSeason(models.Model):
name = fields.Char('Season name')
date_start = fields.Date('Period start')
date_end = fields.Date('Period end')
+ is_default = fields.Boolean('Default season for views?')
@api.constrains('date_start', 'date_end')
def _check_period(self):
@@ -54,10 +55,13 @@ class GolemSeason(models.Model):
@api.multi
def write(self, values):
- """ Extends write to recomputes all current members in case of date
- changes """
- date_start = values.get('date_start')
- date_end = values.get('date_end')
- if date_start or date_end:
- self.env['golem.member']._compute_is_current()
- return super(GolemSeason, self).write(values)
+ """ Extends write to recomputes all current members in case of
+ is_default changes and ensures that only one is_default is active """
+ is_new_default = values.get('is_default')
+ old_default_season = self.search([('is_default', '=', True)])
+ res = super(GolemSeason, self).write(values)
+ if is_new_default:
+ if old_default_season:
+ old_default_season.is_default = False
+ self.env['golem.member'].search([])._compute_is_current()
+ return res
diff --git a/golem_season/views/golem_season_view.xml b/golem_season/views/golem_season_view.xml
index 14a9f65..e1c2efa 100644
--- a/golem_season/views/golem_season_view.xml
+++ b/golem_season/views/golem_season_view.xml
@@ -29,6 +29,7 @@ along with this program. If not, see .
+
@@ -44,6 +45,7 @@ along with this program. If not, see .
+
@@ -57,6 +59,8 @@ along with this program. If not, see .
+