[IMP]GOLEM analysis : use m2o / o2m to avoid full erasal on new analysis

This commit is contained in:
Fabien BOURGEOIS 2019-01-21 12:10:22 +01:00
parent d895203d1a
commit 9705eb0f5a
4 changed files with 10 additions and 4 deletions

View File

@ -73,19 +73,20 @@ class GolemActivityRegistrationAnalysisWizard(models.TransientModel):
registrations = self.env['golem.activity.registration'].search( registrations = self.env['golem.activity.registration'].search(
[('season_id', '=', analysis_rec.season_id.id)] [('season_id', '=', analysis_rec.season_id.id)]
) )
self.env['golem.member.analysis'].search([]).unlink()
if registrations: if registrations:
for registration in registrations: for registration in registrations:
self.env['golem.member.analysis'].create({ self.env['golem.member.analysis'].create({
'season_id': analysis_rec.season_id.id, 'season_id': analysis_rec.season_id.id,
'member_id': registration.member_id.id, 'member_id': registration.member_id.id,
'activity_id': registration.activity_id.id 'activity_id': registration.activity_id.id,
'resgistration_analysis_id': analysis_rec.id
}) })
analyse_pivot = analysis_rec.get_pivot_view() analyse_pivot = analysis_rec.get_pivot_view()
return { return {
'name': _('Member Analysis'), 'name': _('Member Analysis'),
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'res_model': 'golem.member.analysis', 'res_model': 'golem.member.analysis',
'domain': [('resgistration_analysis_id', '=', analysis_rec.id)],
'view_type': 'pivot', 'view_type': 'pivot',
'view_mode': 'pivot', 'view_mode': 'pivot',
'view_id': analyse_pivot.id, 'view_id': analyse_pivot.id,

View File

@ -27,4 +27,7 @@ class GolemMemberAnalysis(models.TransientModel):
_inherit = 'golem.member.analysis' _inherit = 'golem.member.analysis'
_description = 'GOLEM Member Analysis Adaptation' _description = 'GOLEM Member Analysis Adaptation'
resgistration_analysis_id = fields.Many2one(
'golem.activity.registration.analysis.wizard', index=True
)
activity_id = fields.Many2one('golem.activity', 'Activity') activity_id = fields.Many2one('golem.activity', 'Activity')

View File

@ -29,6 +29,7 @@ class GolemMemberAnalysisPivot(models.TransientModel):
_name = 'golem.member.analysis' _name = 'golem.member.analysis'
_description = 'GOLEM Members Analysis Management' _description = 'GOLEM Members Analysis Management'
member_analysis_id = fields.Many2one('golem.member.analysis.wizard', index=True)
season_id = fields.Many2one('golem.season', 'Season', required=True, season_id = fields.Many2one('golem.season', 'Season', required=True,
ondelete='cascade') ondelete='cascade')
member_id = fields.Many2one('golem.member', 'Service user') member_id = fields.Many2one('golem.member', 'Service user')

View File

@ -86,12 +86,12 @@ class GolemMemberAnalysis(models.TransientModel):
analysis_rec = self[0] analysis_rec = self[0]
members = self.env['golem.member'].search([]).filtered( members = self.env['golem.member'].search([]).filtered(
lambda m: analysis_rec.season_id.id in m.season_ids.ids) lambda m: analysis_rec.season_id.id in m.season_ids.ids)
self.env['golem.member.analysis'].search([]).unlink()
if members: if members:
for member in members: for member in members:
self.env['golem.member.analysis'].create({ self.env['golem.member.analysis'].create({
'member_id': member.id, 'member_id': member.id,
'season_id': analysis_rec.season_id.id 'season_id': analysis_rec.season_id.id,
'member_analysis_id': analysis_rec.id
}) })
analyse_pivot = analysis_rec.get_pivot_view() analyse_pivot = analysis_rec.get_pivot_view()
@ -99,6 +99,7 @@ class GolemMemberAnalysis(models.TransientModel):
'name': _('Member Analysis'), 'name': _('Member Analysis'),
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'res_model': 'golem.member.analysis', 'res_model': 'golem.member.analysis',
'domain': [('member_analysis_id', '=', analysis_rec.id)],
'view_type': 'pivot', 'view_type': 'pivot',
'view_mode': 'pivot', 'view_mode': 'pivot',
'view_id': analyse_pivot.id, 'view_id': analyse_pivot.id,