Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
152 Zobrazení

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

Avatar
Zrušit
Nejlepší odpověď

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.

Avatar
Zrušit