[Analyses pour la ville] Add member analysis assistant

This commit is contained in:
Youssef Elouahby 2019-01-14 03:30:33 +01:00
parent af1bb8966c
commit c06eda9a63
2 changed files with 154 additions and 0 deletions

View File

@ -0,0 +1,95 @@
# -*- 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, _
from odoo.exceptions import UserError, ValidationError
_LOGGER = logging.getLogger(__name__)
class GolemMemberAnalysis(models.TransientModel):
""" GOLEM Members Analysis Management """
_name = 'golem.member.analysis.wizard'
_description = 'GOLEM Members Analysis Wizard Management'
season_id = fields.Many2one('golem.season', 'Season', required=True)
#member_analysis_ids = fields.Many2many('golem.member.analysis.pivot', string='Members list')
analyse_type = fields.Selection([('age_start_gender', 'By age at season start and gender'),
('age_end_gender', 'By age at season end and gender'),
('age_start_area', 'By age at season start and area'),
('age_end_area', 'By age at season end and area'),
('age_start_tag', 'By age at season start and tag'),
('age_end_tag', 'By age at season end and tag')],
required=True)
category_id = fields.Many2one('res.partner.category')
@api.multi
def get_pivot_view(self):
self.ensure_one()
rec = self[0]
if rec.analyse_type == 'age_start_gender':
return self.env.ref('golem_member.golem_member_analysis_pivot_age_start_gender', False)
elif rec.analyse_type == 'age_end_gender':
return self.env.ref('golem_member.golem_member_analysis_pivot_age_end_gender', False)
elif rec.analyse_type == 'age_start_area':
return self.env.ref('golem_member.golem_member_analysis_pivot_age_start_area', False)
elif rec.analyse_type == 'age_end_area':
return self.env.ref('golem_member.golem_member_analysis_pivot_age_end_area', False)
elif rec.analyse_type == 'age_start_tag':
return self.env.ref('golem_member.golem_member_analysis_pivot_age_start_tag', False)
elif rec.analyse_type == 'age_end_tag':
return self.env.ref('golem_member.golem_member_analysis_pivot_age_end_tag', False)
@api.multi
def members_analye(self):
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_type': analysis_rec.analyse_type
})
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',
#'views': [(analyse_pivot.id, 'form')],
'view_id': analyse_pivot.id,
'target': 'new',
}
#record = self[0]
#data = {}
#data = self.read(['season_id', 'member_analysis_ids', 'analyse_type'])[0]
#_LOGGER.warning('________________________________________________________________________')
#_LOGGER.warning('analysis function')
#return self.env['report'].get_action(self, 'golem_member.golem_member_analysis_report', data=data)
#return self.env['report'].get_action(self, 'golem_resource_report.golem_reservation_report', data=data)

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="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/>.
-->
<odoo>
<data>
<!-- Forms -->
<record model="ir.ui.view" id="golem_member_analysis_wizard_view_form">
<field name="name">GOLEM Member Analysis Wizard Form</field>
<field name="model">golem.member.analysis.wizard</field>
<field name="arch" type="xml">
<form string="Member Analysis">
<sheet>
<group>
<field name="season_id" options="{'no_create': True}"/>
<field name="analyse_type"/>
<field name="category_id"
attrs="{'invisible': [('analyse_type', 'not in', ('age_start_tag','age_end_tag'))],
'required': [('analyse_type', 'in', ('age_start_tag','age_end_tag'))]}"
options="{'no_create': True}"/>
</group>
<footer>
<button name="members_analye" string="Analyse Members" type="object"
class="oe_highlight" />
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</sheet>
</form>
</field>
</record>
<!-- Actions -->
<act_window id="golem_analysis_action" name="Analysis"
res_model="golem.member.analysis.wizard" view_mode="form"
target="new"/>
<menuitem id="golem_analysis_menu" name="Members analysis"
parent="golem_membership.menu_association" sequence="15"
action="golem_analysis_action"/>
</data>
</odoo>