diff --git a/golem_member/models/golem_member.py b/golem_member/models/golem_member.py index 2a02b1e..7820343 100644 --- a/golem_member/models/golem_member.py +++ b/golem_member/models/golem_member.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from openerp import models, fields, _ +from openerp import models, fields, api, _ class ResPartner(models.Model): @@ -39,3 +39,14 @@ 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 diff --git a/golem_member/views/golem_member_view.xml b/golem_member/views/golem_member_view.xml index 1223c49..9943e7f 100644 --- a/golem_member/views/golem_member_view.xml +++ b/golem_member/views/golem_member_view.xml @@ -34,6 +34,9 @@ along with this program. If not, see . + + + @@ -123,12 +126,15 @@ along with this program. If not, see . + + @@ -156,7 +162,8 @@ along with this program. If not, see . + view_mode="kanban,tree,form,graph" + context="{'search_default_season_default': True}" /> kanban diff --git a/golem_member_season/__init__.py b/golem_member_season/__init__.py deleted file mode 100644 index 2fca3d2..0000000 --- a/golem_member_season/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2016 Fabien Bourgeois -# -# 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 . - -from . import models diff --git a/golem_member_season/__openerp__.py b/golem_member_season/__openerp__.py deleted file mode 100644 index 9688ee6..0000000 --- a/golem_member_season/__openerp__.py +++ /dev/null @@ -1,32 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2016 Fabien Bourgeois -# -# 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 . - -{ - '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'] -} diff --git a/golem_member_season/models/__init__.py b/golem_member_season/models/__init__.py deleted file mode 100644 index ea7d215..0000000 --- a/golem_member_season/models/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2016 Fabien Bourgeois -# -# 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 . - -from . import golem_member_season diff --git a/golem_member_season/models/golem_member_season.py b/golem_member_season/models/golem_member_season.py deleted file mode 100644 index c87d30f..0000000 --- a/golem_member_season/models/golem_member_season.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2016 Fabien Bourgeois -# -# 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 . - -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 diff --git a/golem_member_season/views/golem_member_season_view.xml b/golem_member_season/views/golem_member_season_view.xml deleted file mode 100644 index a4e7460..0000000 --- a/golem_member_season/views/golem_member_season_view.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - Add season at top of GOLEM member form - golem.member - - -
- - - - -
-
-
- - - - Add Seasons Search and Filter - golem.member - - - - - - - - - - - - - - - - - -
-
diff --git a/golem_season/models/golem_season.py b/golem_season/models/golem_season.py index 0c54e8a..57aff77 100644 --- a/golem_season/models/golem_season.py +++ b/golem_season/models/golem_season.py @@ -52,3 +52,17 @@ 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