diff --git a/openerp/addons/base/res/res_currency.py b/openerp/addons/base/res/res_currency.py index 4756cdbe01a..dac5988b585 100644 --- a/openerp/addons/base/res/res_currency.py +++ b/openerp/addons/base/res/res_currency.py @@ -31,6 +31,12 @@ CURRENCY_DISPLAY_PATTERN = re.compile(r'(\w+)\s*(?:\((.*)\))?') class res_currency(osv.osv): def _current_rate(self, cr, uid, ids, name, arg, context=None): + return self._current_rate_computation(cr, uid, ids, name, arg, True, context=context) + + def _current_rate_silent(self, cr, uid, ids, name, arg, context=None): + return self._current_rate_computation(cr, uid, ids, name, arg, False, context=context) + + def _current_rate_computation(self, cr, uid, ids, name, arg, raise_on_no_rate, context=None): if context is None: context = {} res = {} @@ -48,9 +54,12 @@ class res_currency(osv.osv): if cr.rowcount: id, rate = cr.fetchall()[0] res[id] = rate + elif not raise_on_no_rate: + res[id] = 0 else: raise osv.except_osv(_('Error!'),_("No currency rate associated for currency %d for the given period" % (id))) return res + _name = "res.currency" _description = "Currency" _columns = { @@ -59,6 +68,10 @@ class res_currency(osv.osv): 'symbol': fields.char('Symbol', size=4, help="Currency sign, to be used when printing amounts."), 'rate': fields.function(_current_rate, string='Current Rate', digits=(12,6), help='The rate of the currency to the currency of rate 1.'), + + # Do not use for computation ! Same as rate field with silent failing + 'rate_silent': fields.function(_current_rate_silent, string='Current Rate', digits=(12,6), + help='The rate of the currency to the currency of rate 1 (0 if no rate defined).'), 'rate_ids': fields.one2many('res.currency.rate', 'currency_id', 'Rates'), 'accuracy': fields.integer('Computational Accuracy'), 'rounding': fields.float('Rounding Factor', digits=(12,6)), diff --git a/openerp/addons/base/res/res_currency_view.xml b/openerp/addons/base/res/res_currency_view.xml index 907eec866fb..c74b677ea72 100644 --- a/openerp/addons/base/res/res_currency_view.xml +++ b/openerp/addons/base/res/res_currency_view.xml @@ -22,7 +22,7 @@ - + @@ -37,7 +37,7 @@
- + diff --git a/openerp/tests/test_acl.py b/openerp/tests/test_acl.py index 1d8d6bfb22a..9f9019e5db9 100644 --- a/openerp/tests/test_acl.py +++ b/openerp/tests/test_acl.py @@ -29,18 +29,18 @@ class TestACL(common.TransactionCase): view_arch = etree.fromstring(form_view.get('arch')) has_tech_feat = self.res_users.has_group(self.cr, self.demo_uid, GROUP_TECHNICAL_FEATURES) self.assertFalse(has_tech_feat, "`demo` user should not belong to the restricted group before the test") - self.assertTrue('rate' in original_fields, "'rate' field must be properly visible before the test") - self.assertNotEquals(view_arch.xpath("//field[@name='rate']"), [], - "Field 'rate' must be found in view definition before the test") + self.assertTrue('accuracy' in original_fields, "'accuracy' field must be properly visible before the test") + self.assertNotEquals(view_arch.xpath("//field[@name='accuracy']"), [], + "Field 'accuracy' must be found in view definition before the test") # Restrict access to the field and check it's gone - self.res_currency._columns['rate'].groups = GROUP_TECHNICAL_FEATURES + self.res_currency._columns['accuracy'].groups = GROUP_TECHNICAL_FEATURES fields = self.res_currency.fields_get(self.cr, self.demo_uid, []) form_view = self.res_currency.fields_view_get(self.cr, self.demo_uid, False, 'form') view_arch = etree.fromstring(form_view.get('arch')) - self.assertFalse('rate' in fields, "'rate' field should be gone") - self.assertEquals(view_arch.xpath("//field[@name='rate']"), [], - "Field 'rate' must not be found in view definition") + self.assertFalse('accuracy' in fields, "'accuracy' field should be gone") + self.assertEquals(view_arch.xpath("//field[@name='accuracy']"), [], + "Field 'accuracy' must not be found in view definition") # Make demo user a member of the restricted group and check that the field is back self.tech_group.write({'users': [(4, self.demo_uid)]}) @@ -50,13 +50,13 @@ class TestACL(common.TransactionCase): view_arch = etree.fromstring(form_view.get('arch')) #import pprint; pprint.pprint(fields); pprint.pprint(form_view) self.assertTrue(has_tech_feat, "`demo` user should now belong to the restricted group") - self.assertTrue('rate' in fields, "'rate' field must be properly visible again") - self.assertNotEquals(view_arch.xpath("//field[@name='rate']"), [], - "Field 'rate' must be found in view definition again") + self.assertTrue('accuracy' in fields, "'accuracy' field must be properly visible again") + self.assertNotEquals(view_arch.xpath("//field[@name='accuracy']"), [], + "Field 'accuracy' must be found in view definition again") #cleanup self.tech_group.write({'users': [(3, self.demo_uid)]}) - self.res_currency._columns['rate'].groups = False + self.res_currency._columns['accuracy'].groups = False @mute_logger('openerp.osv.orm') def test_field_crud_restriction(self):