It is currently Sun Feb 12, 2012 10:54 am

All times are UTC + 2 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Placing an Attachment Thumbnail in product_view.xml
PostPosted: Thu Feb 18, 2010 8:04 am 
Offline

Joined: Wed Feb 10, 2010 10:49 pm
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2010 3:34 am 
Offline

Joined: Sat Jun 27, 2009 4:08 am
Posts: 82
Location: Buenos Aires - Argentina
could you solved this???

_________________
...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2010 7:46 pm 
Offline

Joined: Sat Jun 27, 2009 4:08 am
Posts: 82
Location: Buenos Aires - Argentina
lflback, you could make it work???? Im looking for similar functionality...

Thks!!!

_________________
...


Top
 Profile  
 
 Post subject: Re: Placing an Attachment Thumbnail in product_view.xml
PostPosted: Sun Jun 05, 2011 2:36 pm 
Offline

Joined: Tue Jan 18, 2011 5:16 pm
Posts: 235
Hi,

Anybody make it work?
please share.
Thanks
Mihai

_________________
OpenERP debugging with Eclipse on headless server


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP