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

How to dynamically set field attributes in python files?

By
AJ Schrafel Paper Corp
on 2/17/13, 3:30 PM 4,403 views

In purchase order lines I want to have 2 fields either readonly or not depending on the product selected.

I understand how to determine which product is selected in the onchange function, but i don't know how to make those fields readonly.

I imagine it is something like:

res = {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'product_uom' : uom_id or False}, 'readonly': {'diameter': 1}

res = {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'product_uom' : uom_id or False}, 'attrs': {'diameter':[('readonly', True)],}}

But neither of these lines of code make the field diameter on the purchase order line read only.

What am I missing?

Anything new on how to update field attributes in python rather than XML?

AJ Schrafel Paper Corp
on 3/15/13, 1:24 AM
4

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 2/18/13, 12:59 AM

You should write attrs in .xml.

Try this:

<field name="field_name" attrs="{'readonly':[('field', 'operator', value)]}"

Thank you for the suggestion, I was hoping to keep it all in the .py

Is there a way to change the attributes in the .py or can they only be set in the .xml?

AJ Schrafel Paper Corp
on 2/18/13, 10:11 AM

Hello everyone, how about using node.set? is it possible!

voathnak lim
on 5/31/13, 6:15 AM

Suppose I have many2one field "demo_field" and I have two groups "demogroup1","demogroup2" then for demo1 group I want demo_field as default functionality of many2one field and for demogroup2 demo_field is readonly then what can I do?

Vaibhav
on 7/12/13, 5:26 AM

Can set the attribute as following?

<field name="field_name" attrs="{'readonly':[('m2o_field.id', 'operator', value)]}"/>

Sebin Siby
on 9/1/16, 7:21 AM
0

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2060
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 2/18/13, 10:10 AM

Thank you for the suggestion, I was hoping to keep it all in the .py

Is there a way to change the attributes in the .py or can they only be set in the .xml?

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

0 follower(s)

Stats

Asked: 2/17/13, 3:30 PM
Seen: 4403 times
Last updated: 3/16/15, 8:10 AM