Monetary fields
Monetary fields are mainly used for storing the amount in a certain currency. Odoo
provides a dedicated feature for monetary values associated with a currency.
All amount fields are monetary fields or float fields with monetary widget.
Let’s check how to create a monetary field
First create a python file and add the following code
from odoo import api, fields, models
class FeeInherit(models.Model):
_inherit = "hr.employee"
company_id = fields.Many2one('res.company', store=True, copy=False,
string="Company",
default=lambda self: self.env.user.company_id.id)
currency_id = fields.Many2one('res.currency', string="Currency",
related='company_id.currency_id',
default=lambda
self: self.env.user.company_id.currency_id.id)
fee = fields.Monetary(string="Fee")
In this code, we set the current company currency as the default currency.
Next, add an XML file to shows the field on the user interface.
<form>
<sheet>
<group>
<group>
<field name="currency_id" invisible="1"/>
<field name="fee"/>
</group>
</group>
</sheet>
</form>
We can set the fee field as a float field and in the XML file give a widget for fee field
as a monetary.
<field name="fee" widget="monetary"/>
We can see that on the user interface.