0
votes

I have created a button on OpenERP_7. Its basic use is to print the selected record in the tree view. Its like the More button used in OpenERP-7. The problem here I m facing is that I dont want this button to be shown on the form view.Right now its being displayed on tree view as well as form view but I want it to be view only on tree view.Since its not a simple button thats why Im having problems. Do I have to make changes in the web module or can this be done with any user access permissions? I really need guidance on this. Plz guide me to achieve this.

this is the xml part:

<?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve">
<t t-name="AddPrintScreenMain">
    <div class="oe_form_dropdown_section">
        <button class="oe_dropdown_toggle oe_dropdown_arrow">Printscreen</button>
        <ul class="oe_dropdown_menu">
            <li class="oe_sidebar_printscreen_pdf"><span>PDF</span></li>
            <li class="oe_sidebar_printscreen_xls"><span>Excel</span></li>
        </ul>
    </div>
</t>
</templates>

I did changes like this:

 def fields_view_get(self, cr, uid, view_id=None, view_type='form',context=None, toolbar=False, submenu=False):
        result = super(deg_form, self).fields_view_get(cr, uid, view_id,
                                    view_type, context, toolbar, submenu)
        if result.get("name") == u'deg.form':

           doc = etree.XML(result['arch'])
           modifiers = '{"invisible": true}'
           nodes = doc.xpath("//button[@name='AddPrintScreenMain']")
           for node in nodes:
               node.set('modifiers', modifiers)
           result['arch'] = etree.tostring(doc)
        return result
1
Can you please post your code - nitesh
I need to show the button on the tree view only. thanks - Arsalan Sherwani

1 Answers

0
votes

What you need to do is overwrite fields_view_get method and do as follows:

from lxml import etree 

def fields_view_get(self, cr, uid, view_id=None, view_type='form',
                    context=None, toolbar=False, submenu=False):
    result = super(work_order, self).fields_view_get(cr, uid, view_id,
                                    view_type, context, toolbar, submenu)
    if result.get("name") == u'your.form.name.here':

        doc = etree.XML(result['arch'])
        modifiers = '{"invisible": true}'
        nodes = doc.xpath("//button[@name='btn_name_here']")
        for node in nodes:
            node.set('modifiers', modifiers)
        result['arch'] = etree.tostring(doc)
    return result