forked from Yaltik/golem
[Analyses pour la ville] Add analysis by tag
This commit is contained in:
parent
89eb287ee1
commit
06e0116283
@ -24,12 +24,6 @@ from odoo.exceptions import UserError, ValidationError
|
||||
from dateutil.relativedelta import relativedelta
|
||||
_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):
|
||||
""" GOLEM Members Analysis Pivot Management """
|
||||
_name = 'golem.member.analysis'
|
||||
@ -37,26 +31,36 @@ class GolemMemberAnalysisPivot(models.TransientModel):
|
||||
|
||||
season_id = fields.Many2one('golem.season', required=True)
|
||||
member_id = fields.Many2one('golem.member', 'Season')
|
||||
area_id = fields.Many2one(related='member_id.area_id', store=True)
|
||||
gender = fields.Selection(related='member_id.gender', store=True)
|
||||
category_id = fields.Many2many('res.partner.category')
|
||||
age_start_season = fields.Integer(compute='_compute_age', string='Age at season start')
|
||||
age_end_season = fields.Integer(compute='_compute_age', string='Age 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',
|
||||
compute='_compute_age_range', store=True)
|
||||
area_id = fields.Many2one('golem.partner.area')
|
||||
gender = fields.Selection([('male', _('Male')),
|
||||
('female', _('Female')),
|
||||
('not_disclosed', _('Not Disclosed'))])
|
||||
category_id = fields.Many2one('res.partner.category')
|
||||
age_start_season = fields.Integer(string='Age at season start')
|
||||
age_end_season = fields.Integer(string='Age at season end')
|
||||
age_range_start_season = fields.Many2one('golem.member.age.range', 'Age range at season start')
|
||||
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.multi
|
||||
def compute_fields(self):
|
||||
""" compute model fields """
|
||||
for rec in self:
|
||||
rec.category_id = get_root_category(rec.member_id.category_id)
|
||||
|
||||
|
||||
@api.depends('member_id')
|
||||
def _compute_category_id(self):
|
||||
""" Compute category_id """
|
||||
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:
|
||||
rec.category_id = self.get_root_category(rec.member_id.category_id)
|
||||
rec._compute_age()
|
||||
rec._compute_age_range()
|
||||
|
||||
@api.depends('member_id')
|
||||
def _compute_age(self):
|
||||
|
@ -30,10 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
<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"
|
||||
|
Loading…
Reference in New Issue
Block a user