Skip to Content
Menu
This question has been flagged
3 Replies
2807 Views

Can we call a function to return to form after the button wizard is called?


My code:

class HrPlanWizard(models.TransientModel):
    _inherit = 'hr.plan.wizard'

    def action_launch(self): //Button in wizard
        self.action_launchplan()
        self.open_plans()

    def open_plans(self): //this is a button for return form
        self.ensure_one()
        return {
        'name': 'Plans',
        'type': 'ir.actions.act_window',
        'view_mode': 'tree',
        'target': 'current',
        # 'res_id': self.id,
        # 'next': {"type":"ir.actions.act_window_close"},
        'res_model': 'hr.plan.activity',
        'next': {'type': 'ir.actions.act_window_close'},
        'context': {'create': False, 'delete': False, 'edit': False,},
        'domain': [('id','in', self.employee_id.plan_line_ids.ids)],
    }
        
    def action_launchplan(self): // this is the record i want to return tree or form
        for i in self.plan_id.plan_activity_type_ids:
            self.env['hr.plan.activity'].create({
                'employee_id': self.employee_id.id,
                'plan_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]
            })


Avatar
Discard
Best Answer

Hi, you can follow following link for this:

https://youtu.be/oMnHpHH54QU

Hope it helps,

Thanks

Avatar
Discard
Best Answer

HI,

It is possible to use a function to go back to the form view after pressing a wizard button, yes. In your situation, you can accomplish this by changing the action_launch() method.

Use this code:

class HrPlanWizard(models.TransientModel):
_inherit = 'hr.plan.wizard'

def action_launch(self):
self.action_launchplan()
return self.open_plans()

def open_plans(self):
self.ensure_one()
return {
'name': 'Plans',
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'hr.plan.activity',
'res_id': self.env['hr.plan.activity'].search([('employee_id', '=', self.employee_id.id)], limit=1).id,
'target': 'current',
}
 
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,
'plan_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],
})

Regards

Avatar
Discard
Best Answer

you can follow this way
to make it work, you need to modify your code as follows:



class HrPlanWizard(models.TransientModel):
_inherit = 'hr.plan.wizard'

def action_launch(self): # Button in wizard
self.action_launchplan()
return self.open_plans() # Call open_plans() and return the result

def open_plans(self):
self.ensure_one()
return {
'name': 'Plans',
'type': 'ir.actions.act_window',
'view_mode': 'form', # Use 'form' view mode to open the form view
'target': 'current',
'res_model': 'hr.plan.activity',
'res_id': self.plan_id.id, # Specify the ID of the record to open
'context': {'create': False, 'delete': False, 'edit': False},
}

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,
'plan_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]
})

Avatar
Discard
Related Posts Replies Views Activity
2
Sep 23
3932
2
Dec 21
11937
1
Nov 19
5182
2
Dec 16
14084
2
Jun 21
8384