in a model i defined a company_id this way:
company_id = fields.Many2one(
default=lambda self: self.env.user.company_id
In a new document edit form the company id is correctly selected, but when I click on "company id" selection, I get this error:
Uncaught Error: AttributeError: object has no attribute 'company_id'
The "self" object appears to be empty, when logged.
I copied the definition of company_id from one of many core or OCA modules that uses it.
Does it rely on context?
And how could I get the id of the current user and is company_id?
Try like this:
default=lambda self: self.env['res.company']._company_default_get('your.module')
probably correct code is slightly different, see https://github.com/odoo/odoo/issues/10906
default=lambda self: self.env['res.company'].browse(self.env['res.company']._company_default_get('your.module'))
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
|Asked: 12/1/15, 9:10 AM|
|Seen: 3264 times|
|Last updated: 10/14/16, 4:12 PM|