[FIX] res: currency, rates name_search
In currencies, advanced search with "equals" or "not equals" on rates was not possible for something else than a date, in server format (crash). This is because the name field of the model res.currency.rate is a date This is now possible to search rates with just a float and the equal operators, it returns currencies which are having at least one rate set to this float value This is also possible to search rates with the equal operators with a date in user (context) date format.
This commit is contained in:
parent
a804d9a70f
commit
05c907b60b
|
@ -259,6 +259,25 @@ class res_currency_rate(osv.osv):
|
|||
}
|
||||
_order = "name desc"
|
||||
|
||||
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
|
||||
if operator in ['=', '!=']:
|
||||
try:
|
||||
date_format = '%Y-%m-%d'
|
||||
if context.get('lang'):
|
||||
lang_obj = self.pool['res.lang']
|
||||
lang_ids = lang_obj.search(cr, user, [('code', '=', context['lang'])], context=context)
|
||||
if lang_ids:
|
||||
date_format = lang_obj.browse(cr, user, lang_ids[0], context=context).date_format
|
||||
name = time.strftime('%Y-%m-%d', time.strptime(name, date_format))
|
||||
except ValueError:
|
||||
try:
|
||||
args.append(('rate', operator, float(name)))
|
||||
except ValueError:
|
||||
return []
|
||||
name = ''
|
||||
operator = 'ilike'
|
||||
return super(res_currency_rate, self).name_search(cr, user, name, args=args, operator=operator, context=context, limit=limit)
|
||||
|
||||
res_currency_rate()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue