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.

3

How to make invisible Field

By
heru
on 12/18/14, 6:40 PM 1,374 views

Hi, ...

I want to question ...

How  make field become invisible but type field is Selection  ....

I Use code like :

<field name="code_ahm" attrs="{'invisible': [('customer','!=',True)]}"/>

thanks

Ivan, i want to ask about this case :

I try to make function field .

    def _get_groups(self, cr, uid, ids, field_name, args, context=None):
        x = self.pool.get("res.users").browse(cr, uid, uid)['groups_id']
        #is self.group_id in x ?
        return self.group_id in x
    
    def _cek_groups(self, cr, uid, obj, name, args, context=None):
        res = []
        x = self.pool.get("res.users").browse(cr, uid, uid)['groups_id']
        ids = obj.search(cr,uid,[]) # ids of visits
        for v in self.browse(cr, uid, ids): # foreach visit
            if all(v.group_id == y[0] for y in x) :
                res.append(v.id)          
        return [('id','in',res)]

columns :

        'abc':fields.function(_get_groups, string="ABC", type="boolean", fnct_search=_cek_groups)

 

my xml code shown below :

        <record model="ir.actions.act_window" id="approval_portal_action">
            <field name="name">Portal Approval Matrix Biaya</field>
            <field name="res_model">wtc.approval.line</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree</field>
            <field name="domain">[('sts','=','1'),('abc','=',True)]</field>
        </record>


but it didn't return anything ..

On Fri, Dec 19, 2014 at 7:00 AM, Ivan <niecw@mail.odoo.com> wrote:

A new answer for How to make invisible Field has been posted. Click here to access the post.

--
Ivan
Sent by Odoo Inc. using Odoo about Forum Post How to make invisible Field

heru
on 12/29/14, 3:40 AM
0
Juan Carlos
On 12/18/14, 6:51 PM

You can use  invisible="1" in xml field.

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

0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 12/18/14, 7:00 PM

If customer field is a selection, you usually do the reverse: [('customer', '=', False)]

0
heru
On 12/18/14, 6:57 PM

@Juan Carlos

so my code become :

<field name="code_ahm" attrs="{'invisible': [('customer','!=',1)]}"/>   ?

Right ?

@Ivan 

Ivan, type Customer field is boolean ...

You mentioned that "... but type field is Selection ...." Anyway, if you need to domain by a selection field you can use treat it as normal character field with the value being the code of the selection chosen, e.g. [('selection_field', '=', 'value1')], [('selection_field', 'in', ('value1', 'value2'))], etc.

Ivan
on 12/18/14, 7:24 PM
oh I'm sorry ...

I use example your code, in file .xml or .py ?

I make class 'pilih_branch' in file .py :

class pilih_branch(osv.osv):
    _inherit = 'res.partner'
    _columns = {
                'pilih' : fields.selection([('c','Customer'),('b','Branch')],'Opsi Pengisian Data'),

and I make code in file .xml :

<record model="ir.ui.view" id="res_partner_formBranch_view">
    <field name="name">master customer</field>            
    <field name="model">res.partner</field>            
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <field name="function" position="before">
        <field name="pilih" placeholder="--Silahkan Pilih Salah Satu--"/>
        </field>
        </field>
</record>

<record model="ir.ui.view" id="res_partner_form_view"> <field name="name">master cabang</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <field name="website" position="after"> <field name="code_md" attrs="{'invisible': [('b','!=','True')]}"/> <field name="code_dealer" /> </field> </field> </record>
                
                }

<record model="ir.ui.view" id="res_partner_form5_view">
    <field name="name">master customer</field>            
    <field name="model">res.partner</field>            
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <field name="phone" position="before">
        <field name="tgl_lahir" attrs="{'invisible': [('c','!=','True')]}"/>
        </field>
        </field>
</record>

can you help me,  what is wrong my code ?


On Fri, Dec 19, 2014 at 7:24 AM, Ivan <niecw@mail.odoo.com> wrote:

You mentioned that "... but type field is Selection ...." Anyway, if you need to domain by a selection field you can use treat it as normal character field with the value being the code of the selection chosen, e.g. [('selection_field', '=', 'value1')], [('selection_field', 'in', ('value1', 'value2'))], etc.

--
Ivan
Sent by Odoo Inc. using Odoo about Forum Post False
heru
on 12/18/14, 7:46 PM

As the value is only available after the record is displayed this can only be done from view XML. I see that you have pilih field as the selection field, right? 'b' and 'c' are the values. First, if you want to use the field in domain, you need to include the field first, which I see have been included in res_partner_formBranch_view. Then you use it like: attrs="{'invisible': [('pilih','!=','c')]}" if you want to hide, say, the tgl_lahir field if the pilih field is not 'c'.

Ivan
on 12/18/14, 7:59 PM
oh yeah, its works ...
Ivan, can you give me sample code , for clear the field ...

I try make code for clear the field , like :
class branch(osv.osv):
    _inherit = 'res.partner'
    _columns = {
                         'pilih' : fields.selection([('c','Customer'),('b','Branch')],'Opsi Pengisian Data'),
                         'code_md': fields.char('Code MD'),
                         'am': fields.char('AM'),
                         }

    def onchange_value(self, cr, uid, ids, pilih):
        val={
             'value':{                
                      'am':' '   
                     }        
             }
        if pilih=='c':
            val={
                 'value':{
                          'code_md':' '
                          }
             }
        elif pilih=='b':
            val={
                 'value':{
                          'am':' '
                          }
             }
             
        return val

branch()

can you tell me what is the mistake with code ?

<img src="cid:gtalk.328@goomoji.gmail" goomoji="gtalk.328" style="margin: 0px 0.2ex; vertical-align: middle;">



On Fri, Dec 19, 2014 at 7:59 AM, Ivan <niecw@mail.odoo.com> wrote:

As the value is only available after the record is displayed this can only be done from view XML. I see that you have pilih field as the selection field, right? 'b' and 'c' are the values. First, if you want to use the field in domain, you need to include the field first, which I see have been included in res_partner_formBranch_view. Then you use it like: attrs="{'invisible': [('pilih','!=','c')]}" if you want to hide, say, the tgl_lahir field if the pilih field is not 'c'.

--
Ivan
Sent by Odoo Inc. using Odoo about Forum Post False
heru
on 12/18/14, 11:30 PM

@Heru, please post a different question, don't mixed the subject. The image is not displayed, so I can't help you. Also, please consider learning grep (http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_02.html). You can find a lot of examples from the official addons module. That's, AFAIK, is the best route for learning the basics.

Ivan
on 12/18/14, 11:51 PM
sorry Ivan, I can reply your new message , 
oh ok Insya Allah i study your modul ...

Ivan , do you have moduls about odoo ? 

On Fri, Dec 19, 2014 at 11:51 AM, Ivan <niecw@mail.odoo.com> wrote:

@Heru, please post a different question, don't mixed the subject. The image is not displayed, so I can't help you. Also, please consider learning grep (http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_02.html). You can find a lot of examples from the official addons module. That's, AFAIK, is the best route for learning the basics.

--
Ivan
Sent by Odoo Inc. using Odoo about Forum Post False

heru
on 12/20/14, 9:59 PM

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: 12/18/14, 6:40 PM
Seen: 1374 times
Last updated: 3/16/15, 8:10 AM