forked from Yaltik/golem
[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:
parent
accb001ed4
commit
915f8cb8a4
@ -47,10 +47,7 @@ class GolemMember(models.Model):
|
|||||||
@api.depends('season_ids')
|
@api.depends('season_ids')
|
||||||
def _compute_is_current(self):
|
def _compute_is_current(self):
|
||||||
""" Checks if member is active for current season """
|
""" 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:
|
for member in self:
|
||||||
is_current = False
|
member.is_current = default_season in member.season_ids
|
||||||
for s in member.season_ids:
|
|
||||||
if s.date_start <= today <= s.date_end:
|
|
||||||
is_current = True
|
|
||||||
member.is_current = is_current
|
|
||||||
|
@ -133,7 +133,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<field name="mobile" />
|
<field name="mobile" />
|
||||||
<field name="email" />
|
<field name="email" />
|
||||||
<field name="category_id" widget="many2one" />
|
<field name="category_id" widget="many2one" />
|
||||||
<filter name="season_current" string="Current season"
|
<filter name="season_default" string="Default season"
|
||||||
domain="[('is_current', '=', True)]" />
|
domain="[('is_current', '=', True)]" />
|
||||||
<group string="Group By">
|
<group string="Group By">
|
||||||
<filter name="group_city" string="By city"
|
<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"
|
name="GOLEM Members"
|
||||||
res_model="golem.member"
|
res_model="golem.member"
|
||||||
view_mode="kanban,tree,form,graph"
|
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"
|
<record model="ir.actions.act_window.view"
|
||||||
id="golem_member_view_kanban">
|
id="golem_member_view_kanban">
|
||||||
<field name="view_mode">kanban</field>
|
<field name="view_mode">kanban</field>
|
||||||
|
@ -27,6 +27,7 @@ class GolemSeason(models.Model):
|
|||||||
name = fields.Char('Season name')
|
name = fields.Char('Season name')
|
||||||
date_start = fields.Date('Period start')
|
date_start = fields.Date('Period start')
|
||||||
date_end = fields.Date('Period end')
|
date_end = fields.Date('Period end')
|
||||||
|
is_default = fields.Boolean('Default season for views?')
|
||||||
|
|
||||||
@api.constrains('date_start', 'date_end')
|
@api.constrains('date_start', 'date_end')
|
||||||
def _check_period(self):
|
def _check_period(self):
|
||||||
@ -54,10 +55,13 @@ class GolemSeason(models.Model):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def write(self, values):
|
def write(self, values):
|
||||||
""" Extends write to recomputes all current members in case of date
|
""" Extends write to recomputes all current members in case of
|
||||||
changes """
|
is_default changes and ensures that only one is_default is active """
|
||||||
date_start = values.get('date_start')
|
is_new_default = values.get('is_default')
|
||||||
date_end = values.get('date_end')
|
old_default_season = self.search([('is_default', '=', True)])
|
||||||
if date_start or date_end:
|
res = super(GolemSeason, self).write(values)
|
||||||
self.env['golem.member']._compute_is_current()
|
if is_new_default:
|
||||||
return super(GolemSeason, self).write(values)
|
if old_default_season:
|
||||||
|
old_default_season.is_default = False
|
||||||
|
self.env['golem.member'].search([])._compute_is_current()
|
||||||
|
return res
|
||||||
|
@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<sheet>
|
<sheet>
|
||||||
<group string="Season">
|
<group string="Season">
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
|
<field name="is_default" />
|
||||||
<field name="date_start" />
|
<field name="date_start" />
|
||||||
<field name="date_end" />
|
<field name="date_end" />
|
||||||
</group>
|
</group>
|
||||||
@ -44,6 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree>
|
<tree>
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
|
<field name="is_default" />
|
||||||
<field name="date_start" />
|
<field name="date_start" />
|
||||||
<field name="date_end" />
|
<field name="date_end" />
|
||||||
</tree>
|
</tree>
|
||||||
@ -57,6 +59,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<search>
|
<search>
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
|
<filter name="default_season" string="Default season"
|
||||||
|
domain="[('is_default', '=', True)]" />
|
||||||
</search>
|
</search>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
Loading…
Reference in New Issue
Block a user