Odoo Help

0

How to dynamically set field attributes in python files?

By
AJ Schrafel Paper Corp
on 2/17/13, 3:30 PM 6,575 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 (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
11236
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 

LinkedIn

Blog

Stackoverflow

Sudhir Arya
ERP Harbor Consulting Services
skype: 
sudhir@erpharbor.com 
Sudhir Arya (ERP Harbor Consulting Services)
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
Artem
On 7/25/17, 1:15 PM

Check this https://www.odoo.com/forum/help-1/question/how-to-extend-fields-selection-options-without-overwriting-them-21529

0

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2130
| 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?

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

Question tools

0 follower(s)

Stats

Asked: 2/17/13, 3:30 PM
Seen: 6575 times
Last updated: 7/25/17, 1:15 PM