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.


FIXED - What is wrong with this code?

Manuel Pérez
on 1/18/15, 6:46 AM 1,083 views

UPDATE: Issue was with __openerp__.py, the following line was missing:

import controllers

(stupid mistake)


I'd like to display all the images attached to a product (as attachments) on the product page (website shop).

I've extended the website_sale class in the main.py controller of the website_sale addon:

class website_sale_attachment(website_sale):

    @http.route(['/shop/product/<model("product.template"):product>'], type='http', auth="public", website=True)
    def product(self, product, category='', search='', **kwargs):

        response = super(website_sale_attachment, self).product(product, category='', search='', **kwargs)

        attachment_obj = request.env['ir.attachment']
        images = attachment_obj.sudo().search([('res_model', '=', 'product.template'), ('res_id', '=', product.id)])

        response.qcontext.update({'images': images,})
        return response


I've inserted the following in the website_sale.product template to check whether the new variable "images" is present in the context:

<p><t t-esc="len(images)"/></p>

But I get the following error:

"object of type 'NoneType' has no len()" while evaluating 'len(images)'

It is as if the new key value is not visible from the template.

I've pretty much followed the example in the website_sale_digital addon (master version):


I've restarted the server and rebooted it as well but nothing seems to help. Do you have any idea why this is not working? Thanks.


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: 1/18/15, 6:46 AM
Seen: 1083 times
Last updated: 9/25/15, 5:48 AM