跳至内容
菜单
此问题已终结
3 回复
3240 查看

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]
            })


形象
丢弃
最佳答案

Hi, you can follow following link for this:

https://youtu.be/oMnHpHH54QU

Hope it helps,

Thanks

形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

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]
})

形象
丢弃
相关帖文 回复 查看 活动
2
9月 23
4402
2
12月 21
12311
1
11月 19
5450
2
12月 16
14503
2
6月 21
8736