diff --git a/addons/fleet/fleet.py b/addons/fleet/fleet.py index 877e7eb31f9..5108841e3e2 100644 --- a/addons/fleet/fleet.py +++ b/addons/fleet/fleet.py @@ -1,13 +1,15 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from openerp.osv import fields, osv import time import datetime +from dateutil.relativedelta import relativedelta + +import openerp from openerp import tools from openerp.exceptions import UserError +from openerp.osv import fields, osv from openerp.tools.translate import _ -from dateutil.relativedelta import relativedelta def str_to_datetime(strdate): return datetime.datetime.strptime(strdate, tools.DEFAULT_SERVER_DATE_FORMAT) @@ -134,39 +136,36 @@ class fleet_vehicle_model(osv.Model): class fleet_vehicle_model_brand(osv.Model): _name = 'fleet.vehicle.model.brand' _description = 'Brand model of the vehicle' - _order = 'name asc' - def _get_image(self, cr, uid, ids, name, args, 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) - return result + name = openerp.fields.Char('Make', required=True) - def _set_image(self, cr, uid, id, name, value, args, context=None): - return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context) + image = openerp.fields.Binary("Logo", attachment=True, + help="This field holds the image used as logo for the brand, 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 logo of the brand. 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 logo of the brand. It is automatically "\ + "resized as a 64x64px image, with aspect ratio preserved. "\ + "Use this field anywhere a small image is required.") - _columns = { - 'name': fields.char('Make', required=True), - 'image': fields.binary("Logo", - help="This field holds the image used as logo for the brand, limited to 1024x1024px."), - 'image_medium': fields.function(_get_image, fnct_inv=_set_image, - string="Medium-sized photo", type="binary", multi="_get_image", - store = { - 'fleet.vehicle.model.brand': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Medium-sized logo of the brand. 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="Smal-sized photo", type="binary", multi="_get_image", - store = { - 'fleet.vehicle.model.brand': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Small-sized photo of the brand. It is automatically "\ - "resized as a 64x64px image, with aspect ratio preserved. "\ - "Use this field anywhere a small image is required."), - } + @openerp.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) class fleet_vehicle(osv.Model): diff --git a/addons/gamification/models/badge.py b/addons/gamification/models/badge.py index ec364374216..79c383bf475 100644 --- a/addons/gamification/models/badge.py +++ b/addons/gamification/models/badge.py @@ -133,7 +133,8 @@ class gamification_badge(osv.Model): _columns = { 'name': fields.char('Badge', required=True, translate=True), 'description': fields.text('Description'), - 'image': fields.binary("Image", help="This field holds the image used for the badge, limited to 256x256"), + 'image': fields.binary("Image", attachment=True, + help="This field holds the image used for the badge, limited to 256x256"), 'rule_auth': fields.selection([ ('everyone', 'Everyone'), ('users', 'A selected list of users'), diff --git a/addons/hr/hr.py b/addons/hr/hr.py index fb60c5cc18e..8594f0c1e93 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -3,6 +3,7 @@ import logging +import openerp from openerp import api from openerp import SUPERUSER_ID from openerp import tools @@ -136,15 +137,6 @@ class hr_employee(osv.osv): _mail_post_access = 'read' - def _get_image(self, cr, uid, ids, name, args, 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) - return result - - def _set_image(self, cr, uid, id, name, value, args, context=None): - return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context) - _columns = { #we need a related field in order to be able to sort the employee by name 'name_related': fields.related('resource_id', 'name', type='char', string='Name', readonly=True, store=True), @@ -170,25 +162,6 @@ class hr_employee(osv.osv): 'resource_id': fields.many2one('resource.resource', 'Resource', ondelete='cascade', required=True, auto_join=True), 'coach_id': fields.many2one('hr.employee', 'Coach'), 'job_id': fields.many2one('hr.job', 'Job Title'), - # image: all image fields are base64 encoded and PIL-supported - 'image': fields.binary("Photo", - help="This field holds the image used as photo for the employee, limited to 1024x1024px."), - 'image_medium': fields.function(_get_image, fnct_inv=_set_image, - string="Medium-sized photo", type="binary", multi="_get_image", - store = { - 'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Medium-sized photo of the employee. 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 photo", type="binary", multi="_get_image", - store = { - 'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Small-sized photo of the employee. It is automatically "\ - "resized as a 64x64px image, with aspect ratio preserved. "\ - "Use this field anywhere a small image is required."), 'passport_id': fields.char('Passport No'), 'color': fields.integer('Color Index'), 'city': fields.related('address_id', 'city', type='char', string='City'), @@ -196,6 +169,34 @@ class hr_employee(osv.osv): 'last_login': fields.related('user_id', 'date', type='datetime', string='Latest Connection', readonly=1), } + # image: all image fields are base64 encoded and PIL-supported + image = openerp.fields.Binary("Photo", attachment=True, + help="This field holds the image used as photo for the employee, limited to 1024x1024px.") + image_medium = openerp.fields.Binary("Medium-sized photo", + compute='_compute_images', inverse='_inverse_image_medium', store=True, attachment=True, + help="Medium-sized photo of the employee. 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 photo", + compute='_compute_images', inverse='_inverse_image_small', store=True, attachment=True, + help="Small-sized photo of the employee. 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) + def _get_default_image(self, cr, uid, context=None): image_path = get_module_resource('hr', 'static/src/img', 'default_image.png') return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64')) diff --git a/addons/im_livechat/models/im_livechat_channel.py b/addons/im_livechat/models/im_livechat_channel.py index 3514e8d6d93..bde469c0825 100644 --- a/addons/im_livechat/models/im_livechat_channel.py +++ b/addons/im_livechat/models/im_livechat_channel.py @@ -43,16 +43,18 @@ class ImLivechatChannel(models.Model): rating_percentage_satisfaction = fields.Integer('% Happy', compute='_compute_percentage_satisfaction', store=False, default=-1) # images fields - image = fields.Binary('Image', default=_default_image, + image = fields.Binary('Image', default=_default_image, attachment=True, help="This field holds the image used as photo for the group, limited to 1024x1024px.") - image_small = fields.Binary('Thumbnail', compute='_compute_image', store=True, - help="Small-sized photo of the group. It is automatically "\ - "resized as a 64x64px image, with aspect ratio preserved. "\ - "Use this field anywhere a small image is required.") - image_medium = fields.Binary('Medium', compute='_compute_image', store=True, + image_medium = fields.Binary('Medium', + compute='_compute_image', store=True, attachment=True, help="Medium-sized photo of the group. 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.Binary('Thumbnail', + compute='_compute_image', store=True, attachment=True, + help="Small-sized photo of the group. It is automatically "\ + "resized as a 64x64px image, with aspect ratio preserved. "\ + "Use this field anywhere a small image is required.") # relationnal fields user_ids = fields.Many2many('res.users', 'im_livechat_channel_im_user', 'channel_id', 'user_id', string='Operators', default=_default_user_ids) @@ -67,12 +69,8 @@ class ImLivechatChannel(models.Model): @api.one @api.depends('image') def _compute_image(self): - if self.image: - self.image_small = tools.image_resize_image_small(self.image) - self.image_medium = tools.image_resize_image_medium(self.image) - else: - self.image_small = False - self.image_medium = False + self.image_medium = tools.image_resize_image_medium(self.image) + self.image_small = tools.image_resize_image_small(self.image) @api.multi def _compute_script_external(self): diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 91937470ed8..e9624eb6b2a 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -67,16 +67,18 @@ class Channel(models.Model): "Note that they will be able to manage their subscription manually " "if necessary.") # image: all image fields are base64 encoded and PIL-supported - image = fields.Binary("Photo", default=_get_default_image, - help="This field holds the image used as photo for the group, limited to 1024x1024px.") - image_medium = fields.Binary('Medium-sized photo', compute='_get_image', inverse='_set_image', store=True, - help="Medium-sized photo of the group. 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.Binary('Small-sized photo', compute='_get_image', inverse='_set_image', store=True, - help="Small-sized photo of the group. It is automatically " - "resized as a 64x64px image, with aspect ratio preserved. " - "Use this field anywhere a small image is required.") + image = fields.Binary("Photo", default=_get_default_image, attachment=True, + help="This field holds the image used as photo for the group, limited to 1024x1024px.") + image_medium = fields.Binary('Medium-sized photo', + compute='_get_image', inverse='_set_image_medium', store=True, attachment=True, + help="Medium-sized photo of the group. 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.Binary('Small-sized photo', + compute='_get_image', inverse='_set_image_small', store=True, attachment=True, + help="Small-sized photo of the group. It is automatically " + "resized as a 64x64px image, with aspect ratio preserved. " + "Use this field anywhere a small image is required.") alias_id = fields.Many2one( 'mail.alias', 'Alias', ondelete="restrict", required=True, help="The email address associated with this group. New emails received will automatically create new topics.") @@ -84,12 +86,14 @@ class Channel(models.Model): @api.one @api.depends('image') def _get_image(self): - res = tools.image_get_resized_images(self.image) - self.image_medium = res['image_medium'] - self.image_small = res['image_small'] + self.image_medium = tools.image_resize_image_medium(self.image) + self.image_small = tools.image_resize_image_small(self.image) - def _set_image(self): - self.image = tools.image_resize_image_big(self.image) + def _set_image_medium(self): + self.image = tools.image_resize_image_big(self.image_medium) + + def _set_image_small(self): + self.image = tools.image_resize_image_big(self.image_small) @api.model def create(self, vals): diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 1e174af6cd7..cb95bad942d 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -1,6 +1,7 @@ # -*- coding: utf-'8' "-*-" import logging +import openerp from openerp.osv import osv, fields from openerp.tools import float_round, float_repr, image_get_resized_images, image_resize_image_big from openerp.tools.translate import _ @@ -55,34 +56,12 @@ class PaymentAcquirer(osv.Model): def _get_providers(self, cr, uid, context=None): return [] - def _get_image(self, cr, uid, ids, name, args, context=None): - return dict((p.id, image_get_resized_images(p.image)) for p in self.browse(cr, uid, ids, context=context)) - - def _set_image(self, cr, uid, id, name, value, args, context=None): - return self.write({'image': image_resize_image_big(value)}) - # indirection to ease inheritance _provider_selection = lambda self, *args, **kwargs: self._get_providers(*args, **kwargs) _columns = { 'name': fields.char('Name', required=True, translate=True), 'provider': fields.selection(_provider_selection, string='Provider', required=True), - 'image': fields.binary("Image", help="This field holds the image used for this provider, limited to 1024x1024px"), - 'image_medium': fields.function(_get_image, fnct_inv=_set_image, string="Medium-sized image", type="binary", multi="_get_image", - store={ - 'payment.acquirer': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Medium-sized image of this provider. 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={ - 'payment.acquirer': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Small-sized image of this provider. 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', required=True), 'pre_msg': fields.html('Help Message', translate=True, help='Message displayed to explain and help the payment process.'), @@ -115,6 +94,33 @@ class PaymentAcquirer(osv.Model): 'sequence': fields.integer('Sequence', help="Determine the display order"), } + image = openerp.fields.Binary("Image", attachment=True, + help="This field holds the image used for this provider, 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 provider. 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 provider. It is automatically "\ + "resized as a 64x64px image, with aspect ratio preserved. "\ + "Use this field anywhere a small image is required.") + + @openerp.api.depends('image') + def _compute_images(self): + for rec in self: + rec.image_medium = openerp.tools.image_resize_image_medium(rec.image) + rec.image_small = openerp.tools.image_resize_image_small(rec.image) + + def _inverse_image_medium(self): + for rec in self: + rec.image = openerp.tools.image_resize_image_big(rec.image_medium) + + def _inverse_image_small(self): + for rec in self: + rec.image = openerp.tools.image_resize_image_big(rec.image_small) + _defaults = { 'company_id': lambda self, cr, uid, obj, ctx=None: self.pool['res.users'].browse(cr, uid, uid).company_id.id, 'environment': 'prod', diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index c587e259543..84635131d6f 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -9,6 +9,7 @@ import sets from functools import partial +import openerp from openerp import tools, models, SUPERUSER_ID from openerp.osv import fields, osv from openerp.tools import float_is_zero @@ -1482,15 +1483,6 @@ class pos_category(osv.osv): res = self.name_get(cr, uid, ids, context=context) return dict(res) - def _get_image(self, cr, uid, ids, name, args, 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) - return result - - def _set_image(self, cr, uid, id, name, value, args, context=None): - return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context) - _columns = { 'name': fields.char('Name', required=True, translate=True), 'complete_name': fields.function(_name_get_fnc, type="char", string='Name'), @@ -1498,30 +1490,40 @@ class pos_category(osv.osv): 'child_id': fields.one2many('pos.category', 'parent_id', string='Children Categories'), 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of product categories."), - # NOTE: there is no 'default image', because by default we don't show thumbnails for categories. However if we have a thumbnail - # for at least one category, then we display a default image on the other, so that the buttons have consistent styling. - # In this case, the default image is set by the js code. - # NOTE2: image: all image fields are base64 encoded and PIL-supported - 'image': fields.binary("Image", - help="This field holds the image used as image for the cateogry, limited to 1024x1024px."), - 'image_medium': fields.function(_get_image, fnct_inv=_set_image, - string="Medium-sized image", type="binary", multi="_get_image", - store={ - 'pos.category': (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."), - 'image_small': fields.function(_get_image, fnct_inv=_set_image, - string="Smal-sized image", type="binary", multi="_get_image", - store={ - 'pos.category': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Small-sized image of the category. It is automatically "\ - "resized as a 64x64px image, with aspect ratio preserved. "\ - "Use this field anywhere a small image is required."), } + # NOTE: there is no 'default image', because by default we don't show + # thumbnails for categories. However if we have a thumbnail for at least one + # category, then we display a default image on the other, so that the + # buttons have consistent styling. + # In this case, the default image is set by the js code. + image = openerp.fields.Binary("Image", attachment=True, + help="This field holds the image used as image for the cateogry, 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 the category. 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 the category. It is automatically "\ + "resized as a 64x64px image, with aspect ratio preserved. "\ + "Use this field anywhere a small image is required.") + + @openerp.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) + class product_template(osv.osv): _inherit = 'product.template' diff --git a/addons/pos_restaurant/restaurant.py b/addons/pos_restaurant/restaurant.py index 98822233901..11548073bb2 100644 --- a/addons/pos_restaurant/restaurant.py +++ b/addons/pos_restaurant/restaurant.py @@ -15,7 +15,7 @@ class restaurant_floor(osv.osv): _columns = { 'name': fields.char('Floor Name', required=True, help='An internal identification of the restaurant floor'), 'pos_config_id': fields.many2one('pos.config','Point of Sale'), - 'background_image': fields.binary('Background Image', help='A background image used to display a floor layout in the point of sale interface'), + 'background_image': fields.binary('Background Image', attachment=True, help='A background image used to display a floor layout in the point of sale interface'), 'background_color': fields.char('Background Color', help='The background color of the floor layout, (must be specified in a html-compatible format)'), 'table_ids': fields.one2many('restaurant.table','floor_id','Tables', help='The list of tables in this floor'), 'sequence': fields.integer('Sequence',help='Used to sort Floors'), diff --git a/addons/product/product.py b/addons/product/product.py index da0b32882bc..05e07af5344 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -4,6 +4,7 @@ import re import time +import openerp from openerp import api, tools, SUPERUSER_ID from openerp.osv import osv, fields, expression from openerp.tools.translate import _ @@ -368,15 +369,6 @@ class product_template(osv.osv): _description = "Product Template" _order = "name" - def _get_image(self, cr, uid, ids, name, args, 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, args, context=None): - return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context) - def _is_product_variant(self, cr, uid, ids, name, arg, context=None): return self._is_product_variant_impl(cr, uid, ids, name, arg, context=context) @@ -501,25 +493,6 @@ class product_template(osv.osv): 'uom_id': fields.many2one('product.uom', 'Unit of Measure', required=True, help="Default Unit of Measure used for all stock operation."), 'uom_po_id': fields.many2one('product.uom', 'Purchase Unit of Measure', required=True, help="Default Unit of Measure used for purchase orders. It must be in the same category than the default unit of measure."), 'company_id': fields.many2one('res.company', 'Company', select=1), - # image: all image fields are base64 encoded and PIL-supported - 'image': fields.binary("Image", - help="This field holds the image used as image for the product, 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 product. It is automatically "\ - "resized as a 128x128px image, with aspect ratio preserved, "\ - "only when the image exceeds one of those sizes. 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={ - 'product.template': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Small-sized image of the product. It is automatically "\ - "resized as a 64x64px image, with aspect ratio preserved. "\ - "Use this field anywhere a small image is required."), 'packaging_ids': fields.one2many( 'product.packaging', 'product_tmpl_id', 'Logistical Units', help="Gives the different ways to package the same product. This has no impact on " @@ -540,6 +513,34 @@ class product_template(osv.osv): 'item_ids': fields.one2many('product.pricelist.item', 'product_tmpl_id', 'Pricelist Items'), } + # 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 image for the product, 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 the product. It is automatically "\ + "resized as a 128x128px image, with aspect ratio preserved, "\ + "only when the image exceeds one of those sizes. 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 the product. 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, avoid_if_small=True) + 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) + def _price_get(self, cr, uid, products, ptype='list_price', context=None): if context is None: context = {} @@ -946,7 +947,7 @@ class product_product(osv.osv): 'attribute_value_ids': fields.many2many('product.attribute.value', id1='prod_id', id2='att_id', string='Attributes', ondelete='restrict'), 'is_product_variant': fields.function( _is_product_variant_impl, type='boolean', string='Is a product variant'), # image: all image fields are base64 encoded and PIL-supported - 'image_variant': fields.binary("Variant Image", + 'image_variant': fields.binary("Variant Image", attachment=True, help="This field holds the image used as image for the product variant, limited to 1024x1024px."), 'image': fields.function(_get_image_variant, fnct_inv=_set_image_variant, diff --git a/addons/report_webkit/header.py b/addons/report_webkit/header.py index 8224e49589b..a4e308fb99f 100644 --- a/addons/report_webkit/header.py +++ b/addons/report_webkit/header.py @@ -68,7 +68,7 @@ class HeaderImage(osv.osv): _name = "ir.header_img" _columns = { 'company_id' : fields.many2one('res.company', 'Company'), - 'img' : fields.binary('Image'), + 'img' : fields.binary('Image', attachment=True), 'name' : fields.char('Name', required =True, help="Name of Image"), 'type' : fields.char('Type', required =True, help="Image type(png,gif,jpeg)") } diff --git a/addons/website_event_track/models/event.py b/addons/website_event_track/models/event.py index bd3c19de45d..d560f36e092 100644 --- a/addons/website_event_track/models/event.py +++ b/addons/website_event_track/models/event.py @@ -53,7 +53,7 @@ class event_track(models.Model): ('0', 'Low'), ('1', 'Medium'), ('2', 'High'), ('3', 'Highest')], 'Priority', required=True, default='1') - image = fields.Binary('Image', compute='_compute_image', readonly=True, store=True) + image = fields.Binary('Image', compute='_compute_image', store=True, attachment=True) @api.one @api.depends('speaker_ids.image') @@ -213,4 +213,4 @@ class event_sponsors(models.Model): partner_id = fields.Many2one('res.partner', 'Sponsor/Customer', required=True) url = fields.Char('Sponsor Website') sequence = fields.Integer('Sequence', store=True, related='sponsor_type_id.sequence') - image_medium = fields.Binary(string='Logo', type='binary', related='partner_id.image_medium', store=True) + image_medium = fields.Binary(string='Logo', related='partner_id.image_medium', store=True, attachment=True) diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py index 814bc38b048..7d14d735d19 100644 --- a/addons/website_sale/models/product.py +++ b/addons/website_sale/models/product.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import openerp from openerp import tools from openerp.osv import osv, fields @@ -43,46 +44,46 @@ class product_public_category(osv.osv): res = self.name_get(cr, uid, ids, context=context) return dict(res) - def _get_image(self, cr, uid, ids, name, args, 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) - return result - - def _set_image(self, cr, uid, id, name, value, args, context=None): - return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context) - _columns = { 'name': fields.char('Name', required=True, translate=True), 'complete_name': fields.function(_name_get_fnc, type="char", string='Name'), 'parent_id': fields.many2one('product.public.category','Parent Category', select=True), 'child_id': fields.one2many('product.public.category', 'parent_id', string='Children Categories'), 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of product categories."), - - # NOTE: there is no 'default image', because by default we don't show thumbnails for categories. However if we have a thumbnail - # for at least one category, then we display a default image on the other, so that the buttons have consistent styling. - # In this case, the default image is set by the js code. - # NOTE2: image: all image fields are base64 encoded and PIL-supported - '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.public.category': (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."), - 'image_small': fields.function(_get_image, fnct_inv=_set_image, - string="Smal-sized image", type="binary", multi="_get_image", - store={ - 'product.public.category': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Small-sized image of the category. It is automatically "\ - "resized as a 64x64px image, with aspect ratio preserved. "\ - "Use this field anywhere a small image is required."), } + # NOTE: there is no 'default image', because by default we don't show + # thumbnails for categories. However if we have a thumbnail for at least one + # category, then we display a default image on the other, so that the + # buttons have consistent styling. + # In this case, the default image is set by the js code. + image = openerp.fields.Binary("Image", attachment=True, + help="This field holds the image used as image for the category, 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 the category. 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 the category. It is automatically "\ + "resized as a 64x64px image, with aspect ratio preserved. "\ + "Use this field anywhere a small image is required.") + + @openerp.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) + class product_template(osv.Model): _inherit = ["product.template", "website.seo.metadata", 'website.published.mixin', 'rating.mixin'] _order = 'website_published desc, website_sequence desc, name' diff --git a/addons/website_slides/models/slides.py b/addons/website_slides/models/slides.py index c62abddcc8e..1a3fb5f66a0 100644 --- a/addons/website_slides/models/slides.py +++ b/addons/website_slides/models/slides.py @@ -231,9 +231,9 @@ class Slide(models.Model): [('none', 'No One'), ('user', 'Authentified Users Only'), ('public', 'Everyone')], string='Download Security', required=True, default='user') - image = fields.Binary('Image') - image_medium = fields.Binary('Medium', compute="_get_image", store=True) - image_thumb = fields.Binary('Thumbnail', compute="_get_image", store=True) + image = fields.Binary('Image', attachment=True) + image_medium = fields.Binary('Medium', compute="_get_image", store=True, attachment=True) + image_thumb = fields.Binary('Thumbnail', compute="_get_image", store=True, attachment=True) @api.depends('image') def _get_image(self):