Skip to content

Commit

Permalink
[IMP] base: Forbid users from setting currency rate as 0 or less
Browse files Browse the repository at this point in the history
   Because it doesn't have any meaning to do so. Also the default value for rate is now set to 1 instead of 0
  • Loading branch information
qdp-odoo committed Dec 4, 2017
1 parent 028573c commit 2984915
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion odoo/addons/base/models/res_currency.py
Expand Up @@ -222,13 +222,14 @@ 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), help='The rate of the currency to the currency of rate 1')
rate = fields.Float(digits=(12, 6), 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.user.company_id)

_sql_constraints = [
('unique_name_per_day', 'unique (name,currency_id,company_id)', 'Only one currency rate per day allowed!'),
('currency_rate_check', 'CHECK (rate>0)', 'The currency rate must be strictly positive.'),
]

@api.model
Expand Down
7 changes: 5 additions & 2 deletions odoo/addons/base/tests/test_float.py
Expand Up @@ -160,9 +160,12 @@ def try_roundtrip(value, expected, date):

# res.currency.rate uses 6 digits of precision by default
try_roundtrip(2.6748955, 2.674896, '2000-01-01')
try_roundtrip(-2.6748955, -2.674896, '2000-01-02')
try_roundtrip(10000.999999, 10000.999999, '2000-01-03')
try_roundtrip(-10000.999999, -10000.999999, '2000-01-04')

#TODO re-enable those tests when tests are made on dedicated models
# (res.currency.rate don't accept negative value anymore)
#try_roundtrip(-2.6748955, -2.674896, '2000-01-02')
#try_roundtrip(-10000.999999, -10000.999999, '2000-01-04')

def test_float_split_05(self):
""" Test split method with 2 digits. """
Expand Down

0 comments on commit 2984915

Please sign in to comment.