[IMP] res.users: cleaned a bit the code; res_partner: from photo to specified images; update res_company because of its logo coming from res.partner old photo.
bzr revid: tde@openerp.com-20120627155749-ms6p6d7z8c5u2gjg
This commit is contained in:
@@ -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'),
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Partners" version="7.0">
|
||||
<sheet>
|
||||
<field name="photo" widget='image' class="oe_avatar oe_right" height="70"/>
|
||||
<field name="image_small" widget='image' class="oe_avatar oe_right" on_change="onchange_image(image_small)" height="70"/>
|
||||
<div class="oe_right oe_button_box" name="buttons">
|
||||
|
||||
</div>
|
||||
@@ -180,7 +180,7 @@
|
||||
<field name="phone"/>
|
||||
<field name="street"/>
|
||||
<field name="street2"/>
|
||||
<field name="photo"/>
|
||||
<field name="image_small"/>
|
||||
<field name="zip"/>
|
||||
<field name="city"/>
|
||||
<field name="country_id"/>
|
||||
@@ -193,7 +193,7 @@
|
||||
<a t-if="! read_only_mode" type="delete" style="position: absolute; right: 0; padding: 4px; diplay: inline-block">X</a>
|
||||
<div class="oe_module_vignette">
|
||||
<a type="edit">
|
||||
<img t-att-src="kanban_image('res.partner', 'photo', record.id.value)" class="oe_avatar oe_kanban_avatar_toto"/>
|
||||
<img t-att-src="kanban_image('res.partner', 'image_small', record.id.value)" class="oe_avatar oe_kanban_avatar_toto"/>
|
||||
</a>
|
||||
<div class="oe_module_desc">
|
||||
<div class="oe_kanban_box_content oe_kanban_color_bglight oe_kanban_box_show_onclick_trigger oe_kanban_color_border">
|
||||
@@ -294,7 +294,7 @@
|
||||
<field name="phone"/>
|
||||
<field name="street"/>
|
||||
<field name="street2"/>
|
||||
<field name="photo"/>
|
||||
<field name="image_small"/>
|
||||
<field name="zip"/>
|
||||
<field name="city"/>
|
||||
<field name="country_id"/>
|
||||
@@ -304,7 +304,7 @@
|
||||
<t t-name="kanban-box">
|
||||
<div class="oe_kanban_vignette">
|
||||
<a type="edit">
|
||||
<img t-att-src="kanban_image('res.partner', 'photo', record.id.value)" class="oe_kanban_image"/>
|
||||
<img t-att-src="kanban_image('res.partner', 'image_small', record.id.value)" class="oe_kanban_image"/>
|
||||
</a>
|
||||
<div class="oe_kanban_details">
|
||||
<h4 class="oe_partner_heading"><a type="edit"><field name="name"/></a>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<field name="id" invisible="1"/>
|
||||
<sheet>
|
||||
<div class="oe_right">
|
||||
<field name="image_medium" widget='image' nolabel="1" on_change="onchange_image(image_medium)" class="oe_avatar"/>
|
||||
<field name="image_small" widget='image' nolabel="1" on_change="onchange_image(image_small)" class="oe_avatar"/>
|
||||
</div>
|
||||
<div class="oe_title">
|
||||
<label for="name" class="oe_edit_only"/>
|
||||
|
||||
Reference in New Issue
Block a user