简体   繁体   中英

How to set domain for curency_id field in odoo?

I have an entity with 2 fields payment (manetary) and its currency. The currency_id field in the view displays a list of all possible currencies. How can I set domain to the curency_id field so the user only will be able to select two possible currencies? In this case the options would be: US Dollar (USD) and Dominican Peso (DOP)

payment = fields.Monetary(string='Payment',currency_field='currency_id') currency_id = fields.Many2one('res.currency', string='Currency', required=True)

And in the view:
<field name="payment"/>
<field name="currency_id"/>

You need to add domain on currency_id field. Name field available on res.currency object to find desire currency.

Try with following code:

currency_id = fields.Many2one(
    'res.currency', 
    string='Currency', 
    required=True, 
    domain=[('name', 'in', ('USD', 'DOP'))])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM