This question has been flagged
1 Reply
12776 Views

Is there a way to get the current active view_id? I need to refresh the page according to the active form that user are viewing. Or is there a way for me to refresh 2 or more page? (parent and wizard view)

I have tried:

@api.multi
def refresh_ot(self, activity):

    ir_model_data = self.env['ir.model.data']
    form_res = self.env.ref('mrp_employee_relation.mrp_employee_activity_form_view')
    tree_res = self.env.ref('mrp_employee_relation.mrp_employee_activity_tree_view')

return { 'view_mode': 'form', 'view_type': 'form', 'res_model': 'mrp.employee.activity', 'res_id' : activity.id, 'view_id' : False, 'views' : [(form_res.id, 'form'), (tree_res.id, 'tree')], 'type' : 'ir.actions.act_window', }


@api.multi
 def refresh_plat(self, plating):
    ir_model_data = self.env['ir.model.data']
    form_res = self.env.ref('mrp_employee_relation.mrp_plating_report_form_view')
    tree_res = self.env.ref('mrp_employee_relation.mrp_plating_report_tree_view')

return { 'view_mode': 'form', 'view_type': 'form', 'res_model': 'mrp.plating.report', 'res_id' : plating.id, 'view_id' : False, 'views' : [(form_res.id, 'form'), (tree_res.id, 'tree')], 'type' : 'ir.actions.act_window', }


Then I call both function at Return, this method only work if I am in wizard view and it wont work if I am using the parent view while pressing a object button. 



Avatar
Discard
Best Answer

Hello Munesh Nandwani,


Try below code.


@api.multi

def refresh_plat(self, plating):

     model_obj = self.env['ir.model.data']

     data_id = model_obj._get_id('module_name', 'view_id_which_you_want_refresh')

     view_id = model_obj.browse(data_id).res_id

     return {

         'type': 'ir.actions.client',

         'tag': 'reload',               

         'name': _('View Name'),               

         'res_model': 'model_name',               

         'view_type': 'view type which is kanban, form',               

         'view_mode': 'view mode which is kanban, form',               

         'view_id': view_id,               

         'target': 'current',               

         'nodestroy': True,

     }


Hope it will works for you.

Thanks,


Avatar
Discard
Author

Hi Jignesh Metha,

Thank you for you reply. But it's not the solution that I am looking for. I wish I can upload a picture to have a clearer view of the situation.

What happen is, In From Employee Activity I have one2many of Plating. In that one2many tree I have a button name "start". If u click the one2many it will pop up a wizard that will have the same button (start).

If use the button inside the wizard and I call both refresh function. It work properly. But if I use the button inside the one2many (without having a pop out wizard) it will not refresh properly (it only refresh that one2many not other one2many that are created because of that start button).

So If i can find out currently the user is using the start button from wizard view or not wizard view I can call the function accordingly. I hope this clarifies my question. Thank you.