forked from Yaltik/golem
[IMP]GOLEM Member : be able to search only current season members, with automated computing of current and handling of seasons dates changes
This commit is contained in:
parent
b27084fe73
commit
e18bc7f55d
@ -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
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
@ -41,3 +41,16 @@ class GolemMember(models.Model):
|
||||
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 """
|
||||
today = fields.Date.context_today(self)
|
||||
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
|
||||
|
@ -131,6 +131,8 @@ 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="Is active in current season"
|
||||
domain="[('is_current', '=', True)]" />
|
||||
<group string="Group By">
|
||||
<filter name="group_city" string="By city"
|
||||
context="{'group_by': 'city'}"/>
|
||||
|
@ -27,6 +27,6 @@
|
||||
'license': 'AGPL-3',
|
||||
'application': False,
|
||||
'installable': True,
|
||||
'depends': ['membership'],
|
||||
'depends': ['golem_member'],
|
||||
'data': ['views/golem_season_view.xml']
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ class GolemSeason(models.Model):
|
||||
else:
|
||||
seasons = self.env['golem.season'].search([])
|
||||
for s in seasons:
|
||||
print s.name
|
||||
if s.date_start < season.date_start < s.date_end:
|
||||
msg = _('Start of the period is in range of an '
|
||||
'existing period {}'.format(s.name))
|
||||
@ -52,3 +51,13 @@ 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 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user