Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to Show a Product List with JavaScript in a Snippet?

By
Max
on 2/12/15, 4:58 AM 1,958 views

GREETINGS ODOO COMMUNITY !

I'm developing a custom module with a snippet to show a product list.

So, I need to access the product's database and to show a result of a query, my test code in views/snippets.xml is :

<template id="show_products" inherit_id="website.snippets" name="Show Products">
   <xpath expr="//div[@id='snippet_structure']" position="inside">
        <div name="Show Products" class="o_block_image_floating">
        <div class="oe_snippet_thumbnail">
            <img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_text_image.png"/>
            <span class="oe_snippet_thumbnail_title">Show Products</span>
        </div>
        <div class="oe_snippet_body o_image_floating o_margin_l pull-right">
        <script>
                var Products = new openerp.Model('product.product');

//product.product should be the correct model's name, however it didn't work with res.config.settings neither

// var Products = new instance.web.Model("product.product"); fails as well
                Products.query(['id']).filter(['active','=',true]).first().then(function(id){

// in postgresql database there is table product_product and it has columns id and active

                    alert(id);

// alert() works fine alone, but it doesn't trigger here...

                });
        </script>
        </div>
    </div>
   </xpath>

</template>

Since I'm in "read-only mode", I don't need to specify any inheritances/dependencies in models.py/__init__.py/__openerp__.py am I ?

So far, my snippet's code doesn't work...

Could somebody please tell me WHY ?

I'm using Odoo v8 and I upgrade regularly my module in Local Modules.

THANK YOU VERY MUCH !

1
Max
On 2/18/15, 4:57 AM

Finally, it doesn't seem to be possible to make a query to db in Frontend, nevertheless we still could make a function call :
var website = openerp.website;
website.session.model('product.product')
        .call('name_search', ['',[]], { context: website.get_context()})
        .then(function(list){

        alert(list);

        }
});

I hope that this information will help someone someday :)

0
yuri
On 3/17/15, 5:40 AM

Did you finally get the snippet? I would like to know the answer!


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)

Stats

Asked: 2/12/15, 4:58 AM
Seen: 1958 times
Last updated: 3/17/15, 5:40 AM