[IMP]GOLEM Seasons management : choose default season, once only possible and recomputes is_current according to new way of doing

This commit is contained in:
Fabien Bourgeois 2016-06-26 09:24:57 +02:00
parent accb001ed4
commit 915f8cb8a4
4 changed files with 20 additions and 15 deletions

View File

@ -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

View File

@ -133,7 +133,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="mobile" />
<field name="email" />
<field name="category_id" widget="many2one" />
<filter name="season_current" string="Current season"
<filter name="season_default" string="Default season"
domain="[('is_current', '=', True)]" />
<group string="Group By">
<filter name="group_city" string="By city"
@ -159,7 +159,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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}" />
<record model="ir.actions.act_window.view"
id="golem_member_view_kanban">
<field name="view_mode">kanban</field>

View File

@ -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

View File

@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<sheet>
<group string="Season">
<field name="name" />
<field name="is_default" />
<field name="date_start" />
<field name="date_end" />
</group>
@ -44,6 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="is_default" />
<field name="date_start" />
<field name="date_end" />
</tree>
@ -57,6 +59,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="arch" type="xml">
<search>
<field name="name" />
<filter name="default_season" string="Default season"
domain="[('is_default', '=', True)]" />
</search>
</field>
</record>