Ok, I am attempting to place a picture thumbnail of each product, as taken from the first attachment associated with a product in the list that appears as a result of product_view.xml. So in short when you click "products" from products in the list of products each one has an image thumbnail that it gets from attachments.
Here is what i have tried
In product_view.xml at about line 19 under product.product.tree, i add
Code:
field name="x_preview" widget="image" readonly="1" nolabel="1" colspan="4" img_height="400" img_width="800" string="Thumbnail"/>
ok now in product.py under '_columns' for product.product i add
Code:
'x_preview': fields.function(_get_preview, method=True, type='binary', string='Image Preview'),
which i understand is now a binary field that calls _get_preview to find its value. Now for all this to work i have to go to. "Administration" -> "Customization" -> "Database Structure" -> "Objects" and then add a x_preview field to the product.product object (if i do not i get an error when i click on products saying i havn't properly set up the view or something)
So this is all dandy - now my understanding is that _get_preview in product.product should be called.
Code:
def _get_preview(self, cr, uid, ids, name, arg, context={}):
FILE2 = open('/home/openuser/monkey2.txt', 'a')
attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model', '=', 'product.product'), ('res_id', '=', product.id)])
data = self.pool.get('ir.attachment').read(cr, uid, attach_ids)
FILE2.write(str(attach_ids))
FILE2.write("\n")
FILE2.write(str(cr))
FILE2.write("\n")
FILE2.write(str(uid))
FILE2.write("\n")
FILE2.write(str(data))
FILE2.write("\n")
FILE.close()
return data
However it is never called. My first and most important question is why is it never called and the second question would be, is this function correct for the purpose of returning the appropriate attachment (or do i need to update the database cursor first with a SQL call??). Any help would be great i can't figure out why the function is not executing when the page is loaded (ignore the file writes they are just there for debugging)
thanks