Odoo Help


FIXED - What is wrong with this code?

Manuel Pérez
on 1/18/15, 6:46 AM 1,642 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.


About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 1/18/15, 6:46 AM
Seen: 1642 times
Last updated: 9/25/15, 5:48 AM