Odoo Help

2

0
3 Answers
2
Avatar

Prakash India

--Prakash--

11631
| 6 7 9
Bikaner, India
--Prakash--

OpenERP Developer at SunARC Technology

Prakash India
4/7/14, 6:00 AM

The below code When you select India in the many2one field, two char field should be display. Python Code:-

_columns = {        
    'country_id': fields.many2one('res.country', 'Country'),
    'country_name': fields.related('country_id', 'name', type="char", relation="res.country", string="Name"),
        'field1_name': fields.char('Field1', size=64),  
        'field2_name': fields.char('Field2', size=64),  
    }

def onchange_country(self, cr, uid, ids, country_id, context=None):
value = {}
res_country = self.pool.get('res.country')        
if country_id:           
    value = {
      'country_name': res_country.browse(cr, uid, country_id).name
    }
return {'value': value}

XML code:-

<field name="country_id" on_change="onchange_country(country_id)"/> 
<field name="country_name" invisible="1"/> 
<field name="field1_name" attrs="{'invisible':[('country_name', '!=', 'India')]}"/>
<field name="field2_name" attrs="{'invisible':[('country_name', '!=', 'India')]}"/>
7 Comments
Remya India
4/7/14, 6:04 AM

Thank you very much,Prakash. I just ask you a doubt. If i directly give country_id=23 for india will it work.ie, attrs="{'invisible':[('country_id', '!=', 23)]}"

Prakash India
4/7/14, 6:14 AM

Yes it will works. But country_id hard coded. For Example in my DB Country ID for India is stored 105. so need to change code ID based on DB. The above code will works in any DB.

Remya India
4/7/14, 7:44 AM

But i give the above attr line, its not working.

Prakash India
4/7/14, 8:07 AM

Have u used the same code?.. on_change function and invisible country_name in the form view.

Remya India
4/7/14, 8:57 AM

sorry, not your code Prakash. I just simply created a field with <field name="field1_name" attrs="{'invisible':[('country_id', '!=', '2')]}"/> , but its not working. will it not work without python code?

Prakash India
4/7/14, 10:48 AM

Remove the symbol ' ' and apply <field name="field1_name" attrs="{'invisible':[('country_id', '!=', 2)]}"/> And to check ID using select id from res_company where name="India' and apply the ID in xml file.

Remya India
4/8/14, 5:55 AM

Hi Prakash, I'm asking another doubt: I want to display first login time in my attendance custom report. Did you know the code? One employee will login more than one time a day, but i want the first login time. http://help.openerp.com/question/48949/generating-a-custom-report-for-employees-login-time/ Can you please help me?

1
Serge Canada
4/7/14, 11:46 AM

You only need a conditition like that, that will hide field if country is not india

<field name="your_field_name_india" attrs="{'invisible':[('country_id', '!=', ref('base.in'))]}"/>
<field name="your_field_name" attrs="{'invisible':[('country_id', '=', ref('base.in'))]}"/>

*base.id is the XML_ID for the country INDIA

0
silvi New Zealand
4/7/14, 1:45 AM

create a hidden related field to many2one . based on that hidden field change the attrs::invisible on the fields that you want to display at runtime.

3 Comments
Remya India
4/7/14, 1:49 AM

I didn't get. I already have a many2one field that is not hidden. I already tried attrs:invisible, but it is not working. i think my code is wrong. can you please wrote the condition here.

silvi New Zealand
4/7/14, 2:23 AM

attrs="{'invisible':[(field , '=', 'india')]}"

Remya India
4/7/14, 2:41 AM

But its not hiding.

Ask a Question
Writer
5672
Remya
Keep Informed
0 follower(s)
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