Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

res_users compnay_ids

By
Zouhair
on 9/12/14, 3:15 AM 1,028 views

hi,

where can i found this field, company_ids, is an array, in table res_users not exist.

thx

1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 9/12/14, 3:48 AM

In Base Module base/res/res_users.py file company_ids added.

company_ids is many2many field in DB it create res_company_users_rel table.

The message shows from the write method base/res/res_partner.py File.

At the time of creating or updating user check the below conditon

        # 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)
 

  @api.multi
    def write(self, vals):
        if vals.get('website'):
            vals['website'] = self._clean_website(vals['website'])
        if vals.get('company_id'):
            company = self.env['res.company'].browse(vals['company_id'])
            for partner in self:
                if partner.user_ids:
                    companies = set(user.company_id for user in partner.user_ids)
                    if len(companies) > 1 or company not in 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(vals)
        for partner in self:
            self._fields_sync(partner, vals)
        return result

1
Daniele Lanfranchi
On 9/12/14, 3:42 AM

Hello Zouhair, the field is not present on res_users table but it's contained in 'res_company_users_rel' 

CREATE TABLE res_company_users_rel
(
  cid integer NOT NULL,
  user_id integer NOT NULL,
  CONSTRAINT res_company_users_rel_cid_fkey FOREIGN KEY (cid)
      REFERENCES res_company (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE,
  CONSTRAINT res_company_users_rel_user_id_fkey FOREIGN KEY (user_id)
      REFERENCES res_users (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE,
  CONSTRAINT res_company_users_rel_cid_user_id_key UNIQUE (cid , user_id )
)

 

In addons/base/res/res_users.py (OpenERP v7)

_columns = { 

....

'company_ids':fields.many2many('res.company','res_company_users_rel','user_id','cid','Companies'),

...

}

0
Zouhair
On 9/12/14, 3:56 AM

hello,

thank you Prakash ,Daniele Lanfranchi for ur help, i want to create a new user into new company by odoo api, but i can do it, i give this msg error

You can not change the company as the partner/user has multiple user linked with different companies.

any one can help me

thx in advance

I updated my answer

Prakash
on 9/12/14, 5:11 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/12/14, 3:15 AM
Seen: 1028 times
Last updated: 3/16/15, 8:10 AM