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:

  1. 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:

  1. 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.
  2. 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.
  3. Add a new configuration, setting Usage to Book Price and choosing the Digits precision:
  1. Add the new dependency to the __manifest__.py manifest file. It should look as follows:
{   'name': 'Chapter 05 code', 
    'depends': ['base', 'decimal_precision'], 
    'data': ['views/library_book.xml'] } 
  1. To add the model field using this decimal precision setting, edit the models/library_book.py file by adding the following code:
from odoo.addons import decimal_precision as dp 
class LibraryBook(models.Model): 
    cost_price = fields.Float( 
        'Book Cost', dp.get_precision('Book Price'))
Whenever you add new fields in models, you will need to add them into views in order to access them from the user interface. In the previous example, we added the cost_price field. To see this in the form view, you need to add it with
<field name="cost_price"/>.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset