This question has been flagged
2 Replies
773 Views

this is when i created the new record:

def action_launchplan(self):
        for i in self.plan_id.plan_activity_type_ids:
            self.env['hr.plan.activity'].create({
                'employee_id': self.employee_id.id,
                'activity_type_id': i.id,
                'date':date.today(),
                'plan_id':self.plan_id.id,
                'line_ids': [(0,0, {
                    'name': i.name,
                    'description': i.description,
                })for i in i.line_ids]
            })


this is when i wanted to opened a window after a new record has been created:

def open_plans(self):
        self.ensure_one()
        return {
            'name': 'Plans',
            'type': 'ir.actions.act_window',
            'view_mode': 'tree,form',
            'target': 'current',
            'res_model': 'hr.plan.activity',
            'context': {'create': False, 'delete': False, 'edit': False,},
            'domain': [('id','in', self.plan_line_ids.ids)],
        }

This is the actual Function:

def action_launch(self):
        self.action_launchplan()
        self.employee_id.open_plans()
Avatar
Discard
Author

how do i get the current record id ?

return {
'name': 'Plans',
'type': 'ir.actions.act_window',
'view_mode': 'tree,form',
'target': 'current',
'res_id':current_record.id
'res_model': 'hr.plan.activity',
'context': {'create': False, 'delete': False, 'edit': False,},
'domain': [('id','in', self.plan_line_ids.ids)],
}


Best Answer

Hi 

After creating the new record,you can pass the value as res_id in the return of open_plans() function 

return {
'name': 'Plans',
'type': 'ir.actions.act_window',
'view_mode': 'tree,form',
'target': 'current',
'res_id':current_record.id
'res_model': 'hr.plan.activity',
'context': {'create': False, 'delete': False, 'edit': False,},
'domain': [('id','in', self.plan_line_ids.ids)],
}

Hope this Helps


Regards


Avatar
Discard
Best Answer

Hi,

You may change your action_launch method as follows to open the newly created record:

def action_launch(self):
plan_activities = self.env['hr.plan.activity']
for i in self.plan_id.plan_activity_type_ids:
plan_activity = plan_activities.create({
'employee_id': self.employee_id.id,
'activity_type_id': i.id,
'date': date.today(),
'plan_id': self.plan_id.id,
'line_ids': [(0, 0, {
'name': i.name,
'description': i.description,
}) for i in i.line_ids]
})
plan_activity.open_plans()

Regards

Avatar
Discard