- Odoo 11 Development Cookbook(Second Edition)
- Holger Brunn Alexandre Fayolle
- 204字
- 2021-06-25 22:48:47
How to do it...
We need to install the decimal_precision module, add a "Usage" entry for our configuration, and then use it in the model field:
- Ensure that the Decimal Accuracy module is installed; select Apps from the top menu, remove the default filter, search for the Decimal Precision Configuration app, and install it if it's not already installed:
- Activate Developer Mode from the link in the Settings menu (refer to the Activating the Odoo developer tools recipe in Chapter 1, Installing the Odoo Development Environment). This will enable the Settings | Technical menu.
- Access the Decimal Precision configurations. To do this, open the Settings top menu and select Technical | Database Structure | Decimal Accuracy. We should see a list of the currently defined settings.
- Add a new configuration, setting Usage to Book Price and choosing the Digits precision:
- Add the new dependency to the __manifest__.py manifest file. It should be similar to this:
{ 'name': 'Chapter 05 code', 'depends': ['base', 'decimal_precision], 'data': ['views/library_book.xml'] }
- To add the model field using this decimal precision setting, edit the models/library_book.py file by adding the following:
from odoo.addons import decimal_precision as dp # ... class LibraryBook(models.Model): # ... cost_price = fields.Float( 'Book Cost', dp.get_precision('Book Price))