Fabien BOURGEOIS
48507f10d6
* Small / medium refactoring on analysis ; * Usage of current instead of new ; * Renamings / typos.
107 lines
4.4 KiB
Python
107 lines
4.4 KiB
Python
# -*- 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 Members Analysis Management """
|
|
|
|
import logging
|
|
from odoo import models, fields, api, _
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
class GolemMemberAnalysis(models.TransientModel):
|
|
""" GOLEM Members Analysis Management """
|
|
_name = 'golem.member.analysis.wizard'
|
|
_description = 'GOLEM Members Analysis Wizard Management'
|
|
|
|
def default_season(self):
|
|
""" Get default season """
|
|
domain = [('is_default', '=', True)]
|
|
return self.env['golem.season'].search(domain, limit=1)
|
|
|
|
name = fields.Char(default='Service User Analysis')
|
|
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([('gender', 'By gender'), ('area', 'By area'),
|
|
('tag', 'By tag')], required=True,
|
|
default='gender')
|
|
age_computing = fields.Selection([('season_start', 'At season start'),
|
|
('season_end', 'At season stop'),
|
|
('now', 'Now')], required=True,
|
|
default='season_start', string='Age')
|
|
category_id = fields.Many2one('res.partner.category', ondelete='cascade')
|
|
|
|
|
|
@api.multi
|
|
def get_pivot_view(self):
|
|
""" Get pivot view """
|
|
self.ensure_one()
|
|
rec = self[0]
|
|
ref = u''
|
|
if rec.age_computing == 'season_start':
|
|
if rec.analyse_type == 'gender':
|
|
ref = u'golem_member.golem_member_analysis_pivot_age_start_gender'
|
|
elif rec.analyse_type == 'area':
|
|
ref = u'golem_member.golem_member_analysis_pivot_age_start_area'
|
|
else: # Tag
|
|
ref = u'golem_member.golem_member_analysis_pivot_age_start_tag'
|
|
elif rec.age_computing == 'season_end':
|
|
if rec.analyse_type == 'gender':
|
|
ref = u'golem_member.golem_member_analysis_pivot_age_end_gender'
|
|
elif rec.analyse_type == 'area':
|
|
ref = u'golem_member.golem_member_analysis_pivot_age_end_area'
|
|
else: # Tag
|
|
ref = u'golem_member.golem_member_analysis_pivot_age_end_tag'
|
|
else: # now
|
|
if rec.analyse_type == 'gender':
|
|
ref = u'golem_member.golem_member_analysis_pivot_age_now_gender'
|
|
elif rec.analyse_type == 'area':
|
|
ref = u'golem_member.golem_member_analysis_pivot_age_now_area'
|
|
else: # Tag
|
|
ref = u'golem_member.golem_member_analysis_pivot_age_now_tag'
|
|
return self.env.ref(ref)
|
|
|
|
|
|
|
|
@api.multi
|
|
def members_analyse(self):
|
|
""" members analyse """
|
|
self.ensure_one()
|
|
analysis_rec = self[0]
|
|
members = self.env['golem.member'].search([]).filtered(
|
|
lambda m: analysis_rec.season_id.id in m.season_ids.ids)
|
|
self.env['golem.member.analysis'].search([]).unlink()
|
|
if members:
|
|
for member in members:
|
|
self.env['golem.member.analysis'].create({
|
|
'member_id': member.id,
|
|
'season_id': analysis_rec.season_id.id
|
|
})
|
|
|
|
analyse_pivot = analysis_rec.get_pivot_view()
|
|
return {
|
|
'name': _('Member Analysis'),
|
|
'type': 'ir.actions.act_window',
|
|
'res_model': 'golem.member.analysis',
|
|
'view_type': 'pivot',
|
|
'view_mode': 'pivot',
|
|
'view_id': analyse_pivot.id,
|
|
'target': 'current'
|
|
}
|