Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
6789 Vistas

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,

Avatar
Descartar
Autor Mejor respuesta

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.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
dic 21
2462
1
mar 15
4582
0
mar 15
3256
3
ene 25
2536
0
oct 24
1326