In Odoo 16 CE I'm trying to store the res.company of the current user in the field company_id in a model in my custom module. Whenever the user created a new record of this model, the current company should be stored as well.
The way I'm trying to do this right now is this:
company_id = fields.Many2one('res.company', string="Company", default=lambda self: self.env['res.company'].search(['id', '=', self.env.user.company_id]))
I'm trying to get the res.company record of the corresponding company_id stored in the current user's company_id field. So, I get all the res.company records and search() to get the res.company record where the res_company.id and res_users.company_id match.
Am I approaching this the wrong way? Is there a simpler option? Please let me know.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kirjanpito
- Varastointi
- PoS
- Project
- MRP
Tämä kysymys on merkitty
2
Vastaukset
3082
Näkymät
Hi,
The more simpler method is :
company_id = fields.Many2one('res.company', string='Company', index=True, default=lambda self: self.env.company)
Regards
Thanks Cybrosys Techno Solutions Pvt.Ltd
If I could upvote or mark your reply as the best answer or simply reply to your answer... I would . But this dumb forum won't let me because I don't have enough karma...
Nautitko keskustelusta? Älä vain lue, vaan osallistu!
Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!
RekisteröidyAiheeseen liittyviä artikkeleita | Vastaukset | Näkymät | Toimenpide | |
---|---|---|---|---|
|
2
maalisk. 24
|
3288 | ||
|
1
elok. 23
|
3432 | ||
|
0
huhtik. 24
|
1090 | ||
|
0
maalisk. 23
|
2891 | ||
|
1
huhtik. 25
|
1395 |