[Analyses pour la ville] Add analysis by tag

This commit is contained in:
Youssef Elouahby 2019-01-14 14:32:08 +01:00
parent 89eb287ee1
commit 06e0116283
2 changed files with 27 additions and 27 deletions

View File

@ -24,12 +24,6 @@ from odoo.exceptions import UserError, ValidationError
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
def get_root_category(category_id):
""" Get Root Category """
if not category_id.parent_id:
return category_id
return get_root_category(category_id.parent_id)
class GolemMemberAnalysisPivot(models.TransientModel): class GolemMemberAnalysisPivot(models.TransientModel):
""" GOLEM Members Analysis Pivot Management """ """ GOLEM Members Analysis Pivot Management """
_name = 'golem.member.analysis' _name = 'golem.member.analysis'
@ -37,26 +31,36 @@ class GolemMemberAnalysisPivot(models.TransientModel):
season_id = fields.Many2one('golem.season', required=True) season_id = fields.Many2one('golem.season', required=True)
member_id = fields.Many2one('golem.member', 'Season') member_id = fields.Many2one('golem.member', 'Season')
area_id = fields.Many2one(related='member_id.area_id', store=True) area_id = fields.Many2one('golem.partner.area')
gender = fields.Selection(related='member_id.gender', store=True) gender = fields.Selection([('male', _('Male')),
category_id = fields.Many2many('res.partner.category') ('female', _('Female')),
age_start_season = fields.Integer(compute='_compute_age', string='Age at season start') ('not_disclosed', _('Not Disclosed'))])
age_end_season = fields.Integer(compute='_compute_age', string='Age at season end') category_id = fields.Many2one('res.partner.category')
age_range_start_season = fields.Many2one('golem.member.age.range', 'Age range at season start', age_start_season = fields.Integer(string='Age at season start')
compute='_compute_age_range', store=True) age_end_season = fields.Integer(string='Age at season end')
age_range_end_season = fields.Many2one('golem.member.age.range', 'Age range at season end', age_range_start_season = fields.Many2one('golem.member.age.range', 'Age range at season start')
compute='_compute_age_range', store=True) age_range_end_season = fields.Many2one('golem.member.age.range', 'Age range at season end')
@api.model
def get_root_category(self, category_ids):
""" Get Root Category """
categories = self.env['res.partner.category']
for category_id in category_ids:
if not category_id.parent_id:
return category_id
categories |= category_id.parent_id
return self.get_root_category(categories)
@api.constrains('member_id') @api.constrains('member_id')
@api.multi
def compute_fields(self): def compute_fields(self):
""" compute model fields """
for rec in self: for rec in self:
rec.category_id = get_root_category(rec.member_id.category_id) rec.area_id = rec.member_id.area_id
rec.gender = rec.member_id.gender
if rec.member_id.category_id:
@api.depends('member_id') rec.category_id = self.get_root_category(rec.member_id.category_id)
def _compute_category_id(self): rec._compute_age()
""" Compute category_id """ rec._compute_age_range()
for rec in self:
rec.category_id = get_root_category(rec.member_id.category_id)
@api.depends('member_id') @api.depends('member_id')
def _compute_age(self): def _compute_age(self):

View File

@ -30,10 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<group> <group>
<field name="season_id" options="{'no_create': True}"/> <field name="season_id" options="{'no_create': True}"/>
<field name="analyse_type"/> <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> </group>
<footer> <footer>
<button name="members_analye" string="Analyse Members" type="object" <button name="members_analye" string="Analyse Members" type="object"