コンテンツへスキップ
メニュー
この質問にフラグが付けられました

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

Walnut Software Solutions

アバター
破棄
著作者

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

アバター
破棄
関連投稿 返信 ビュー 活動
3
11月 24
4582
1
10月 23
2174
2
7月 23
3953
2
7月 24
2921
3
12月 23
3506