콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
2330 화면

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.

아바타
취소
베스트 답변

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

아바타
취소
작성자 베스트 답변

Thank You so much!

아바타
취소
관련 게시물 답글 화면 활동
0
1월 25
919
1
11월 24
1193
0
11월 24
1116
3
7월 25
2142
1
6월 25
2609