[FIX] fields: implement _description_digits
Otherwise, fields_get returns the string, not the digits Add test
This commit is contained in:
@@ -45,5 +45,11 @@
|
||||
<record id="bool_4" model="domain.bool">
|
||||
<field name="bool_undefined" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record id="decimal_new_api_number" model="decimal.precision">
|
||||
<field name="name">New API Precision</field>
|
||||
<field name="digits" eval="3"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -284,6 +284,7 @@ class MixedModel(models.Model):
|
||||
_description = 'Test New API Mixed'
|
||||
|
||||
number = fields.Float(digits=(10, 2), default=3.14)
|
||||
number2 = fields.Float(digits='New API Precision')
|
||||
date = fields.Date()
|
||||
now = fields.Datetime(compute='_compute_now')
|
||||
lang = fields.Selection(string='Language', selection='_get_lang')
|
||||
|
||||
@@ -443,6 +443,12 @@ class TestFields(common.TransactionCase):
|
||||
record.number = 2.4999999999999996
|
||||
self.assertEqual(record.number, 2.50)
|
||||
|
||||
def test_21_float_digits(self):
|
||||
""" test field description """
|
||||
precision = self.env.ref('test_new_api.decimal_new_api_number')
|
||||
description = self.env['test_new_api.mixed'].fields_get()['number2']
|
||||
self.assertEqual(description['digits'], (16, precision.digits))
|
||||
|
||||
def check_monetary(self, record, amount, currency, msg=None):
|
||||
# determine the possible roundings of amount
|
||||
if currency:
|
||||
|
||||
+3
-1
@@ -1290,7 +1290,9 @@ class Float(Field):
|
||||
return self._digits
|
||||
|
||||
_related__digits = property(attrgetter('_digits'))
|
||||
_description_digits = property(attrgetter('_digits'))
|
||||
|
||||
def _description_digits(self, env):
|
||||
return self.get_digits(env)
|
||||
|
||||
def convert_to_column(self, value, record, values=None, validate=True):
|
||||
result = float(value or 0.0)
|
||||
|
||||
Reference in New Issue
Block a user