diff --git a/openerp/addons/base/ir/ir_ui_menu.py b/openerp/addons/base/ir/ir_ui_menu.py index f9db2707371..1db06966ea9 100644 --- a/openerp/addons/base/ir/ir_ui_menu.py +++ b/openerp/addons/base/ir/ir_ui_menu.py @@ -6,7 +6,7 @@ import operator import re import threading -import openerp.modules +import openerp from openerp.osv import fields, osv from openerp import api, tools from openerp.http import request @@ -175,15 +175,6 @@ class ir_ui_menu(osv.osv): icon_file.close() return icon_image - def _get_image_icon(self, cr, uid, ids, names, args, context=None): - res = {} - for menu in self.browse(cr, uid, ids, context=context): - res[menu.id] = r = {} - for fn in names: - fn_src = fn[:-5] # remove _data - r[fn] = self.read_image(menu[fn_src]) - return res - def _get_needaction_enabled(self, cr, uid, ids, field_names, args, context=None): """ needaction_enabled: tell whether the menu has a related action that uses the needaction mechanism. """ @@ -333,7 +324,6 @@ class ir_ui_menu(osv.osv): "If this field is empty, Odoo will compute visibility based on the related object's read access."), 'complete_name': fields.function(_get_full_name, string='Full Path', type='char'), 'web_icon': fields.char('Web Icon File'), - 'web_icon_data': fields.function(_get_image_icon, string='Web Icon Image', type='binary', readonly=True, store=True, multi='icon'), 'needaction_enabled': fields.function(_get_needaction_enabled, type='boolean', store=True, @@ -349,6 +339,14 @@ class ir_ui_menu(osv.osv): ]), } + web_icon_data = openerp.fields.Binary('Web Icon Image', + compute="_compute_web_icon", store=True, attachment=True) + + @api.depends('web_icon') + def _compute_web_icon(self): + for menu in self: + menu.web_icon_data = self.read_image(menu.web_icon) + _constraints = [ (osv.osv._check_recursion, 'Error ! You can not create recursive Menu.', ['parent_id']) ] diff --git a/openerp/addons/base/res/res_company.py b/openerp/addons/base/res/res_company.py index 0845b743017..c5bd670140e 100644 --- a/openerp/addons/base/res/res_company.py +++ b/openerp/addons/base/res/res_company.py @@ -68,6 +68,8 @@ class res_company(osv.osv): 'font': fields.many2one('res.font', string="Font", domain=[('mode', 'in', ('Normal', 'Regular', 'all', 'Book'))], help="Set the font into the report header, it will be used as default font in the RML reports of the user company"), 'logo': fields.related('partner_id', 'image', string="Logo", type="binary"), + # logo_web: do not store in attachments, since the image is retrieved in SQL for + # performance reasons (see addons/web/controllers/main.py, Binary.company_logo) 'logo_web': fields.function(_get_logo_web, string="Logo Web", type="binary", store={ 'res.company': (lambda s, c, u, i, x: i, ['partner_id'], 10), 'res.partner': (_get_companies_from_partner, ['image'], 10), diff --git a/openerp/addons/base/res/res_country.py b/openerp/addons/base/res/res_country.py index dd30a3e4566..e59d00ed50a 100644 --- a/openerp/addons/base/res/res_country.py +++ b/openerp/addons/base/res/res_country.py @@ -42,7 +42,7 @@ addresses belonging to this country.\n\nYou can use the python-style string pate \n%(country_name)s: the name of the country \n%(country_code)s: the code of the country"""), 'currency_id': fields.many2one('res.currency', 'Currency'), - 'image': fields.binary("Image"), + 'image': fields.binary("Image", attachment=True), 'phone_code': fields.integer('Country Calling Code'), 'country_group_ids': fields.many2many('res.country.group', 'res_country_res_country_group_rel', 'res_country_id', 'res_country_group_id', string='Country Groups'), 'state_ids': fields.one2many('res.country.state', 'country_id', string='States'), diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index 152bfa71106..769607723e8 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -165,14 +165,6 @@ class res_partner(osv.Model, format_address): (p.id, datetime.datetime.now(pytz.timezone(p.tz or 'GMT')).strftime('%z')) for p in self) - @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)}) - def _commercial_partner_compute(self, cr, uid, ids, name, args, context=None): """ Returns the partner that is considered the commercial entity of this partner. The commercial entity holds the master data @@ -266,25 +258,6 @@ class res_partner(osv.Model, format_address): 'by hand instead of a true function field. When migrating to ' 'the new API the code should be simplified.'), 'use_parent_address': fields.boolean('Use Company Address', help="Select this if you want to set company's address information for this contact"), - # image: all image fields are base64 encoded and PIL-supported - 'image': fields.binary("Image", - help="This field holds the image used as avatar for this contact, limited to 1024x1024px"), - 'image_medium': fields.function(_get_image, fnct_inv=_set_image, - string="Medium-sized image", type="binary", multi="_get_image", - store={ - 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Medium-sized image of this contact. It is automatically "\ - "resized as a 128x128px image, with aspect ratio preserved. "\ - "Use this field in form views or some kanban views."), - 'image_small': fields.function(_get_image, fnct_inv=_set_image, - string="Small-sized image", type="binary", multi="_get_image", - store={ - 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Small-sized image of this contact. It is automatically "\ - "resized as a 64x64px image, with aspect ratio preserved. "\ - "Use this field anywhere a small image is required."), 'company_id': fields.many2one('res.company', 'Company', select=1), 'color': fields.integer('Color Index'), 'user_ids': fields.one2many('res.users', 'partner_id', 'Users'), @@ -294,6 +267,34 @@ class res_partner(osv.Model, format_address): 'commercial_partner_id': fields.function(_commercial_partner_id, type='many2one', relation='res.partner', string='Commercial Entity', store=_commercial_partner_store_triggers) } + # image: all image fields are base64 encoded and PIL-supported + image = openerp.fields.Binary("Image", attachment=True, + help="This field holds the image used as avatar for this contact, limited to 1024x1024px") + image_medium = openerp.fields.Binary("Medium-sized image", + compute='_compute_images', inverse='_inverse_image_medium', store=True, attachment=True, + help="Medium-sized image of this contact. It is automatically "\ + "resized as a 128x128px image, with aspect ratio preserved. "\ + "Use this field in form views or some kanban views.") + image_small = openerp.fields.Binary("Small-sized image", + compute='_compute_images', inverse='_inverse_image_small', store=True, attachment=True, + help="Small-sized image of this contact. It is automatically "\ + "resized as a 64x64px image, with aspect ratio preserved. "\ + "Use this field anywhere a small image is required.") + + @api.depends('image') + def _compute_images(self): + for rec in self: + rec.image_medium = tools.image_resize_image_medium(rec.image) + rec.image_small = tools.image_resize_image_small(rec.image) + + def _inverse_image_medium(self): + for rec in self: + rec.image = tools.image_resize_image_big(rec.image_medium) + + def _inverse_image_small(self): + for rec in self: + rec.image = tools.image_resize_image_big(rec.image_small) + @api.model def _default_category(self): category_id = self.env.context.get('category_id', False)