- Allow setting the company_id of the partner to False in order to make the partner shared between all companies.
bzr revid: jam@tinyerp.com-20130513060734-niodo4rzs0m1v073
This commit is contained in:
parent
7ca67757fe
commit
6d4215c9bf
|
@ -488,6 +488,17 @@ class res_partner(osv.osv, format_address):
|
|||
def write(self, cr, uid, ids, vals, context=None):
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
#res.partner must only allow to set the company_id of a partner if it
|
||||
#is the same as the company of all users that inherit from this partner
|
||||
#(this is to allow the code from res_users to write to the partner!) or
|
||||
#if setting the company_id to False (this is compatible with any user company)
|
||||
if 'company_id' in vals and vals.get('company_id'):
|
||||
user_pool = self.pool.get('res.users')
|
||||
for partner in ids:
|
||||
uspa = user_pool.search(cr, uid, [('partner_id', '=', partner)], context=context)
|
||||
usco = set([user.company_id.id for user in user_pool.browse(cr, uid, uspa, context=context)])
|
||||
if usco and len(usco) > 1:
|
||||
raise osv.except_osv(_("Warning"),_("You can not chnage the partner company as the partner has mutiple user linked with different companies."))
|
||||
result = super(res_partner,self).write(cr, uid, ids, vals, context=context)
|
||||
for partner in self.browse(cr, uid, ids, context=context):
|
||||
self._fields_sync(cr, uid, partner, vals, context)
|
||||
|
|
|
@ -281,10 +281,9 @@ class res_users(osv.osv):
|
|||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
user_id = super(res_users, self).create(cr, uid, vals, context=context)
|
||||
#User->Partner Company has to be Same as User Company, instaed logged in users.
|
||||
user = self.read(cr, uid, user_id, ['partner_id', 'company_id'], context=context)
|
||||
company_id = self._get_company( cr, uid, context=context, uid2=user['id'])
|
||||
self.pool.get('res.partner').write(cr,uid, user['partner_id'][0], {'company_id':company_id})
|
||||
user = self.browse(cr, uid, user_id, context=context)
|
||||
if user.partner_id.company_id:
|
||||
user.partner_id.write({'company_id': user.company_id.id})
|
||||
return user_id
|
||||
|
||||
def write(self, cr, uid, ids, values, context=None):
|
||||
|
@ -301,13 +300,11 @@ class res_users(osv.osv):
|
|||
uid = 1 # safe fields only, so we write as super-user to bypass access rights
|
||||
|
||||
res = super(res_users, self).write(cr, uid, ids, values, context=context)
|
||||
#User->Partner Company has to be Same as User Company, instaed logged in users.
|
||||
if 'company_id' in values:
|
||||
partner_pool = self.pool.get('res.partner')
|
||||
for user in self.read(cr, uid, ids, ['partner_id', 'company_id'], context=context):
|
||||
company_id = self._get_company( cr, uid, context=context, uid2=user['id'])
|
||||
partner_pool.write(cr,uid, user['partner_id'][0], {'company_id':company_id})
|
||||
|
||||
for user in self.browse(cr, uid, ids, context=context):
|
||||
# if partner is global we keep it that way
|
||||
if user.partner_id.company_id and user.partner_id.company_id.id != values.get('company_id'):
|
||||
user.partner_id.write({'company_id': user.company_id.id})
|
||||
# clear caches linked to the users
|
||||
self.pool.get('ir.model.access').call_cache_clearing_methods(cr)
|
||||
clear = partial(self.pool.get('ir.rule').clear_cache, cr)
|
||||
|
|
Loading…
Reference in New Issue