Odoo Help

0

How to restrict a print report from specific views

By
Kitti Upariphutthiphong
on 7/29/13, 2:55 AM 1,439 views

When I create a new report form, i.e., Customer Invoice. I create it by identify it to a model "account.invoice". Then this "Customer Invoice" show in both Customer Invoice and Supplier Invoice windows. I know, we can restrict access report using group security, but given I am using the same person to work on both sales and purchase, this won't help. (as he/she need to see both forms, but different view)

The question is, are there ways to restrict Customer Invoice (to not show) from the Supplier Invoice window.

Or if it require coding, where is the place to look at (report assign to print menu).

Thank you,

0

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.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 7/29/13, 2:55 AM
Seen: 1439 times
Last updated: 3/16/15, 8:10 AM