From 353a5aabeb8c7fa2053d71a313e8f02f82770350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 09:30:05 +0100 Subject: [PATCH 01/47] [ADD] res.users: added photo field bzr revid: tde@openerp.com-20120221083005-6lpz3208cgzwpcau --- openerp/addons/base/res/res_users.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index f148813ae05..ae1f1f9fe91 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -241,6 +241,7 @@ class users(osv.osv): "otherwise leave empty. After a change of password, the user has to login again."), 'user_email': fields.char('Email', size=64), 'signature': fields.text('Signature', size=64), + 'photo': fields.binary('Photo'), '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."), From 5d267e015860ec8ef3de64768a7238c62e60c1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 09:30:49 +0100 Subject: [PATCH 02/47] [ADD] Added default user photo file bzr revid: tde@openerp.com-20120221083049-crwehkw9qxwzlmmb --- openerp/addons/base/images/photo.png | Bin 0 -> 2685 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 openerp/addons/base/images/photo.png diff --git a/openerp/addons/base/images/photo.png b/openerp/addons/base/images/photo.png new file mode 100644 index 0000000000000000000000000000000000000000..1d124127b2bf7115fdb38ab2fc136fdf5b531237 GIT binary patch literal 2685 zcmV-@3WD{CP)@cEZEfxEk3asno3<^Q<_tXZ%rjptisIYOxmYO`k|dEhj$y6UT5BSrwW26~{@7!W z4W?ytDg>T*;)!H-cJ@bQSsn&Z0w~fnt+Ff&aU4?|$JSb#0!W>6rYy_fJo@OPzn|DJ z05uIIb8~Y)b0#_|B70 zJ{e7Ff1*YF^wUrGwAPOR820=9t-)Y$WoBk(n}`Y#aUle8&Y`L*4WQCm2j?7#h#{i6 zg9i`(1i;TeH3G(%FL>|6)vH$rhYugVHZwERUt3!nZES2*Q55mw;-Xk<5kd&gIUbEh z6hg2egbYBZEX#wF*q@kywf6Iyo15;ThaM^x78XX<+T#BE?{`Y6aQ^&xxp3hEhQlH5 zzWeTwBngZ$l~QW7y}douS{EUNxu>3b%1#nqC(Q!~XJ=>q+}vEPl&Y0dL2Dhf)^hy# zaXESNWIK)ku!wkOt_Oob{pzc)*2Wl)qUb&VZ{I0^i54+4ck?`FrIaV4pp*(qDG(8e z2qMz_^dyj~AjVOioUL(A3-#+%< zW70e{5dmXNIXgSs0^4&;`~4Up0l;w_OQ+L86h&7i!Ena}UU}t}Kp!}8z+-|13`{_v z)9L)9uIsMWS_6ng#E6J)35)@6!IOw+5wXqq$a|j<(d(ZIffFZAlp%z-8@EXTq(l?} z(DYFocdPczCjc@LNvf*ijg5^rKNSK15JLFva5&r+kz7PNA%ujPt%xXQMkCaSX68sl zvJgVf%rP@Refsoi{?rJZI(6zT0KX0)WX#+RA#_3rQ3JLG4rW%&Y?wJ=<~)Rud+$G3 zUS9s^B=#pJ001XXp1k0_-)81cLm&+yjL!lwvkDYTG71kKD8LZGH^LkNj;E-lM43L*SyDz>Mgq^hbv)OBr`Icwf>q6dp?Y)Qho*FVHgb;0SZ`*#q z|F>z_1*Sv*0HP>*>(Zr5)_ZT8J-=$+JT)_+opa{>_un^JmQ9qr#@p1&Dp{6Y9F0bb znGFEN%!-;M&|LM(%8FiCSfIgR@XoaCPK^LF*M|-rqLq~uSZmed;v(AJW>r;KSy{pS z{52$uKwXTS$ zBqB#dfrz+~KtxVNN+K$=Ec^bn>`qLeD2n;@_4V)Od9DCl6Okb^S0WOaSpZ1WF98hF zH0{sL&CM1?@x7|5mL|1-$1b$Bwe`iSs=jWmJ=E*AzTX~Y#U>Clu`pCD$25SWm$?+3Q-hMk|b6{5^HTINs<`=Ga}LjkO4@Td8Cwj z%{lkGJkPhLN?>bi>;BPb^i8ex=h8G~A}WkABM}*Dtp`LjAfgd7kF?fRUDsYjxX~>{ zL|SX5wKmO}Aq9{(;5*HBJQI-=fFYs_BJxs_ByUYjV0Cr%2LQg(>2ykK?NDnyP)ZGn zXb51Wlq!g*1W*I;L=^CmD~u~Ae021*jl?3-9&mC1xrlT`q(elBi2OB8(_i5hu60WS ztE;O&^xmK7^?HLONp=A25Ya$uJ=9v4L{y82BO)&%Ohnv({y3%W@k}>FGGm;6>ynAHTy2+xSDF`7F!~?7CMfBDweeV87q*b-UebH!9dOk(FinwJ3_n7&8Je z5|M(L9T9nMwBy#Ua;HRCDb>1FAtJ-ZK5MNX-0Q)c2&}BESZ01$Ywd}s5|IkK)5;nY$%*;k96|b+aKYSyB>lX3LFTYG#mL0t7uDf&; zMTz&mCnBDRED;sn`7dIFTU6bA^iB>d+$9uKR;htYe(Muk%*L9>$=zL)m2sbvMgPm z=i~8woWx$qjBbz?cq^8fO0r0PuI63008IC zom1ZXdqm_b_uY5jgG)JyIk0%8R2U2f-WcOs0z|}(ueSN&#t=JRy;e#oYKpYoAp<(+rlSwC~;%uQR0TW%%Jo;|CUmzQ-}mWx$YJ+QR2 zbR^5N12Z!-y>7Q_j4|zgpPR_hZl47Jm|2bu)lO}0f{*M4VbXJ;@NTwGgQ z`&X~mdvpK({a0Uj;RV?X_-zr`Yi0oGG);A<)1k|kFVA}K=S3tn#>CFKn3 Date: Tue, 21 Feb 2012 09:49:39 +0100 Subject: [PATCH 03/47] [IMP] res.users: added photo in form view bzr revid: tde@openerp.com-20120221084939-2eewuecsd476f2jt --- openerp/addons/base/base_update.xml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/base_update.xml b/openerp/addons/base/base_update.xml index c5594f76e22..0ed0b525e5c 100644 --- a/openerp/addons/base/base_update.xml +++ b/openerp/addons/base/base_update.xml @@ -122,11 +122,17 @@ - - - - - + + + + + + + + + + + From 2388c019f15191adff1578ad7f6378aefc509823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 09:56:06 +0100 Subject: [PATCH 04/47] [IMP] res.users: added default photo (base/images/photo.png) bzr revid: tde@openerp.com-20120221085606-h5wufginyq4su9sw --- openerp/addons/base/res/res_users.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index ae1f1f9fe91..9b6a66d3b82 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -353,9 +353,14 @@ class users(osv.osv): pass return result + def _get_photo(self, cr, uid, context=None): + photo_path = openerp.modules.get_module_resource('base','images','photo.png') + return open(photo_path, 'rb').read().encode('base64') + _defaults = { 'password' : '', 'context_lang': 'en_US', + 'photo': _get_photo, 'active' : True, 'menu_id': _get_menu, 'company_id': _get_company, From 0e6c779ae2a213e748a9199d127259afa2c67117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 10:12:57 +0100 Subject: [PATCH 05/47] [ADD] Added photo_mini field, holding a resized version of photo. Added resizing method. bzr revid: tde@openerp.com-20120221091257-r2g306wgkalcpyrl --- openerp/addons/base/res/res_users.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 9b6a66d3b82..5907840cd5b 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -35,6 +35,9 @@ from tools.translate import _ import openerp import openerp.exceptions +import io, StringIO +from PIL import Image + _logger = logging.getLogger(__name__) class groups(osv.osv): @@ -200,6 +203,20 @@ class users(osv.osv): self.write(cr, uid, ids, {'groups_id': [(4, extended_group_id)]}, context=context) return True + def _get_photo_mini(self, cr, uid, ids, name, args, context=None): + result = {} + for obj in self.browse(cr, uid, ids, context=context): + if not obj.photo: + result[obj.id] = False + continue + + image_stream = io.BytesIO(obj.photo.decode('base64')) + img = Image.open(image_stream) + img.thumbnail((120, 100), Image.ANTIALIAS) + img_stream = StringIO.StringIO() + img.save(img_stream, "JPEG") + result[obj.id] = img_stream.getvalue().encode('base64') + return result def _get_interface_type(self, cr, uid, ids, name, args, context=None): """Implementation of 'view' function field getter, returns the type of interface of the users. @@ -242,6 +259,10 @@ class users(osv.osv): 'user_email': fields.char('Email', size=64), 'signature': fields.text('Signature', size=64), 'photo': fields.binary('Photo'), + 'photo_mini': fields.function(_get_photo_mini, string='Photo Mini', type="binary", + store = { + 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10), + }), '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."), From 42806faa81f5025cda6ec3bccbfc2e924f2bda9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 10:23:54 +0100 Subject: [PATCH 06/47] [ADD] res.users: preferences screen: added photo field bzr revid: tde@openerp.com-20120221092354-x4hw1uqk8afk0k08 --- openerp/addons/base/base_update.xml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/openerp/addons/base/base_update.xml b/openerp/addons/base/base_update.xml index 0ed0b525e5c..af915e083aa 100644 --- a/openerp/addons/base/base_update.xml +++ b/openerp/addons/base/base_update.xml @@ -84,12 +84,18 @@
- - - - - - + + + + + + + + + + + + @@ -131,7 +137,7 @@ - + From 4183dcb27e79fa843b3b3e64879bb885ac86a744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 11:04:51 +0100 Subject: [PATCH 07/47] [IMP] res.users: form view: cleaned code tabulations, added names to fields for inheritance bzr revid: tde@openerp.com-20120221100451-2kl56w08ggdtxtj5 --- openerp/addons/base/base_update.xml | 54 ++++++++++++++--------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/openerp/addons/base/base_update.xml b/openerp/addons/base/base_update.xml index af915e083aa..250305ca7db 100644 --- a/openerp/addons/base/base_update.xml +++ b/openerp/addons/base/base_update.xml @@ -124,38 +124,38 @@ - - - - - - - - - + + + + + + + + + + + + + + - - - + + + + + + + + - - - - - - - - + + + + - - - - - - From ac1f134ac94b0bfacdae301f931220d2b03e3da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 11:12:05 +0100 Subject: [PATCH 08/47] [REF] Removed unused group names bzr revid: tde@openerp.com-20120221101205-akwdpwn09ytnagp1 --- openerp/addons/base/base_update.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/base_update.xml b/openerp/addons/base/base_update.xml index 250305ca7db..983ef792e25 100644 --- a/openerp/addons/base/base_update.xml +++ b/openerp/addons/base/base_update.xml @@ -127,8 +127,8 @@ - - + + From c9d383613a0996aed2a4f680147921ccbbbefeec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 12:35:23 +0100 Subject: [PATCH 09/47] [IMP] res.users: added photo_calc for calculated photo; can be overriden to display photo from another module (ex: hr). By default, photo_calc is the photo defined in the user. bzr revid: tde@openerp.com-20120221113523-1o3j83a9hrtcojh9 --- openerp/addons/base/res/res_users.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 5907840cd5b..4e52771b97d 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -218,6 +218,18 @@ class users(osv.osv): result[obj.id] = img_stream.getvalue().encode('base64') return result + def _get_photo_calc(self, cr, uid, ids, name, args, context=None): + result = {} + for user in self.browse(cr, uid, ids, context=context): + result[user.id] = user.photo + return result + + def _get_photo_calc_mini(self, cr, uid, ids, name, args, context=None): + result = {} + for user in self.browse(cr, uid, ids, context=context): + result[user.id] = user.photo_mini + return result + def _get_interface_type(self, cr, uid, ids, name, args, context=None): """Implementation of 'view' function field getter, returns the type of interface of the users. @param field_name: Name of the field @@ -258,11 +270,13 @@ class users(osv.osv): "otherwise leave empty. After a change of password, the user has to login again."), 'user_email': fields.char('Email', size=64), 'signature': fields.text('Signature', size=64), - 'photo': fields.binary('Photo'), - 'photo_mini': fields.function(_get_photo_mini, string='Photo Mini', type="binary", + 'photo': fields.binary('User Photo'), + 'photo_mini': fields.function(_get_photo_mini, string='User Photo Mini', type="binary", store = { 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10), }), + 'photo_calc': fields.function(_get_photo_calc, string='Photo', type="binary", readonly=True), + 'photo_calc_mini': fields.function(_get_photo_calc_mini, string='Photo Mini', type="binary", readonly=True), '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."), From 1805d55959be90579e07e264a23965172b39d230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 14:12:28 +0100 Subject: [PATCH 10/47] [ADD] hr.employee: added a photo_mini field holding a resized version of photo field; modified inheritance of res.users to be able to use employee photo instead of user photo; added hr_photo_prior option to res.user form view bzr revid: tde@openerp.com-20120221131228-q0w6pyk6phlnmnrd --- addons/hr/hr.py | 54 +++++++++++++++++++++++++++++++++++++++++++ addons/hr/hr_view.xml | 13 +++++++++++ 2 files changed, 67 insertions(+) diff --git a/addons/hr/hr.py b/addons/hr/hr.py index 76f9295a829..6cc2b520f0f 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -23,6 +23,9 @@ from osv import fields, osv import logging import addons +import io, StringIO +from PIL import Image + class hr_employee_category(osv.osv): def name_get(self, cr, uid, ids, context=None): @@ -145,6 +148,23 @@ class hr_employee(osv.osv): _name = "hr.employee" _description = "Employee" _inherits = {'resource.resource': "resource_id"} + + def _get_photo_mini(self, cr, uid, ids, name, args, context=None): + result = {} + for obj in self.browse(cr, uid, ids, context=context): + print obj + if not obj.photo: + result[obj.id] = False + continue + + image_stream = io.BytesIO(obj.photo.decode('base64')) + img = Image.open(image_stream) + img.thumbnail((120, 100), Image.ANTIALIAS) + img_stream = StringIO.StringIO() + img.save(img_stream, "JPEG") + result[obj.id] = img_stream.getvalue().encode('base64') + return result + _columns = { 'country_id': fields.many2one('res.country', 'Nationality'), 'birthday': fields.date("Date of Birth"), @@ -171,6 +191,10 @@ class hr_employee(osv.osv): 'coach_id': fields.many2one('hr.employee', 'Coach'), 'job_id': fields.many2one('hr.job', 'Job'), 'photo': fields.binary('Photo'), + 'photo_mini': fields.function(_get_photo_mini, string='Photo Mini', type="binary", + store = { + 'hr.epployee': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10), + }), 'passport_id':fields.char('Passport No', size=64), 'color': fields.integer('Color Index'), 'city': fields.related('address_id', 'city', type='char', string='City'), @@ -274,6 +298,36 @@ class res_users(osv.osv): return user_id + def _get_photo_calc(self, cr, uid, ids, name, args, context=None): + result = {} + empl_obj = self.pool.get('hr.employee') + for user in self.browse(cr, uid, ids, context=context): + result[user.id] = user.photo + if user.hr_photo_prior: + empl_ids = empl_obj.search(cr, uid, [('user_id', '=', user.id)], context=context) + if empl_ids: + empl = empl_obj.browse(cr, uid, empl_ids, context=context)[0] + result[user.id] = empl.photo + return result + + def _get_photo_calc_mini(self, cr, uid, ids, name, args, context=None): + result = {} + empl_obj = self.pool.get('hr.employee') + for user in self.browse(cr, uid, ids, context=context): + result[user.id] = user.photo_mini + if user.hr_photo_prior: + empl_ids = empl_obj.search(cr, uid, [('user_id', '=', user.id)], context=context) + if empl_ids: + empl = empl_obj.browse(cr, uid, empl_ids, context=context)[0] + result[user.id] = empl.photo_mini + return result + + _columns = { + 'hr_photo_prior': fields.boolean('Use employee photo'), + 'photo_calc': fields.function(_get_photo_calc, string='Photo', type="binary", readonly=True), + 'photo_calc_mini': fields.function(_get_photo_calc_mini, string='Photo Mini', type="binary", readonly=True), + } + res_users() diff --git a/addons/hr/hr_view.xml b/addons/hr/hr_view.xml index 29066be2208..39da28b7025 100644 --- a/addons/hr/hr_view.xml +++ b/addons/hr/hr_view.xml @@ -219,6 +219,19 @@ + + + res.users.form_hr_photo + res.users + form + + + + + + + + + - - From 8413a61979942ab16fbebd1add8dcacfb29a36ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 16:15:42 +0100 Subject: [PATCH 13/47] [IMP] Removed calculated photo. res.users do not have to be aware it will be inherited. We won't make links between employee photo and user photo: user photo will be used. bzr revid: tde@openerp.com-20120221151542-u2ic748f0wtnvrsr --- openerp/addons/base/res/res_users.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 4e52771b97d..6ec8b6fd72f 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -218,18 +218,6 @@ class users(osv.osv): result[obj.id] = img_stream.getvalue().encode('base64') return result - def _get_photo_calc(self, cr, uid, ids, name, args, context=None): - result = {} - for user in self.browse(cr, uid, ids, context=context): - result[user.id] = user.photo - return result - - def _get_photo_calc_mini(self, cr, uid, ids, name, args, context=None): - result = {} - for user in self.browse(cr, uid, ids, context=context): - result[user.id] = user.photo_mini - return result - def _get_interface_type(self, cr, uid, ids, name, args, context=None): """Implementation of 'view' function field getter, returns the type of interface of the users. @param field_name: Name of the field @@ -275,8 +263,6 @@ class users(osv.osv): store = { 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10), }), - 'photo_calc': fields.function(_get_photo_calc, string='Photo', type="binary", readonly=True), - 'photo_calc_mini': fields.function(_get_photo_calc_mini, string='Photo Mini', type="binary", readonly=True), '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."), From dc6b84ab97e899d28d13eb278a001c95e2777adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 16:29:10 +0100 Subject: [PATCH 14/47] [IMP] Renamed photo field to avatar. Propagated changes. Modified user view: photo is now on the left of users tab. bzr revid: tde@openerp.com-20120221152910-mw9zm3fnbyxbmqq8 --- openerp/addons/base/base_update.xml | 25 ++++++++++++------------- openerp/addons/base/res/res_users.py | 26 +++++++++++++++----------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/openerp/addons/base/base_update.xml b/openerp/addons/base/base_update.xml index 04d72a480f3..0eef0a0f4cb 100644 --- a/openerp/addons/base/base_update.xml +++ b/openerp/addons/base/base_update.xml @@ -93,8 +93,8 @@ - - + + @@ -124,20 +124,19 @@ - + - + + + + + - - - - - - - - + + + @@ -149,7 +148,7 @@ - + diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py index 6ec8b6fd72f..7936ec2f5c9 100644 --- a/openerp/addons/base/res/res_users.py +++ b/openerp/addons/base/res/res_users.py @@ -203,21 +203,25 @@ class users(osv.osv): self.write(cr, uid, ids, {'groups_id': [(4, extended_group_id)]}, context=context) return True - def _get_photo_mini(self, cr, uid, ids, name, args, context=None): + def _get_avatar_mini(self, cr, uid, ids, name, args, context=None): result = {} for obj in self.browse(cr, uid, ids, context=context): - if not obj.photo: + if not obj.avatar: result[obj.id] = False continue - image_stream = io.BytesIO(obj.photo.decode('base64')) + image_stream = io.BytesIO(obj.avatar.decode('base64')) img = Image.open(image_stream) - img.thumbnail((120, 100), Image.ANTIALIAS) + img.thumbnail((180, 150), Image.ANTIALIAS) img_stream = StringIO.StringIO() img.save(img_stream, "JPEG") result[obj.id] = img_stream.getvalue().encode('base64') return result + def _set_avatar_mini(self, cr, uid, id, name, value, args, context=None): + self.write(cr, uid, [id], {'avatar': value}, context=context) + return True + def _get_interface_type(self, cr, uid, ids, name, args, context=None): """Implementation of 'view' function field getter, returns the type of interface of the users. @param field_name: Name of the field @@ -258,10 +262,10 @@ class users(osv.osv): "otherwise leave empty. After a change of password, the user has to login again."), 'user_email': fields.char('Email', size=64), 'signature': fields.text('Signature', size=64), - 'photo': fields.binary('User Photo'), - 'photo_mini': fields.function(_get_photo_mini, string='User Photo Mini', type="binary", + 'avatar': fields.binary('User Avatar'), + 'avatar_mini': fields.function(_get_avatar_mini, fnct_inv=_set_avatar_mini, string='User Avatar Mini', type="binary", store = { - 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10), + 'res.users': (lambda self, cr, uid, ids, c={}: ids, ['avatar'], 10), }), '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."), @@ -374,14 +378,14 @@ class users(osv.osv): pass return result - def _get_photo(self, cr, uid, context=None): - photo_path = openerp.modules.get_module_resource('base','images','photo.png') - return open(photo_path, 'rb').read().encode('base64') + def _get_avatar(self, cr, uid, context=None): + avatar_path = openerp.modules.get_module_resource('base','images','photo.png') + return open(avatar_path, 'rb').read().encode('base64') _defaults = { 'password' : '', 'context_lang': 'en_US', - 'photo': _get_photo, + 'avatar': _get_avatar, 'active' : True, 'menu_id': _get_menu, 'company_id': _get_company, From 08267fe081e81f2b2b50733cb5b55495f598817c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Feb 2012 16:31:18 +0100 Subject: [PATCH 15/47] [IMP] Removed link to res.users. Employee photo is now independant from user avatar. bzr revid: tde@openerp.com-20120221153118-o9792mljc9q0ir7d --- addons/hr/hr.py | 40 +++++++--------------------------------- addons/hr/hr_view.xml | 19 +------------------ 2 files changed, 8 insertions(+), 51 deletions(-) diff --git a/addons/hr/hr.py b/addons/hr/hr.py index 6cc2b520f0f..07b04998018 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -159,12 +159,16 @@ class hr_employee(osv.osv): image_stream = io.BytesIO(obj.photo.decode('base64')) img = Image.open(image_stream) - img.thumbnail((120, 100), Image.ANTIALIAS) + img.thumbnail((180, 150), Image.ANTIALIAS) img_stream = StringIO.StringIO() img.save(img_stream, "JPEG") result[obj.id] = img_stream.getvalue().encode('base64') return result + def _set_photo_mini(self, cr, uid, id, name, value, args, context=None): + self.write(cr, uid, [id], {'photo': value}, context=context) + return True + _columns = { 'country_id': fields.many2one('res.country', 'Nationality'), 'birthday': fields.date("Date of Birth"), @@ -191,9 +195,9 @@ class hr_employee(osv.osv): 'coach_id': fields.many2one('hr.employee', 'Coach'), 'job_id': fields.many2one('hr.job', 'Job'), 'photo': fields.binary('Photo'), - 'photo_mini': fields.function(_get_photo_mini, string='Photo Mini', type="binary", + 'photo_mini': fields.function(_get_photo_mini, fnct_inv=_set_photo_mini, string='Photo Mini', type="binary", store = { - 'hr.epployee': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10), + 'hr.employee': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10), }), 'passport_id':fields.char('Passport No', size=64), 'color': fields.integer('Color Index'), @@ -298,36 +302,6 @@ class res_users(osv.osv): return user_id - def _get_photo_calc(self, cr, uid, ids, name, args, context=None): - result = {} - empl_obj = self.pool.get('hr.employee') - for user in self.browse(cr, uid, ids, context=context): - result[user.id] = user.photo - if user.hr_photo_prior: - empl_ids = empl_obj.search(cr, uid, [('user_id', '=', user.id)], context=context) - if empl_ids: - empl = empl_obj.browse(cr, uid, empl_ids, context=context)[0] - result[user.id] = empl.photo - return result - - def _get_photo_calc_mini(self, cr, uid, ids, name, args, context=None): - result = {} - empl_obj = self.pool.get('hr.employee') - for user in self.browse(cr, uid, ids, context=context): - result[user.id] = user.photo_mini - if user.hr_photo_prior: - empl_ids = empl_obj.search(cr, uid, [('user_id', '=', user.id)], context=context) - if empl_ids: - empl = empl_obj.browse(cr, uid, empl_ids, context=context)[0] - result[user.id] = empl.photo_mini - return result - - _columns = { - 'hr_photo_prior': fields.boolean('Use employee photo'), - 'photo_calc': fields.function(_get_photo_calc, string='Photo', type="binary", readonly=True), - 'photo_calc_mini': fields.function(_get_photo_calc_mini, string='Photo Mini', type="binary", readonly=True), - } - res_users() diff --git a/addons/hr/hr_view.xml b/addons/hr/hr_view.xml index 7dd5fe98c16..733ebe901a0 100644 --- a/addons/hr/hr_view.xml +++ b/addons/hr/hr_view.xml @@ -33,7 +33,7 @@ - + @@ -219,23 +219,6 @@ - - - res.users.form_hr_photo - res.users - form - - - - - - - - - - - -