From 05c907b60be23b5cfc463147a87fe2425cfecbdd Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 30 Jan 2015 15:00:21 +0100 Subject: [PATCH] [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. --- openerp/addons/base/res/res_currency.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/openerp/addons/base/res/res_currency.py b/openerp/addons/base/res/res_currency.py index dac5988b585..5a92eba01df 100644 --- a/openerp/addons/base/res/res_currency.py +++ b/openerp/addons/base/res/res_currency.py @@ -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: