2019-01-14 11:49:11 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright 2019 Fabien Bourgeois <fabien@yaltik.com>
|
|
|
|
# Copyright 2019 Youssef El Ouahby <youssef@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/>.
|
|
|
|
|
|
|
|
""" GOLEM Activity Registration Analysis Wizard Management """
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from odoo import models, fields, api, _
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class GolemActivityRegistrationAnalysisWizard(models.TransientModel):
|
|
|
|
""" GOLEM Activity Registration Analysis Wizard Management """
|
|
|
|
_name = 'golem.activity.registration.analysis.wizard'
|
|
|
|
_description = 'GOLEM Activity Registration Analysis Wizard Management '
|
|
|
|
|
2019-01-21 11:52:26 +01:00
|
|
|
def default_season(self):
|
|
|
|
""" Get default season """
|
|
|
|
domain = [('is_default', '=', True)]
|
|
|
|
return self.env['golem.season'].search(domain, limit=1)
|
|
|
|
|
2019-01-21 12:14:43 +01:00
|
|
|
name = fields.Char(default='/')
|
2019-01-21 11:52:26 +01:00
|
|
|
season_id = fields.Many2one('golem.season', 'Season', required=True,
|
|
|
|
default=default_season, ondelete='cascade')
|
|
|
|
season_start = fields.Date(related='season_id.date_start')
|
|
|
|
season_end = fields.Date(related='season_id.date_end')
|
|
|
|
analyse_type = fields.Selection([('activity_area', 'By area and activity')],
|
|
|
|
default='activity_area', required=True)
|
|
|
|
age_computing = fields.Selection([('season_start', 'At season start'),
|
|
|
|
('season_end', 'At season stop'),
|
|
|
|
('now', 'Now')], required=True,
|
|
|
|
default='season_start', string='Age')
|
2019-01-14 11:49:11 +01:00
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def get_pivot_view(self):
|
2019-01-14 14:34:44 +01:00
|
|
|
""" get pivot view """
|
2019-01-14 11:49:11 +01:00
|
|
|
self.ensure_one()
|
|
|
|
rec = self[0]
|
2019-01-21 11:52:26 +01:00
|
|
|
ref = u''
|
|
|
|
if rec.age_computing == 'season_start':
|
|
|
|
if rec.analyse_type == 'activity_area':
|
|
|
|
ref = (u'golem_activity_registration.'
|
|
|
|
'golem_member_analysis_pivot_age_start_activity_area')
|
|
|
|
elif rec.age_computing == 'season_end':
|
|
|
|
if rec.analyse_type == 'activity_area':
|
|
|
|
ref = (u'golem_activity_registration.'
|
|
|
|
'golem_member_analysis_pivot_age_end_activity_area')
|
|
|
|
else: # now
|
|
|
|
if rec.analyse_type == 'activity_area':
|
|
|
|
ref = (u'golem_activity_registration.'
|
|
|
|
'golem_member_analysis_pivot_age_now_activity_area')
|
|
|
|
return self.env.ref(ref, False)
|
2019-01-14 11:49:11 +01:00
|
|
|
|
2019-01-21 12:20:36 +01:00
|
|
|
@api.multi
|
|
|
|
def get_registrations(self):
|
|
|
|
""" Returns registrations """
|
|
|
|
self.ensure_one()
|
|
|
|
return self.env['golem.activity.registration'].search(
|
|
|
|
[('season_id', '=', self[0].season_id.id)]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-01-14 11:49:11 +01:00
|
|
|
@api.multi
|
2019-01-21 11:52:26 +01:00
|
|
|
def registration_analyse(self):
|
2019-01-14 14:34:44 +01:00
|
|
|
""" registration analyse """
|
2019-01-14 11:49:11 +01:00
|
|
|
self.ensure_one()
|
|
|
|
analysis_rec = self[0]
|
2019-01-21 12:20:36 +01:00
|
|
|
registrations = analysis_rec.get_registrations()
|
2019-01-14 11:49:11 +01:00
|
|
|
if registrations:
|
|
|
|
for registration in registrations:
|
|
|
|
self.env['golem.member.analysis'].create({
|
|
|
|
'season_id': analysis_rec.season_id.id,
|
|
|
|
'member_id': registration.member_id.id,
|
2019-01-21 12:10:22 +01:00
|
|
|
'activity_id': registration.activity_id.id,
|
|
|
|
'resgistration_analysis_id': analysis_rec.id
|
2019-01-14 11:49:11 +01:00
|
|
|
})
|
2019-01-21 11:52:26 +01:00
|
|
|
analyse_pivot = analysis_rec.get_pivot_view()
|
|
|
|
return {
|
2019-01-21 12:14:43 +01:00
|
|
|
'name': _('Registration Analysis'),
|
2019-01-21 11:52:26 +01:00
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
'res_model': 'golem.member.analysis',
|
2019-01-21 12:10:22 +01:00
|
|
|
'domain': [('resgistration_analysis_id', '=', analysis_rec.id)],
|
2019-01-21 11:52:26 +01:00
|
|
|
'view_type': 'pivot',
|
|
|
|
'view_mode': 'pivot',
|
|
|
|
'view_id': analyse_pivot.id,
|
|
|
|
'target': 'current',
|
|
|
|
}
|