Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
4200 Zobrazení

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

Avatar
Zrušit
Nejlepší odpověď

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

Walnut Software Solutions

Avatar
Zrušit
Autor

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

Nejlepší odpověď

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

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
lis 24
4395
1
říj 23
2093
2
čvc 23
3775
2
čvc 24
2831
3
pro 23
3385