[IMP] 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

bzr revid: jam@tinyerp.com-20130611055803-or29rx40278bqttt
This commit is contained in:
Jigar Amin (OpenERP) 2013-06-11 11:28:03 +05:30
parent d334814bf5
commit 7dafd9d58e
1 changed files with 5 additions and 6 deletions

View File

@ -493,13 +493,12 @@ class res_partner(osv.osv, format_address):
#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'):
if 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."))
for partner in self.browse(cr, uid, ids, context=context):
user_companies = set([users.company_id.id for users in partner.user_ids])
if len(user_companies) > 1 or vals.get('company_id') not in user_companies:
raise osv.except_osv(_("Warning"),_("You can not change the company as the partner/user 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)