[FIX] fix demo data problem, now able to assign company to existing partner which does not have

any company. Did small variable name change

bzr revid: rha@tinyerp.com-20130801062706-imbu9ac2nimbd28f
This commit is contained in:
Rifakat 2013-08-01 11:57:06 +05:30
commit acd76079ba
2 changed files with 23 additions and 1 deletions

View File

@ -489,6 +489,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 vals.get('company_id'):
user_pool = self.pool.get('res.users')
for partner in self.browse(cr, uid, ids, context=context):
if partner.user_ids:
user_companies = set([user.company_id.id for user 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 multiple 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)

View File

@ -279,6 +279,13 @@ class res_users(osv.osv):
return result
def create(self, cr, uid, vals, context=None):
user_id = super(res_users, self).create(cr, uid, vals, context=context)
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):
if not hasattr(ids, '__iter__'):
ids = [ids]
@ -293,7 +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)
if 'company_id' in values:
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['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)