Odoo Help

Welcome!

This community 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.

0

Hide field in a tree view

By
José
on 3/12/15, 5:15 PM 2,811 views

Hello, I have Odoo 8.

I have added some fields to sale.order.line model and I added them to the sale.order form view, in which I can create new sale orders.

I want to hide the tree fields if the customer name is 'XYZ'. How can I specify this in the xml view? Because the 'name' of the customer is a attribute of res.partner model, and the 'partner_id' attribute is a field of sale.order. Then, the fields I want to hide are from sale.order.line model.

Thanks!

fields in a line or complete line ?

Cyril Gaspard (GEM)
on 3/12/15, 5:42 PM

Fields in a line

José
on 3/12/15, 5:50 PM

I want to hide complete column of the tree

José
on 3/12/15, 5:51 PM
1
Tintu Mon
On 4/11/16, 9:36 AM

In Tree view doesn't hide complete column when we use attrs="{'invisible':[('partner_name', '!=', 'XYZ')]}", I found it only hides the data/content in that column. So I tried to using invisible="context.get('partner_name') != 'XYZ'" instead of above one. It hides the complete column in Tree view. I hope it will help you.

1

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 3/12/15, 7:04 PM

try to add this code in a new module to install :

python code with new api v8 :

from openerp import models, fileds, api

 

class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'

    partner_name = fields.Char(_get_partner_order_name, string="Partner order name")

    @api.one

    @api.depends('order_id', 'order_id.partner_id')

    def _get_partner_order_name(self):

        self.ensure_one()

        self.partner_name = self.order_id.partner_id.name or ''

 

xml : hide column price_unit

?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="view_order_hide_columns_form" model="ir.ui.view">
            <field name="name">sale.order.hide.columns.form</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='order_line']/tree/field[@name='product_id'] position="after">
                    <field name="partner_name" invisible="1"/>
                <xpath expr="//field[@name='order_line']/tree/field[@name='price_unit'] position="attributes">
                    <attribute name="attrs">{'invisible': [('partner_name', '=', 'XYZ')]}</attribute>
                </xpath>

        </record>
    </data>
</openerp>

 

Bye

It works fine, except by the hiding of the field. My attribute is: attrs="{'invisible':[('partner_name', '!=', 'XYZ')]}" but if the partner_name is XYZ, the field is still invisibile. Why?

José
on 3/13/15, 8:16 AM

If I put operator '=' works correctly. If the partner_name is XYZ, then hide the field. But if I put '!=' not works, if the partner_name isn't XYZ the field is still invisible.

José
on 3/13/15, 8:24 AM

I solved the problem. Is there any way to hide the entire column of the tree? With the invisibiel attr the field is not editable, but the column is still there.

José
on 3/13/15, 9:30 AM

in sale.order, add a function field stored to get partner name partner_name. in view duplicate field order_line with form and tree; and in this second tree, remove colums you don't want. Add in two fiels order_line respectively attrs="{'invisible': [('partner_name', '=', 'value1')]}" attrs="{'invisible': [('partner_name', 'not in', ['value1')]]}" depending the tree you want to display. Bye

Cyril Gaspard (GEM)
on 3/14/15, 12:05 PM

In Tree view does it hide complete column when we use attrs="{'invisible':[('partner_name', '!=', 'XYZ')]}", I found it only hides the data/content in that column. So I tried to using invisible="context.get('partner_name') != 'XYZ'" instead of above one. It hides the complete column in Tree view. I hope it will help you.

Tintu Mon
on 4/11/16, 9:36 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/12/15, 5:15 PM
Seen: 2811 times
Last updated: 4/11/16, 9:36 AM