Hide or Show Tree Line Columns


(wuf31) #1

Context:

I’ve added a new boolean field ‘w_tax’ on sale model.
I’ve also added a calculated ‘amount_w_tax’ on sale line model.

Now, I’d like to hide or show the column ‘amount_w_tax’ on sale lines tree, according to the field ‘w_tax’ on sale model.

Tried Solutions

I’ve tried doing the following stuff:

  1. Extend view_attributes method on sale line model:
    @classmethod
    def view_attributes(cls):
        return super(SaleLine, cls).view_attributes() + [
            ('/tree//field[@name="amount_w_tax"]', 'tree_invisible',
               Get(Eval('_parent_sale', {}), 'w_tax', False)),
            ]
This one doesn't seem to do anything at all
  1. add tree_invisible via xml
    <xpath expr="/tree/field[@name='amount']" position="after">
        <field name="amount_w_tax" tree_invisible="Eval('sale_w_tax')" pyson="1" />
        <field name="sale_w_tax" tree_invisible="1"/>
    </xpath>
This one generate an error on the client
ERROR:tryton.common.common:Traceback (most recent call last):
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/list.py", line 994, in __sig_switch
    if not self.screen.row_activate() and self.children_field:
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/screen/screen.py", line 471, in default_row_activate
    self.switch_view(view_type='form')
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/screen/screen.py", line 494, in switch_view
    self.load_view_to_load()
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/screen/screen.py", line 515, in load_view_to_load
    self.add_view_id(view_id, view_type)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/screen/screen.py", line 528, in add_view_id
    return self.add_view(view)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/screen/screen.py", line 553, in add_view
    view = View.parse(self, xml_dom, view.get('field_childs'))
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/__init__.py", line 46, in parse
    return ViewForm(screen, root)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/form.py", line 172, in __init__
    container = self.parse(xml)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/form.py", line 210, in parse
    widget = parser(node, container, node_attrs)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/form.py", line 303, in _parse_notebook
    self.parse(node, notebook)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/form.py", line 210, in parse
    widget = parser(node, container, node_attrs)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/form.py", line 335, in _parse_page
    container = self.parse(node)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/form.py", line 210, in parse
    widget = parser(node, container, node_attrs)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/form.py", line 363, in _parse_field
    widget = Widget(self, attributes)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/form_gtk/one2many.py", line 191, in __init__
    limit=None)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/screen/screen.py", line 140, in __init__
    self.switch_view()
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/screen/screen.py", line 494, in switch_view
    self.load_view_to_load()
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/screen/screen.py", line 515, in load_view_to_load
    self.add_view_id(view_id, view_type)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/screen/screen.py", line 528, in add_view_id
    return self.add_view(view)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/screen/screen.py", line 553, in add_view
    view = View.parse(self, xml_dom, view.get('field_childs'))
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/__init__.py", line 44, in parse
    return ViewTree(screen, root, children_field)
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/list.py", line 318, in __init__
    self.display()
  File "C:/Code/Python/tryton/tryton/gui/window/view_form/view/list.py", line 1096, in display
    if decoder.decode(widget.attrs.get('tree_invisible', '0')):
  File "C:/Development/msys2/mingw32/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:/Development/msys2/mingw32/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

NOTE:
This is done on tryton and trytond tip version


(Cédric Krier) #2

The evaluation of the tree_invisible is only done with the screen context so you can not use parent fields not direct fields.
This is because the view is constructed only once.


(wuf31) #3

I see. Thank you for the clarification :smile: