Beginner in odoo, I Inherited the product model and show the kanban view and list view in my custom module, How to override the create button so that on creating the product it should be a book, i made a boolean field is_a_book in product template to show whether the product is book or not . How?
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,
To override the create button and set the default value for the is_a_book 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">Books</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_a_book': True}</field>
</record>
Regards
Hi, for that you need to inherit the create method in the appropriate model (product.template) to add your business logic and call the super.
@api.model def create(self, vals): # Do some business logic, modify vals... ... # Then call super to execute the parent method return super().create(vals)
Odoo documentation here : https://www.odoo.com/documentation/16.0/developer/tutorials/getting_started/13_inheritance.html?highlight=super
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ýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
1
thg 1 23
|
5339 | ||
|
1
thg 4 25
|
1744 | ||
Odoo App
Đã xử lý
|
|
1
thg 11 23
|
2350 | |
|
0
thg 5 24
|
2059 | ||
|
0
thg 9 23
|
2977 |
Thanks @Cybrosys,your code works. Can you possibly tell me how change the view of my custom model like here you can see all the products instead of i want to see only book in my custom model
Add domain like this
<record id="product_template_action" model="ir.actions.act_window">
<field name="name">Books</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="domain">[('default_is_a_book', '=', True)]</field
<field name="context">{'default_is_a_book': True}</field>
</record>