[ADD][TMP]Separation of GOLEM members and seasons (but not smart, will be reverted)

This commit is contained in:
Fabien Bourgeois 2016-07-07 17:13:58 +02:00
parent 9c87fdf81d
commit 11a355d329
8 changed files with 188 additions and 34 deletions

View File

@ -15,7 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from openerp import models, fields, api, _
from openerp import models, fields, _
class ResPartner(models.Model):
@ -39,14 +39,3 @@ class GolemMember(models.Model):
number = fields.Char('Number', size=50, index=True)
pictures_agreement = fields.Boolean('Pictures agreement?')
opt_out_sms = fields.Boolean('Out of SMS campaigns')
season_ids = fields.Many2many('golem.season', string='Seasons')
is_current = fields.Boolean('Current user?', store=True, default=False,
compute='_compute_is_current')
@api.depends('season_ids')
def _compute_is_current(self):
""" Checks if member is active for current season """
domain = [('is_default', '=', True)]
default_season = self.env['golem.season'].search(domain)
for member in self:
member.is_current = default_season in member.season_ids

View File

@ -34,9 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="name" class="oe_inline" readonly="True" />
</h1>
</div>
<group>
<field name="season_ids" widget="many2many_tags" />
</group>
</group>
<group string="Personal details">
<group>
@ -126,15 +123,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<search>
<field name="number" />
<field name="name" />
<field name="season_ids" widget="many2one" />
<field name="contact_address" />
<field name="city" />
<field name="phone" />
<field name="mobile" />
<field name="email" />
<field name="category_id" widget="many2one" />
<filter name="season_default" string="Default season"
domain="[('is_current', '=', True)]" />
<group string="Group By">
<filter name="group_age" string="By age"
context="{'group_by': 'is_minor'}"/>
@ -162,8 +156,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<act_window id="action"
name="GOLEM Members"
res_model="golem.member"
view_mode="kanban,tree,form,graph"
context="{'search_default_season_default': True}" />
view_mode="kanban,tree,form,graph" />
<record model="ir.actions.act_window.view"
id="view_kanban">
<field name="view_mode">kanban</field>

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import models

View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{
'name': 'GOLEM members seasons',
'summary': 'GOLEM non-profit members seasons glue code',
'description': ''' Link between GOLEM members and seasons, with
management of number code linked to season ''',
'version': '0.1',
'category': 'Non-profit management',
'author': 'Fabien Bourgeois',
'license': 'AGPL-3',
'application': False,
'installable': True,
'auto_install': True,
'depends': ['golem_member', 'golem_season'],
'data': ['views/golem_member_season_view.xml']
}

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import golem_member_season

View File

@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from openerp import models, fields, api
class GolemMember(models.Model):
_inherit = 'golem.member'
season_ids = fields.Many2many('golem.season', string='Seasons')
is_current = fields.Boolean('Current user?', store=True, default=False,
compute='_compute_is_current')
@api.depends('season_ids')
def _compute_is_current(self):
""" Checks if member is active for current season """
domain = [('is_default', '=', True)]
default_season = self.env['golem.season'].search(domain)
for member in self:
member.is_current = default_season in member.season_ids
class GolemSeason(models.Model):
@api.multi
def write(self, 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()
self.env['golem.activity'].search([])._compute_is_current()
return res

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<openerp>
<data>
<!-- Forms -->
<record model="ir.ui.view" id="member_season_form">
<field name="name">Add season at top of GOLEM member form</field>
<field name="model">golem.member</field>
<field name="inherit_id" ref="golem_member.view_form" />
<field name="arch" type="xml">
<div class="oe_title" position="after">
<field name="is_volunteer" />
<group>
<field name="season_ids" widget="many2many_tags" />
</group>
</div>
</field>
</record>
<!-- Searches -->
<record model="ir.ui.view" id="member_season_search">
<field name="name">Add Seasons Search and Filter</field>
<field name="model">golem.member</field>
<field name="inherit_id" ref="golem_member.view_filter" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="season_ids" widget="many2one" />
</field>
<field name="category_id" position="after">
<filter name="season_default" string="Default season"
domain="[('is_current', '=', True)]" />
</field>
</field>
</record>
<!-- Actions -->
<act_window id="action"
name="GOLEM Members"
res_model="golem.member"
view_mode="kanban,tree,form,graph"
context="{'search_default_season_default': True}" />
<!-- Menu items -->
<menuitem id="golem_member.golem_members_menu" name="GOLEM Members"
parent="membership.menu_membership" sequence="5"
action="action" />
</data>
</openerp>

View File

@ -52,17 +52,3 @@ class GolemSeason(models.Model):
msg = _('Period {} cannot be included into current '
'period'.format(s.name))
raise models.ValidationError(msg)
@api.multi
def write(self, 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()
self.env['golem.activity'].search([])._compute_is_current()
return res