Skip to Content
Menu
This question has been flagged
945 Views

i need create a dynamic snippet  but "no data showing"

after update Dynamic Snippet is showing , and after Drag and drop the Dynamic Snippet to the building block section "no data showing" only show word product list but no shoing product and price


file :   controllers/controllers.py


from odoo import http

from odoo.http import request

import json


class ProductList(http.Controller):

    @http.route('/product/list', type='json', auth='public', methods=['POST'])

    def product_list(self):

        products = request.env['product.product'].search([], limit=10)

        product_data_list = []

        for product in products:

            product_data = {

                'product': product.name,

                'price': product.list_price

            }

            product_data_list.append(product_data)

        data_list = {

            'data': product_data_list

        }

        res = http.Response(template='home_market.product_list',

                            qcontext=data_list)

        return res.render()


file :   views/dynamic_snippet_template.xml

   

       

           

Product List

           

               

                   

                       

                           

                               

                                    t-esc="product['product']"/>

                           

                           

                                   

  •                                     t-esc="product['price']"/>

                               

                       

                   

               

           

       

   


       

   

             name="Snippet">

       

              position="after">

           

       

   


file :  dynamic_snippet.js


/** @odoo-module **/


import publicWidget from "@web/legacy/js/public/public_widget";

import { jsonrpc } from "@web/core/network/rpc_service";


publicWidget.registry.DynamicSnippet = publicWidget.Widget.extend({

   selector: '.dynamic_snippet',

   start: function () {

       var self = this;

       var data = jsonrpc('/product/list', {}).then((data) => {

           self.$target.empty().append(data)

       });

   }

});


export default publicWidget.registry.DynamicSnippet;



file :   __manifest__.py

{

    'name': 'Home Market',

    'version': '1.0',

    'depends': ['base', 'base_setup', 'product', 'website', 'website_sale',

                'sale', 'theme_common', 'theme_loftspace', 'theme_real_estate'],

    'data': [

        'views/templates.xml',

        'views/views.xml',

        'security/ir.model.access.csv',

        'views/dynamic_snippet_template.xml',

    ],

    'assets': {

        'web.assets_frontend': [

            '/home_market/static/src/js/dynamic_snippet.js',

        ],

    },

    'installable': True,

    'application': True,

    'license': 'LGPL-3',

    'auto_install': False

}




Avatar
Discard
Related Posts Replies Views Activity
1
Jul 23
1220
0
Apr 24
700
0
Nov 24
854
1
May 24
1985
0
Apr 22
2061