Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4317 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 11 24
4570
1
thg 10 23
2165
2
thg 7 23
3934
2
thg 7 24
2914
3
thg 12 23
3470