Odoo Help


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.


Display a calculated field in the frontend odoo

on 7/26/15, 11:02 AM 549 views


I would count the number of products in the product_template table corresponding to a category of product_public_categ table.

I can get it with a calculated field but then if I want to display the contents of this field is calculated with the Qweb frontend, he referred me an error like "2" while Evaluating

Can you explain why the Qweb does not happen to the show? Sorry for my English 

class product_category(osv.Model):


def _nb_product_fnc(self, cr, uid, ids, name, arg, context=None):


         res,id_ ={}, None

        for categ in self.browse(cr, uid, ids, context=context):

            category = categ.id

            id_ = categ.id

        cr.execute("select count(id) from product_template where categ=%s" %(category))

        rep = cr.fetchone()[0] or 0 

        if id_:

            res[id_] =rep

        return res


'nb_product': fields.function(_nb_product_fnc, type="integer", string="Total product for this categories"),


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

1 follower(s)


Asked: 7/26/15, 11:02 AM
Seen: 549 times
Last updated: 7/26/15, 11:03 AM