[FIX] res_currency: allow silent failing for computation of current rate if no rate exists, allow accessing the tree and form view if incorrectly configured currency
lp bug: https://launchpad.net/bugs/1174294 fixed bzr revid: mat@openerp.com-20130731145128-flzp1imkyrh86zpa
This commit is contained in:
commit
1a0c4dd407
|
@ -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)),
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="rate_ids" invisible="1"/>
|
||||
<field name="date"/>
|
||||
<field name="rate"/>
|
||||
<field name="rate_silent"/>
|
||||
<field name="rounding"/>
|
||||
<field name="accuracy"/>
|
||||
<field name="position"/>
|
||||
|
@ -37,7 +37,7 @@
|
|||
<form string="Currency" version="7.0">
|
||||
<group col="4">
|
||||
<field name="name"/>
|
||||
<field name="rate"/>
|
||||
<field name="rate_silent"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue