I have developed custom modules, with their own data, and i wish to present them on the website module. I wish to create a block with it so it is easy to put it out. Sadly i found no material on how to do this.
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ờ
To present your custom module data on the Odoo website and create a block for easy integration, you can follow these steps. It involves using Odoo's Website Builder and extending it to display your custom module's data dynamically.
Here’s a step-by-step guide to achieve that:
1. Create a Custom Controller
You need to create a custom controller to fetch your custom module data and pass it to the website template.
Example:
Let's assume your custom module is called my_custom_module and you want to display a list of products or records from this module on your website.
- First, create a Python controller in your custom module. This will handle the request and pass data to the website.
from odoo import http from odoo.http import request class MyCustomModuleController(http.Controller): @http.route('/my_custom_module', auth='public', website=True) def index(self, **kw): # Fetch data from your custom module records = request.env['my.custom.model'].search([]) # Replace with your model name # Render a template with the fetched records return request.render('my_custom_module.template_id', { 'records': records, })
This will create a URL (/my_custom_module) where your custom module data will be displayed.
2. Create a Website Template
Next, you need to create a template in the views folder of your module. This template will display the data passed from the controller.
Example Template (views/website_template.xml):
<odoo> <template id="template_id" name="Custom Module Template"> <div class="custom-module-block"> <h2>My Custom Data</h2> <t t-foreach="records" t-as="record"> <div class="record"> <h3><t t-esc="record.name"/></h3> <!-- Replace with your model's field --> <p><t t-esc="record.description"/></p> <!-- Replace with your model's field --> </div> </t> </div> </template> </odoo>
In this template:
- We're using <t t-foreach="records" t-as="record"> to loop through the records passed from the controller.
- Replace record.name and record.description with the actual fields from your model.
3. Add the Block to the Website
Once the controller and template are set up, you can create a block for this data on your website.
- Go to Website → Pages → Add New Page or edit an existing page.
- In the page editor, you can add your new custom block using Custom HTML or Snippet options.
- In the editor, add the block with a dynamic URL (e.g., /my_custom_module) so it pulls the data from the controller template.
Hey, i think your answer is here: https://www.odoo.com/documentation/18.0/fr/developer/howtos/website_themes/building_blocks.html
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 | |
---|---|---|---|---|
|
3
thg 5 25
|
2812 | ||
|
0
thg 12 23
|
2481 | ||
|
1
thg 7 23
|
2562 | ||
|
0
thg 7 22
|
1984 | ||
Odoo? Why this new name?
Đã xử lý
|
|
3
thg 9 21
|
22174 |