Skip to Content
Menu
This question has been flagged
2 Replies
1495 Views

Hi!! I wanted to know if there's possible to display some values in Odoo Website module getting them from a module that does the calculations. I searched about this but couldn't see any examples.

Avatar
Discard
Best Answer

Hi,


Yes, linking your custom module with the Website module in Odoo 17 is possible.


Ensure that the website module is included as a dependency:


{

    'name': 'Custom Website Integration',

    'depends': ['base', 'website'],  # Add 'website' as a dependency

    # ... other manifest settings

}


Create a controller to define the route and pass the calculated data to the website template.

example:


from odoo import http

from odoo.http import request


class CustomWebsite(http.Controller):

    @http.route(['/custom/calculations'], type='http', auth='public', website=True)

    def display_calculations(self, **kwargs):

        # Fetch calculations from your custom model

        calculation_model = request.env['your.model.name']

        calculations = calculation_model.search([])  # Replace 'your.model.name' with your model's name

        values = {

            'calculations': calculations,

        }

        return request.render('your_module.template_id', values)


Create a website template to o show the data on the website. Add this template to your module's views folder:


<?xml version="1.0" encoding="utf-8"?>

<odoo>

    <template id="template_id" name="Calculations">

        <t t-call="website.layout">

            <div class="container">

                <h1>Calculations</h1>

                <div t-foreach="calculations" t-as="calc">

                    <p t-field="calc.value"/>  <!-- Adjust 'value' to match your model's field -->

                </div>

            </div>

        </t>

    </template>

</odoo>


If you want to add a menu item to  make your page accessible from the website:


<odoo>

    <record id="menu_calculations" model="website.menu">

        <field name="name">Calculations</field>

        <field name="url">/custom/calculations</field>

        <field name="parent_id" ref="website.main_menu"/>

        <field name="sequence" type="int">11</field>

    </record>

</odoo>


If you want to display your data on an existing website page (e.g., the product page), you can extend the template using inherit_id:


<odoo>

    <template id="product_page_extension" inherit_id="website_sale.product">

        <xpath expr="//div[@id='product_details']" position="after">

            <div class="custom-data">

                <h3>Custom Calculations</h3>

                <div t-foreach="calculations" t-as="calc">

                    <p t-field="calc.value"/>  <!-- Adjust 'value' to match your model's field -->

                </div>

            </div>

        </xpath>

    </template>

</odoo>


You can also create custom snippet templates and integrate them with the Website Builder. For more details refer to the following blogs:

https://www.cybrosys.com/blog/how-to-create-a-snippet-in-odoo-17

https://www.cybrosys.com/blog/how-to-create-a-generic-controller-in-odoo-17-website


Hope it helps

Avatar
Discard
Author Best Answer

Thank You so much!

Avatar
Discard
Related Posts Replies Views Activity
0
Jan 25
530
1
Nov 24
849
0
Nov 24
630
1
Jun 25
633
2
May 25
1006