diff --git a/openerp/addons/base/res/res_company.py b/openerp/addons/base/res/res_company.py index 2454f342436..5e2e345632d 100644 --- a/openerp/addons/base/res/res_company.py +++ b/openerp/addons/base/res/res_company.py @@ -113,7 +113,7 @@ class res_company(osv.osv): 'rml_header': fields.text('RML Header', required=True), 'rml_header2': fields.text('RML Internal Header', required=True), 'rml_header3': fields.text('RML Internal Header', required=True), - 'logo': fields.related('partner_id', 'photo', string="Logo", type="binary"), + 'logo': fields.related('partner_id', 'image_medium', string="Logo", type="binary"), 'currency_id': fields.many2one('res.currency', 'Currency', required=True), 'currency_ids': fields.one2many('res.currency', 'company_id', 'Currency'), 'user_ids': fields.many2many('res.users', 'res_company_users_rel', 'cid', 'user_id', 'Accepted Users'), diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index 1f4e11fca26..08cf19731c6 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -129,6 +129,33 @@ class res_partner(osv.osv): res[partner.id] =self._display_address(cr, uid, partner, context=context) 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): + result[obj.id] = {'image_medium': False, 'image_small': False} + if obj.image: + result[obj.id]['image_medium'] = tools.resize_image_medium(obj.image) + result[obj.id]['image_small'] = tools.resize_image_small(obj.image) + return result + + def _set_image(self, cr, uid, id, name, value, args, context=None): + if value: + value = tools.resize_image_big(value) + return self.write(cr, uid, [id], {'image': value}, context=context) + + def onchange_image(self, cr, uid, ids, value, context=None): + if not value: + return {'value': { + 'image': value, + 'image_medium': value, + 'image_small': value, + }} + return {'value': { + 'image': tools.resize_image_big(value), + 'image_medium': tools.resize_image_medium(value), + 'image_small': tools.resize_image_small(value), + }} + _order = "name" _columns = { 'name': fields.char('Name', size=128, required=True, select=True), @@ -170,7 +197,26 @@ class res_partner(osv.osv): 'birthdate': fields.char('Birthdate', size=64), 'is_company': fields.boolean('Company', help="Check if the contact is a company, otherwise it is a person"), 'use_parent_address': fields.boolean('Use Company Address', help="Select this if you want to set company's address information for this contact"), - 'photo': fields.binary('Photo'), + 'image': fields.binary("Avatar", + help="This field holds the image used as avatar for the "\ + "user. 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 avatar", type="binary", multi="_get_image", + store = { + 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Medium-sized image of the user. 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 avatar", type="binary", multi="_get_image", + store = { + 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Small-sized image of the user. It is automatically "\ + "resized as a 50x50px image, with aspect ratio keps. "\ + "Use this field anywhere a small image is required."), 'company_id': fields.many2one('res.company', 'Company', select=1), 'color': fields.integer('Color Index'), 'contact_address': fields.function(_address_display, type='char', string='Complete Address'), @@ -183,12 +229,12 @@ class res_partner(osv.osv): return [context['category_id']] return False - def _get_photo(self, cr, uid, is_company, context=None): + def _get_default_image(self, cr, uid, is_company, context=None): if is_company: - path = os.path.join( tools.config['root_path'], 'addons', 'base', 'res', 'company_icon.png') + image_path = os.path.join( tools.config['root_path'], 'addons', 'base', 'res', 'company_icon.png') else: - path = os.path.join( tools.config['root_path'], 'addons', 'base', 'res', 'photo.png') - return open(path, 'rb').read().encode('base64') + image_path = os.path.join( tools.config['root_path'], 'addons', 'base', 'res', 'photo.png') + return tools.resize_image_big(open(image_path, 'rb').read().encode('base64')) _defaults = { 'active': True, @@ -199,7 +245,7 @@ class res_partner(osv.osv): 'is_company': False, 'type': 'default', 'use_parent_address': True, - 'photo': lambda self, cr, uid, context: self._get_photo(cr, uid, False, context), + 'image': lambda self, cr, uid, context: self._get_default_image(cr, uid, False, context), } def copy(self, cr, uid, id, default=None, context=None): @@ -210,8 +256,9 @@ class res_partner(osv.osv): return super(res_partner, self).copy(cr, uid, id, default, context) def onchange_type(self, cr, uid, ids, is_company, context=None): - value = {'title': False, - 'photo': self._get_photo(cr, uid, is_company, context)} + # get value as for an onchange on the image + value = self.onchange_image(cr, uid, ids, self._get_default_image(cr, uid, is_company, context), context=context)['value'] + value['title'] = False if is_company: value['parent_id'] = False domain = {'title': [('domain', '=', 'partner')]} @@ -266,6 +313,7 @@ class res_partner(osv.osv): domain_siblings = [('parent_id', '=', partner.parent_id.id), ('use_parent_address', '=', True)] update_ids = [partner.parent_id.id] + self.search(cr, uid, domain_siblings, context=context) self.update_address(cr, uid, update_ids, vals, context) + print vals return super(res_partner,self).write(cr, uid, ids, vals, context=context) def create(self, cr, uid, vals, context=None): @@ -276,8 +324,9 @@ class res_partner(osv.osv): domain_siblings = [('parent_id', '=', vals['parent_id']), ('use_parent_address', '=', True)] update_ids = [vals['parent_id']] + self.search(cr, uid, domain_siblings, context=context) self.update_address(cr, uid, update_ids, vals, context) - if 'photo' not in vals : - vals['photo'] = self._get_photo(cr, uid, vals.get('is_company', False) or context.get('default_is_company'), context) + if 'image' not in vals : + image_value = self._get_default_image(cr, uid, vals.get('is_company', False) or context.get('default_is_company'), context) + vals.update(self.onchange_image(cr, uid, [], image_value, context=context)) return super(res_partner,self).create(cr, uid, vals, context=context) def update_address(self, cr, uid, ids, vals, context=None): diff --git a/openerp/addons/base/res/res_partner_view.xml b/openerp/addons/base/res/res_partner_view.xml index aaab3a7d008..c31d061bcad 100644 --- a/openerp/addons/base/res/res_partner_view.xml +++ b/openerp/addons/base/res/res_partner_view.xml @@ -101,7 +101,7 @@
- +
@@ -180,7 +180,7 @@ - + @@ -193,7 +193,7 @@ X
- +
@@ -294,7 +294,7 @@ - + @@ -304,7 +304,7 @@
- +

diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index d9c18b27dcb..b983b12c744 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -165,29 +165,27 @@ class users(osv.osv): def _get_password(self, cr, uid, ids, arg, karg, context=None): return dict.fromkeys(ids, '') - def _get_image_resized(self, cr, uid, ids, name, args, context=None): + def _get_image(self, cr, uid, ids, name, args, context=None): result = dict.fromkeys(ids, False) - for user in self.browse(cr, uid, ids, context=context): - result[user.id] = {'image_medium': False, 'image_small': False} - if user.image: - result[user.id]['image_medium'] = tools.resize_image_medium(user.image) - result[user.id]['image_small'] = tools.resize_image_small(user.image) + for obj in self.browse(cr, uid, ids, context=context): + result[obj.id] = {'image_medium': False, 'image_small': False} + if obj.image: + result[obj.id]['image_medium'] = tools.resize_image_medium(obj.image) + result[obj.id]['image_small'] = tools.resize_image_small(obj.image) return result - def _set_image_resized(self, cr, uid, id, name, value, args, context=None): - if not value: - vals = {'image': value} - else: - vals = {'image': tools.resize_image_big(value)} - return self.write(cr, uid, [id], vals, context=context) + def _set_image(self, cr, uid, id, name, value, args, context=None): + if value: + value = tools.resize_image_big(value) + return self.write(cr, uid, [id], {'image': value}, context=context) def onchange_image(self, cr, uid, ids, value, context=None): if not value: return {'value': { - 'image': value, - 'image_medium': value, - 'image_small': value, - }} + 'image': value, + 'image_medium': value, + 'image_small': value, + }} return {'value': { 'image': tools.resize_image_big(value), 'image_medium': tools.resize_image_medium(value), @@ -210,26 +208,24 @@ class users(osv.osv): 'signature': fields.text('Signature', size=64), 'image': fields.binary("Avatar", help="This field holds the image used as avatar for the "\ - "user. The avatar field is used as an interface to "\ - "access this field. The image is base64 encoded, "\ - "and PIL-supported. It is stored as a 540x450 px "\ - "image, in case a bigger image must be used."), - 'image_medium': fields.function(_get_image_resized, fnct_inv=_set_image_resized, - string="Medium-sized avatar", type="binary", multi="_get_image_resized", + "user. 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 avatar", type="binary", multi="_get_image", store = { 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), }, help="Medium-sized image of the user. It is automatically "\ - "resized as a 180x180px image, with aspect ratio keps. "\ + "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_resized, fnct_inv=_set_image_resized, - string="Smal-sized avatar", type="binary", multi="_get_image_resized", + 'image_small': fields.function(_get_image, fnct_inv=_set_image, + string="Smal-sized avatar", type="binary", multi="_get_image", store = { 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), }, help="Small-sized image of the user. It is automatically "\ "resized as a 50x50px image, with aspect ratio keps. "\ - "Use this field in form views or some kanban views."), + "Use this field anywhere a small image is required."), 'active': fields.boolean('Active'), 'action_id': fields.many2one('ir.actions.actions', 'Home Action', help="If specified, this action will be opened at logon for this user, in addition to the standard menu."), 'menu_id': fields.many2one('ir.actions.actions', 'Menu Action', help="If specified, the action will replace the standard menu for this user."), @@ -338,7 +334,7 @@ class users(osv.osv): pass return result - def _get_image(self, cr, uid, context=None): + def _get_default_image(self, cr, uid, context=None): # default image file name: avatar0 -> avatar6.png, choose randomly image_path = openerp.modules.get_module_resource('base', 'static/src/img', 'avatar%d.png' % random.randint(0, 6)) return tools.resize_image_big(open(image_path, 'rb').read().encode('base64')) @@ -347,7 +343,7 @@ class users(osv.osv): 'password' : '', 'context_lang': lambda self, cr, uid, context: context.get('lang', 'en_US'), 'context_tz': lambda self, cr, uid, context: context.get('tz', False), - 'image_medium': _get_image, + 'image': _get_default_image, 'active' : True, 'menu_id': _get_menu, 'company_id': _get_company, diff --git a/openerp/addons/base/res/res_users_view.xml b/openerp/addons/base/res/res_users_view.xml index 28790a342a2..0b3ad957adb 100644 --- a/openerp/addons/base/res/res_users_view.xml +++ b/openerp/addons/base/res/res_users_view.xml @@ -82,7 +82,7 @@
- +