Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
1893 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore Risposta migliore

Thank You so much!

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
gen 25
710
1
nov 24
1003
0
nov 24
872
3
lug 25
1460
1
giu 25
1419