How can I come up with different forms for different products in my Odoo setup. For Example In my inventory I have custom products e.g., product A, which should have fields X and Y, but I also have product B which doesn't have fields X and Y but has Z
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
Hi,
Please refer to the code:
<record id="view_product_form_custom" model="ir.ui.view">
<field name="name">product.template.form.custom</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<!-- Field X visible only for Category A -->
<field name="x_field" position="attributes">
<attribute name="invisible">[('categ_id', '!=', ref('your_module.category_a'))]</attribute>
</field>
<!-- Field Y visible only for Category A -->
<field name="y_field" position="attributes">
<attribute name="invisible">[('categ_id', '!=', ref('your_module.category_a'))]</attribute>
</field>
<!-- Field Z visible only for Category B -->
<field name="z_field" position="attributes">
<attribute name="invisible">[('categ_id', '!=', ref('your_module.category_b'))]</attribute>
</field>
</field>
</record>
-invisible takes a domain-style condition.
-ref('your_module.category_a') refers to the external ID of the product category.
-This method works dynamically: when you change the category on the product form, fields appear/disappear accordingly.
-Works for both product templates and variants.
Hope it helps.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng ký