[FIX] fix demo data problem, now able to assign company to existing partner which...
authorRifakat <rha@tinyerp.com>
Thu, 1 Aug 2013 06:27:06 +0000 (11:57 +0530)
committerRifakat <rha@tinyerp.com>
Thu, 1 Aug 2013 06:27:06 +0000 (11:57 +0530)
any company. Did small variable name change

bzr revid: rha@tinyerp.com-20130801062706-imbu9ac2nimbd28f

1  2 
openerp/addons/base/res/res_partner.py
openerp/addons/base/res/res_users.py

@@@ -489,6 -489,16 +489,17 @@@ class res_partner(osv.osv, format_addre
      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):
 -                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."))
++                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)
@@@ -293,7 -300,11 +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.get('company_id'): 
++                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)