
Learn how to use the monetary field and widget in Odoo to manage and display currency values accurately, supporting localization and multi-currency.
In Odoo, managing currency-related fields requires specialized handling, especially when displaying prices, amounts, or other monetary values. The Monetary Field and widget="monetary" provide the perfect solution to format and display currency values effectively. These features offer localization and multi-currency support, enhancing the financial management capabilities in Odoo.
A monetary field in Odoo is a type of field designed to hold currency values. It is similar to a float field but includes additional currency support to format values properly. This field works in conjunction with a currency field to show the appropriate currency symbol or format based on the selected currency.
To create a monetary field in a model, specify the field type as fields.Monetary in Python and add a currency field to manage the currency symbol.
Here is a code example to add a monetary field for prices:
<from odoo import models, fields>
class ProductTemplate(models.Model):
_name = 'product.template'
price = fields.Monetary(string="Price", currency_field="currency_id")
currency_id = fields.Many2one('res.currency', string="Currency")
Explanation:
To display monetary fields in Odoo’s views, use the widget="monetary" attribute in the XML view definition. This widget enables Odoo to properly format the amount based on the selected currency and locale.
Here is an example of using the monetary widget in a form view:
<record id="view_product_template_form" model="ir.ui.view">
<field name="name">product.template.form</field>
<field name="model">product.template</field>
<field name="arch" type="xml">
<form string="Product">
<field name="name"/>
<field name="price" widget="monetary" options="{'currency_field': 'currency_id'}"/>
<field name="currency_id"/>
</form>
</field>
</record>
Explanation:
The monetary widget in Odoo offers various benefits:
Some common scenarios where the monetary field and widget are useful include:
The monetary field and monetary widget in Odoo are essential for handling currency values accurately. By using these features, users can efficiently manage and display financial data with correct formatting, supporting both local and multi-currency requirements. With Odoo’s powerful currency management, managing monetary data becomes seamless and intuitive.
Your email address will not be published. Required fields are marked *