Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
8 Trả lời
19588 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

You should write attrs in .xml.

Try this:

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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?

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

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?

Can set the attribute as following?

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

Tác giả Câu trả lời hay nhất

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
45
thg 4 23
84380
1
thg 5 25
39449
2
thg 7 20
36915
2
thg 10 17
17014
0
thg 3 15
10956