Skip to Content
Menu
This question has been flagged
1 Atsakyti
975 Rodiniai

Hello,

I've inherited the Product model in my custom module, and I'm displaying the views in my custom model. In my product template, I've added a boolean field called is_product_medicine to indicate whether a product is a medicine or not. Now, I want to override the create button behavior so that when I create a new product, it should be marked as a medicine by default.

How can I achieve this?


Portretas
Atmesti
Best Answer

Hi,
To override the create button and set the default value for the is_product_medicine field to True when creating a product, you can use the default_ context key in the action definition.

Here is the example code:

<record id="product_template_action" model="ir.actions.act_window">
    <field name="name">Medicines</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.template</field>
<field name="view_mode">kanban,tree,form</field>
<field name="context">{'default_is_product_medicine': True}</field>
</record>


Hope it helps

Portretas
Atmesti