Skip to Content
Menu
This question has been flagged
1 Reply
5574 Views

Hi,

I've created a multiple pivot view for two objects that varies on how the column, row and measure were specified. The requirement is for the user to click a button and display the pivot view in the required format with filtered records based on the date range specified. I need the domain to be dynamic and so I'm launching the Pivot view from a python method. I've already created a record in the ir.actions.act_window object using XML so I could call its XML ID in my python method from form view via context.

However, it seems that the view_ids does not take effect. It works if I use view_id only but I need to pass both pivot and graph views. See my code below:


@api.multi

    def pivot_report(self):

        """

        This method loads the indicated action in the fpt_servie_report_view.xml file 

        using the xml_id passed via context in the form view of this fpt.report.dashboard.

        The purpose of this method is to change the existing domain to append filters

        for the start_date and end_date field.

        """

        for rec in self:

        # Get the xml_id passed in the form view of this object using context

                

            xml_id = rec.env.context.get('xml_id',False)

            #view_id = rec.env.context.get('view_id',False)

            date_range = rec.date_range()

    

            if xml_id:

                action_id = rec.env.ref(xml_id).id

                #view_id = rec.env.ref(view_id).id or False

                act = self.env['ir.actions.act_window'].browse(action_id)

                domain = act.domain

                

                if date_range:

                    # Replace the original domain by appending the start_date and end_date filter

                    start_date = date_range[0] + ""

                    end_date = date_range[1] + ""

                    date_dom = ",('create_date','>=','%s'),('create_date','<=','%s')]" % (start_date, end_date)

                    prev_dom = act.domain.replace("]","")

                    domain = prev_dom + date_dom

                            

                res = {

                    'name'      : act.name,

                    'view_type' : act.view_type,

                    #'view_mode' : 'pivot',

                    'res_model' : act.res_model,

                    #'view_id'   : view_id,

                    'view_ids'  : (6,0,act.view_ids.ids),

                    'target'    : act.target,

                    'domain'    : domain,

                    'type'      : 'ir.actions.act_window',                

                    }

Avatar
Discard
Best Answer

Here you have to define views in action params. Please refer the example below:


data_obj = self.pool.get('ir.model.data')
form_view_id = data_obj._get_id(cr, uid, 'project', 'edit_project')
form_view = data_obj.read(cr, uid, form_view_id, ['res_id'])
tree_view_id = data_obj._get_id(cr, uid, 'project', 'view_project')
tree_view = data_obj.read(cr, uid, tree_view_id, ['res_id'])
search_view_id = data_obj._get_id(cr, uid, 'project', 'view_project_project_filter')
search_view = data_obj.read(cr, uid, search_view_id, ['res_id'])
return {
'name': _('Projects'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'project.project',
'view_id': False,
'res_id': res_id,
'views': [(form_view['res_id'],'form'),(tree_view['res_id'],'tree')],
'type': 'ir.actions.act_window',
'search_view_id': search_view['res_id'],
}
You can fetch the view ids by using the below method also:
kanban_res = self.env['ir.model.data'].get_object_reference('mail', 'mail_channel_view_kanban')
kanban_id = kanban_res and kanban_res[1] or False
Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
858
0
Mar 24
164
4
Sep 24
45158
3
May 20
4280
0
Aug 18
29926