I'm trying to create
currency_id : many2one field on res.currency model this is the code:
currency_id=fields.Many2one('res.currency')How can i make it take company currency by default.(readonly)?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I'm trying to create
currency_id : many2one field on res.currency model this is the code:
currency_id=fields.Many2one('res.currency')How can i make it take company currency by default.(readonly)?
Hi,
You can achieve it easily as follows:
currency_id = fields.Many2one('res.currency', default=lambda self: self.env.company.currency_id, readonly=True)
Thanks & Regards
What is company ?
is a model?
company is actually the model of 'res.company', but it is made to be a special instance for this purpose
read more at https://www.odoo.com/documentation/15.0/developer/reference/backend/orm.html#environment
Hello,
In Odoo, you can access the current company object by calling ".company" from the "env" object. For example, "self.env.company" will return the current company. The company object has a field called "currency_id" which contains the default currency ID.
To select the default company in a field, you can use a lambda function. Here's an example:
currency_id = fields.Many2one('res.currency', default=lambda self: self.env.company.currency_id, readonly=True)Regards
Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !
S'inscrire| Publications associées | Réponses | Vues | Activité | |
|---|---|---|---|---|
|
3
nov. 24
|
5468 | |||
|
1
oct. 23
|
2733 | |||
|
2
juil. 23
|
5013 | |||
|
2
juil. 24
|
3528 | |||
|
3
déc. 23
|
4625 |
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.