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:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
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.
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อ