Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
1401 Vizualizări

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.

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor Cel mai bun răspuns

Thank You so much!

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
ian. 25
505
1
nov. 24
797
0
nov. 24
612
1
iun. 25
484
2
mai 25
927