Hello, I have found that we the main method is fields_view_get() in BaseModel (orm.py), where at the end, it writeout as following,
result['toolbar'] = {
'print': resprint,
'action': resaction,
'relate': resrelate
}
return result
The reports listing will be in 'print' dict. What I need is to 1) Add restricted Views in Report window and 2) During fieds_view_get() call of each page (i.e., Customer Invoice with model account.invoice) remove Report from the stack if not matched the criteria from (1).
At first I wanted to inherit directly from the BaseModel, but it seem to be beyond my knowledge of python at the moment. Instead I inherit from only account.invoice and account.voucher, as the problem seem to lie on these 2 model anyway.
So, here is what I did,
1) Add restricted view in ir.actions.report.xml
class report_xml(osv.osv):
_inherit = 'ir.actions.report.xml'
_columns = {
'views_id': fields.many2many('ir.ui.view', 'res_views_report_rel', 'uid', 'view_id', 'Views', domain="[('model','=',model),('inherit_id','=',False),('type','in',('tree','form'))]"),
} report_xml()
2) Remove unmatched report if views criteria from (1) are specified.
# Remove report from the list, if the view security is assigned.
def check_print_list(result):
view_id = result.get('view_id', False)
if result.get('toolbar', False):
reports = result['toolbar']['print'][:] # Pass by value
i = 0
for report in reports:
if report['views_id']:
if view_id not in report['views_id']:
result['toolbar']['print'].pop(i)
i = i-1
i = i+1
return result
class account_invoice(osv.osv):
_inherit = 'account.invoice'
def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
result = super(account_invoice, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
result = check_print_list(result)
return result
account_invoice()
class account_voucher(osv.osv):
_inherit = 'account.voucher'
def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
result = super(account_voucher, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
result = check_print_list(result)
return result
account_voucher()
It seem to work for me so far. But if anyone know how to modify from the BaseModel, please share with me.