This question has been flagged
3 Replies
31445 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

Avatar
Discard
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

Best Answer

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

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

Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

@Juan Carlos

so my code become :

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

Right ?

@Ivan 

Ivan, type Customer field is boolean ...

Avatar
Discard

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.

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

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'.

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, 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.

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