Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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'))
About This Community
This platform 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 12/1/15, 9:10 AM|
|Seen: 4814 times|
|Last updated: 10/14/16, 4:12 PM|