Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
5 ตอบกลับ
14978 มุมมอง

Hello,

I want to hide some columns in sale order form depends to product selected.
I think i can use the product's xml_id like this :
<field name="myfield" attrs="{'invisible': [('product_id', '!=', ref('product.my_product'))]}"/>

but i have an error :

NameError: name 'ref' is not defined

What is wrong with my attrs? There is another method to hide a field when a particular product is selected?

Thanks.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi Valentine,

By overriding fields_view_get you can do so.

Reference: fields_view_get example

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

In Odoo10 you can do the following:

<field name="myfield" attrs="{'invisible': [('product_id','!=', %(other_module.xml_id)d)]}"/>

Source: https://answers.launchpad.net/openobject-server/+question/181987

อวตาร
ละทิ้ง

Whoops. Didn't read the entire question.

You can still use this for xml-id's in attrs at least...

คำตอบที่ดีที่สุด

Sorry valentin, you can't do this.

`ref()` can only be used inside `eval` XML attributes (which is evaluated by Odoo's `safe_eval` module) as in the following example:

https://github.com/odoo/odoo/blob/8.0/addons/account/account_bank_view.xml#L42 

If your product is well known (you're already referring it by their External-ID in your example), you may try referring other field with a known value, like the product `code` ("Internal Reference") or  `ean13` ("EAN13 Barcode"):

<field name="myfield" attrs="{'invisible': [('product_id.code', '!=', 'SOME.PRODUCT.CODE')]}"/>

Regards.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

I think you can't hide columns in tree view depending on some choices in the runtime. This is straightforward in form views and could be achieved using attrs tag.



อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
มิ.ย. 19
16121
2
พ.ค. 18
9685
1
มี.ค. 15
4826
0
ม.ค. 25
1531
2
ส.ค. 24
2827