~0k.io/ocb-server/usability-and-fix-on-res-partner-1

« back to all changes in this revision

Viewing changes to openerp/addons/base/res/res_users.py

  • Committer: Holger Brunn
  • Author(s): arthur.vuillard at akretion
  • Date: 2013-09-09 10:46:56 UTC
  • mfrom: (5061.1.1 ocb-server)
  • Revision ID: hbrunn@therp.nl-20130909104656-j5x166erz7wkcuc8
[FIX] user creation in different company (multi company)

Show diffs side-by-side

added added

removed removed

Lines of Context:
279
279
 
280
280
        return result
281
281
 
 
282
    def create(self, cr, uid, vals, context=None):
 
283
        user_id = super(res_users, self).create(cr, uid, vals, context=context)
 
284
        user = self.browse(cr, uid, user_id, context=context)
 
285
        if user.partner_id.company_id: 
 
286
            user.partner_id.write({'company_id': user.company_id.id})
 
287
        return user_id
 
288
 
282
289
    def write(self, cr, uid, ids, values, context=None):
283
290
        if not hasattr(ids, '__iter__'):
284
291
            ids = [ids]
293
300
                uid = 1 # safe fields only, so we write as super-user to bypass access rights
294
301
 
295
302
        res = super(res_users, self).write(cr, uid, ids, values, context=context)
296
 
 
 
303
        if 'company_id' in values:
 
304
            for user in self.browse(cr, uid, ids, context=context):
 
305
                # if partner is global we keep it that way
 
306
                if user.partner_id.company_id and user.partner_id.company_id.id != values['company_id']: 
 
307
                    user.partner_id.write({'company_id': user.company_id.id})
297
308
        # clear caches linked to the users
298
309
        self.pool.get('ir.model.access').call_cache_clearing_methods(cr)
299
310
        clear = partial(self.pool.get('ir.rule').clear_cache, cr)