Odoo Help

0

How can I migrate this code to Odoo?? (_get_image function)

By
chesucr
on 3/9/15, 8:20 AM 1,616 views

How can I migrate this code to the versión 8?? How can I get the "ids" variable?   

def _get_image(self, cr, uid, ids, context=None):
        result = dict.fromkeys(ids, False)
        for obj in self.browse(cr, uid, ids, context=context):
            result[obj.id] = tools.image_get_resized_images(obj.image, avoid_resize_medium=True)
        return result
  
    def _set_image(self, cr, uid, id, name, value, context=None):
        return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context)    
 
    _columns = {
        'image': fields.binary("Image", help="This field holds the image used as image for the category, limited to 1024x1024px."),
        'image_medium': fields.function(_get_image, fnct_inv=_set_image,
            string="Medium-sized image", type="binary", multi="_get_image",
            store={
                'product.template': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
            },
            help="Medium-sized image of the category. It is automatically "\
                 "resized as a 128x128px image, with aspect ratio preserved. "\
                 "Use this field in form views or some kanban views."),

    }

 

thanks

1

Hi Chesucr,

You can migrate your code as like below. You just need to chage your functions like below and you code will be migrate into V8.

    @api.multi
    def _get_image(self, name, args):
        return dict((p.id, tools.image_get_resized_images(p.image)) for p in self)

    @api.one
    def _set_image(self, name, value, args):
        return self.write({'image': tools.image_resize_image_big(value)})

I hope you will get your result. 

Note : Please refer python file from odoo=>openerp=>addons=>base=>res=>res_partner.py in this file looking on the class res_partner.

mmm I think you copied the code from here https://www.odoo.com/es_ES/forum/help-1/question/avatar-image-in-new-api-69525 but that doesn't work. Thanks anyway. Moreover with @api.one and @api.multi you only need 'self' as argument. With the function _set_image I get this error: RuntimeError: maximum recursion depth exceeded. I will go on with my research

chesucr
on 3/10/15, 8:03 AM

As I have write down on the note. I have seen this in that file. I have not copied from https://www.odoo.com/es_ES/forum/help-1/question/avatar-image-in-new-api-69525.

Emipro Technologies Pvt. Ltd.
on 3/10/15, 8:40 AM

OK thanks, I owe you one ;) I tried the functions with this field and it worked: image = fields.Binary("Second product image", compute="_get_image", multi="_get_image", inverse="_set_image")

chesucr
on 3/13/15, 5:56 AM
0
wizardz
On 8/22/16, 7:49 AM

what is now the complete answer ( code) ?

0
Vasanth
On 3/9/15, 9:39 AM

hi,

please refer this link for your way to do migration:

https://www.odoo.com/forum/help-1/question/migrate-database-from-openerp-6-1-to-odoo-72702

I was talking about code migration instead database migration, thanks anyway

chesucr
on 3/9/15, 11:20 AM

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.

Register

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)

Stats

Asked: 3/9/15, 8:20 AM
Seen: 1616 times
Last updated: 8/22/16, 7:49 AM