X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=addons%2Fproduct%2Fproduct.py;h=14b371b2cea9ca4f4a7444edb53cab9b84413360;hb=282f72391b9d3a2de8b68abcdf6c8857c62b00e5;hp=a81074aa56e215fa9b725f20dd301209bda5e096;hpb=3905f5248f6ecd6383f8f68bf60e8ca0ad2a0e51;p=odoo%2Fodoo.git diff --git a/addons/product/product.py b/addons/product/product.py index a81074a..14b371b 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -25,6 +25,7 @@ import decimal_precision as dp import math from _common import rounding import re +import tools from tools.translate import _ def is_pair(x): @@ -492,6 +493,22 @@ class product_product(osv.osv): (data['name'] or '') + (data['variants'] and (' - '+data['variants']) or '') return 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): + resized_image_dict = tools.get_resized_images(obj.image) + result[obj.id] = { + 'image_medium': resized_image_dict['image_medium'], + 'image_small': resized_image_dict['image_small'], + } + return result + + def _set_image(self, cr, uid, id, name, value, args, context=None): + return self.write(cr, uid, [id], {'image': tools.resize_image_big(value)}, context=context) + + def onchange_image(self, cr, uid, ids, value, context=None): + return {'value': tools.get_resized_images(value)} + _defaults = { 'active': lambda *a: 1, 'price_extra': lambda *a: 0.0, @@ -525,7 +542,26 @@ class product_product(osv.osv): 'pricelist_id': fields.dummy(string='Pricelist', relation='product.pricelist', type='many2one'), 'name_template': fields.related('product_tmpl_id', 'name', string="Name", type='char', size=128, store=True, select=True), 'color': fields.integer('Color Index'), - 'product_image': fields.binary('Image'), + 'image': fields.binary("Image", + help="This field holds the image used for the product. "\ + "The image is base64 encoded, and PIL-supported. "\ + "It is limited to a 12024x1024 px image."), + 'image_medium': fields.function(_get_image, fnct_inv=_set_image, + string="Medium-sized image", type="binary", multi="_get_image", + store = { + 'product.product': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Medium-sized image of the product. It is automatically "\ + "resized as a 180x180px image, with aspect ratio kept. "\ + "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.product': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Small-sized image of the product. It is automatically "\ + "resized as a 50x50px image, with aspect ratio keps. "\ + "Use this field anywhere a small image is required."), } def create(self, cr, uid, vals, context=None):