Merge lp:~akretion-team/ocb-server/fix-user-creation-in-multi-company into lp:ocb-server

Proposed by arthru
Status: Merged
Merged at revision: 5085
Proposed branch: lp:~akretion-team/ocb-server/fix-user-creation-in-multi-company
Merge into: lp:ocb-server
Diff against target: 51 lines (+22/-1)
2 files modified
openerp/addons/base/res/res_partner.py (+10/-0)
openerp/addons/base/res/res_users.py (+12/-1)
To merge this branch: bzr merge lp:~akretion-team/ocb-server/fix-user-creation-in-multi-company
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) Approve
Guewen Baconnier @ Camptocamp Approve
Stefan Rijnhart (Opener) core review, testing Approve
Review via email: mp+179762@code.launchpad.net

Description of the change

I propose to merge https://code.launchpad.net/~openerp-dev/openobject-server/7.0-opw-591308-jam/+merge/158311 to OCB as there is no update on merging it in main branch despite many approval.

I've tested it on revno 5061 of lp:ocb-server and it works just fine (res_users and its res_partner have the same company_id) and there is no more Access Denied error (as described in https://bugs.launchpad.net/openobject-server/+bug/1073087).

To post a comment you must log in.
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks! I tested the original fix and as far as I can see this is the exact same change.

review: Approve (core review, testing)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

LGTM

review: Approve
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

I think the error message in 17 sounds weird. Wouldn't "You cannot change the company as the partner has multiple users linked with different companies." be better?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openerp/addons/base/res/res_partner.py'
--- openerp/addons/base/res/res_partner.py 2013-06-12 09:53:00 +0000
+++ openerp/addons/base/res/res_partner.py 2013-08-12 18:04:04 +0000
@@ -489,6 +489,16 @@
489 def write(self, cr, uid, ids, vals, context=None):489 def write(self, cr, uid, ids, vals, context=None):
490 if isinstance(ids, (int, long)):490 if isinstance(ids, (int, long)):
491 ids = [ids]491 ids = [ids]
492 #res.partner must only allow to set the company_id of a partner if it
493 #is the same as the company of all users that inherit from this partner
494 #(this is to allow the code from res_users to write to the partner!) or
495 #if setting the company_id to False (this is compatible with any user company)
496 if vals.get('company_id'):
497 for partner in self.browse(cr, uid, ids, context=context):
498 if partner.user_ids:
499 user_companies = set([user.company_id.id for user in partner.user_ids])
500 if len(user_companies) > 1 or vals['company_id'] not in user_companies:
501 raise osv.except_osv(_("Warning"),_("You can not change the company as the partner/user has multiple user linked with different companies."))
492 result = super(res_partner,self).write(cr, uid, ids, vals, context=context)502 result = super(res_partner,self).write(cr, uid, ids, vals, context=context)
493 for partner in self.browse(cr, uid, ids, context=context):503 for partner in self.browse(cr, uid, ids, context=context):
494 self._fields_sync(cr, uid, partner, vals, context)504 self._fields_sync(cr, uid, partner, vals, context)
495505
=== modified file 'openerp/addons/base/res/res_users.py'
--- openerp/addons/base/res/res_users.py 2013-06-07 09:30:57 +0000
+++ openerp/addons/base/res/res_users.py 2013-08-12 18:04:04 +0000
@@ -279,6 +279,13 @@
279279
280 return result280 return result
281281
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 def write(self, cr, uid, ids, values, context=None):289 def write(self, cr, uid, ids, values, context=None):
283 if not hasattr(ids, '__iter__'):290 if not hasattr(ids, '__iter__'):
284 ids = [ids]291 ids = [ids]
@@ -293,7 +300,11 @@
293 uid = 1 # safe fields only, so we write as super-user to bypass access rights300 uid = 1 # safe fields only, so we write as super-user to bypass access rights
294301
295 res = super(res_users, self).write(cr, uid, ids, values, context=context)302 res = super(res_users, self).write(cr, uid, ids, values, context=context)
296303 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 # clear caches linked to the users308 # clear caches linked to the users
298 self.pool.get('ir.model.access').call_cache_clearing_methods(cr)309 self.pool.get('ir.model.access').call_cache_clearing_methods(cr)
299 clear = partial(self.pool.get('ir.rule').clear_cache, cr)310 clear = partial(self.pool.get('ir.rule').clear_cache, cr)

Subscribers

People subscribed via source and target branches

to status/vote changes: