4
votes

I'm trying to add o image widget in odoo screeen,

I have used the field as below ,

  image = fields.Binary("Image", attachment=True,
                          help="This field holds the image used as avatar for \
        this contact, limited to 1024x1024px",)

XML :

<field name="image" widget='image' class="oe_avatar"/>

The uploaded image has white space around image, how to upload image as it is , without adding white space around image ?

1
Are you inheriting a model from an odoo module like res.partner from base? Or is it fully new model with this Binary field above? - CZoellner
inheriting event.event module - US-1234
How big (length, width) are the tested images? - CZoellner
it will vary for all image - US-1234

1 Answers

1
votes

Here's a thinned down snippet of my code where I stored an image to be used in a QWeb report.

from openerp import api, fields, models, tools
class ResPartner(models.Model):
    _inherit = "res.partner"  

    partner_report_image = fields.Binary(string='Report image', compute='_get_image')

    @api.multi
    @api.depends('image')
    def _get_image(self):
        for rec in self:
            rec.partner_report_image = tools.image_resize_image_medium(
                rec.image, size=(500, 500))

You should check out openerp/tools/image.py it has some pretty neat image processing functions. Hope this helps!