Hi,
I've just started experimenting with Odoo development, and I'm finding it really hard to extend any of the existing website modules. I'd like to develop a module to display product attachments on odoo shop, but I just don't get how. I've replaced the existing product method under the website_sale class with the following code, just to add the attachments to the values dictionary, in order to later display them:
from openerp import SUPERUSER_ID
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website_sale.controllers.main import website_sale
class website_attachments(website_sale):
@http.route(['/shop/product/<model("product.template"):product>'], type='http', auth="public", website=True)
def product(self, product, category='', search='', **kwargs):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
category_obj = pool['product.public.category']
template_obj = pool['product.template']
context.update(active_id=product.id)
if category:
category = category_obj.browse(cr, uid, int(category), context=context)
attrib_list = request.httprequest.args.getlist('attrib')
attrib_values = [map(int,v.split("-")) for v in attrib_list if v]
attrib_set = set([v[1] for v in attrib_values])
keep = QueryURL('/shop', category=category and category.id, search=search, attrib=attrib_list)
category_ids = category_obj.search(cr, uid, [], context=context)
category_list = category_obj.name_get(cr, uid, category_ids, context=context)
category_list = sorted(category_list, key=lambda category: category[1])
pricelist = self.get_pricelist()
from_currency = pool.get('product.price.type')._get_field_currency(cr, uid, 'list_price', context)
to_currency = pricelist.currency_id
compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context)
if not context.get('pricelist'):
context['pricelist'] = int(self.get_pricelist())
product = template_obj.browse(cr, uid, int(product), context=context)
attachment_obj = pool['ir.attachment']
domain=['|',('res_model', '=', 'product.template'), ('res_id', '=', product.id)]
attachment_ids = attachment_obj.search(cr,uid,domain)
attachments = attachment_obj.browse(cr, uid, attachment_ids)
values = {
'search': search,
'category': category,
'pricelist': pricelist,
'attrib_values': attrib_values,
'compute_currency': compute_currency,
'attrib_set': attrib_set,
'keep': keep,
'category_list': category_list,
'main_object': product,
'product': product,
'get_attribute_value_ids': self.get_attribute_value_ids,
'attachments' = attachments
}
return request.website.render("website_sale.product", values)
When I try to loop over attachments in the corresponding template (via the online editor), I get the following error:
foreach enumerator 'attachments' is not defined while rendering template 'website_sale.product'
I would appreciate anyone helping on this, I've gone through the technical documentation on the Odoo community and honestly doesn't help much (although it's a good start).
Thanks in advance.
Manuel - this would be a very useful module to have to augment the ecommerce store - it would allow all sorts of technical documents to be made available for immediate download. Slides can do a reasonable job for uploading and rendering pdf files on gDrive but there may be lots of others sorts of file types (spreadsheets, calibration files, cad files, that need to be offered in support of technical products, and this module would provide a simple way to do this.