Odoo Help

2

fields_view_get() dinamically modify view (one2many tree view)

By
Juan Vicente Pascual
on 6/20/16, 5:54 AM 987 views

I'm trying to modify layout of the tree view for one2many field in sale.order.

This is my code,

@api.model

def fields_view_get(self, view_id=None, view_type=False, context=None,

toolbar=False, submenu=False):

res = super(saleOrder,

self).fields_view_get(view_id=view_id, view_type=view_type,

toolbar=toolbar, submenu=submenu)

if view_type == 'form':

doc = etree.XML(res['arch'])

for node in doc.xpath("//field[@name='order_line']/tree//field[@name='product_id']"):

node.set('invisible', 'True')

res['arch'] = etree.tostring(doc)

return res


After debug, only   //field[@name='order_line'], appears.

can't find  'product_id'.

0
Kabeer
On 9/16/17, 5:35 AM

Try below code

       if view_type =='form':
            doc = etree.XML(result['fields']['order_line']['views']['tree']['arch'])
            node = doc.xpath("//field[@name='product_id']")[0]
            node.set('invisible','1')
            result['fields']['order_line']['views']['tree']['arch'] = etree.tostring(doc)
        return result

Hope it will help you.

0
Juan Vicente Pascual
On 6/20/16, 9:48 AM

I can't do it in the xml file, because i have to show/hide the column, depending of attributes like company_id.

Since now i can't find 'order_line <tree> columns in the doc.xpath, so i cannot replace or hide the fields.


Kind regards.

Hi Juan! Do you have any luck with this problem?

Muhammad Irfan
on 4/21/17, 8:28 AM
0

try this.

from openerp.osv.orm import setup_modifiers


if doc.xpath("//field[@name='order_line']/tree//field[@name='product_id']"):

    node = doc.xpath("//field[@name='order_line']/tree//field[@name='product_id']")[0]

    node.set('invisible', '1')

    setup_modifiers(node, res['fields']['product_id'])

res['arch'] = etree.tostring(doc)

return res

OR

<xpath expr="//field[@name='order_line']//tree//field[@name='product_id']" position="attributes">

           attribute name="invisible">1</attribute>

</xpath>





I hope it's useful for you. 

Thanks in advance for your help,

the problem is that

doc.xpath("//field[@name='order_line']/tree//field[@name='product_id']")

returns an empty element, [ ]

only finds

doc.xpath("//field[@name='order_line']")

cannot find the elements of the one2many field 'order_line'.

Kind regards.

Juan Vicente Pascual
on 6/20/16, 8:08 AM

batter so you can use xpath from form view like

<xpath expr="//field[@name='order_line']/tree//field[@name='product_id']" position="attributes">

<attribute name="invisible">1</attribute>

</xpath>

Prashant Panchal (ppa)
on 6/20/16, 8:11 AM

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

1 follower(s)

Stats

Asked: 6/20/16, 5:54 AM
Seen: 987 times
Last updated: 9/16/17, 5:35 AM