[IMP] base/web: store more precision digits for rate field
Currently, only 6 digits after decimal point is stored in database and for some currencies it may require to have more digits after decimal precision to correctly convert rates, like MXN -> USD currency. So, we allow maximum digits to be stored in database. On the view side, wherever rate is editable(form or tree view), we show 12 digits after decimal point and on list view, we truncate limit it to 6 digits. Also, a bug is fixed for web where 'digits' attribute for float field on list view isn't considered. Also, we have to remove a test case statement which only checks for 6 digits for a float number. task: 2024668 closes: #34279 Signed-off-by: Josse Colpaert <jco@openerp.com>
This commit is contained in:
@@ -405,6 +405,7 @@ var ListRenderer = BasicRenderer.extend({
|
||||
data: record.data,
|
||||
escape: true,
|
||||
isPassword: 'password' in node.attrs,
|
||||
digits: node.attrs.digits && JSON.parse(node.attrs.digits),
|
||||
});
|
||||
this._handleAttributes($td, node);
|
||||
var title = field.type !== 'boolean' ? formattedValue : '';
|
||||
|
||||
@@ -6670,6 +6670,19 @@ QUnit.module('Views', {
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('float field render with digits attribute on listview', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var list = await createView({
|
||||
View: ListView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
arch: '<tree><field name="foo"/><field name="qux" digits="[12,6]"/></tree>',
|
||||
});
|
||||
|
||||
assert.strictEqual(list.$('td.o_list_number:eq(0)').text(), "0.400000", "should contain 6 digits decimal precision");
|
||||
list.destroy();
|
||||
});
|
||||
// TODO: write test on:
|
||||
// - default_get with a field not in view
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ class Currency(models.Model):
|
||||
# Note: 'code' column was removed as of v6.0, the 'name' should now hold the ISO code.
|
||||
name = fields.Char(string='Currency', size=3, required=True, help="Currency Code (ISO 4217)")
|
||||
symbol = fields.Char(help="Currency sign, to be used when printing amounts.", required=True)
|
||||
rate = fields.Float(compute='_compute_current_rate', string='Current Rate', digits=(12, 6),
|
||||
rate = fields.Float(compute='_compute_current_rate', string='Current Rate', digits=0,
|
||||
help='The rate of the currency to the currency of rate 1.')
|
||||
rate_ids = fields.One2many('res.currency.rate', 'currency_id', string='Rates')
|
||||
rounding = fields.Float(string='Rounding Factor', digits=(12, 6), default=0.01)
|
||||
@@ -235,7 +235,7 @@ class CurrencyRate(models.Model):
|
||||
|
||||
name = fields.Date(string='Date', required=True, index=True,
|
||||
default=lambda self: fields.Date.today())
|
||||
rate = fields.Float(digits=(12, 6), default=1.0, help='The rate of the currency to the currency of rate 1')
|
||||
rate = fields.Float(digits=0, default=1.0, help='The rate of the currency to the currency of rate 1')
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', readonly=True)
|
||||
company_id = fields.Many2one('res.company', string='Company',
|
||||
default=lambda self: self.env.company)
|
||||
|
||||
@@ -172,8 +172,7 @@ class TestFloatPrecision(TransactionCase):
|
||||
self.assertEqual(rate.rate, expected,
|
||||
'Roundtrip error: got %s back from db, expected %s' % (rate, expected))
|
||||
|
||||
# res.currency.rate uses 6 digits of precision by default
|
||||
try_roundtrip(2.6748955, 2.674896, '2000-01-01')
|
||||
# res.currency.rate no more uses 6 digits of precision by default, it now uses whatever precision it gets
|
||||
try_roundtrip(10000.999999, 10000.999999, '2000-01-03')
|
||||
|
||||
#TODO re-enable those tests when tests are made on dedicated models
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Currency Rates" editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="rate"/>
|
||||
<field name="rate" digits="[12,12]"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</tree>
|
||||
</field>
|
||||
@@ -32,7 +32,7 @@
|
||||
<group>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="rate"/>
|
||||
<field name="rate" digits="[12,12]"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="currency_id"/>
|
||||
@@ -75,7 +75,7 @@
|
||||
<field name="symbol"/>
|
||||
<field name="rate_ids" invisible="1"/>
|
||||
<field name="date"/>
|
||||
<field name="rate"/>
|
||||
<field name="rate" digits="[12,6]"/>
|
||||
<field name="active" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
@@ -102,7 +102,7 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<strong><span>Current Rate: </span></strong>
|
||||
<field name="rate"/>
|
||||
<field name="rate" digits="[12,6]"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -125,7 +125,7 @@
|
||||
<group>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="rate"/>
|
||||
<field name="rate" digits="[12,12]"/>
|
||||
<field name="active"/>
|
||||
</group>
|
||||
<group>
|
||||
|
||||
Reference in New Issue
Block a user