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',
}