From a804d9a70f4288cde4d08d6dc0970a2b0c495b6a Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 30 Jan 2015 13:39:02 +0100 Subject: [PATCH 1/2] [FIX] web: possibility to autocomplete 'No' for boolean fields In the search bar. Besides, if the label value of the selection field is set to False, which is quite dummy but accepted The autocomplete crashed. --- addons/web/static/src/js/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index d2db5b55213..3ac03cf4052 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -1453,7 +1453,7 @@ instance.web.search.SelectionField = instance.web.search.Field.extend(/** @lends var results = _(this.attrs.selection).chain() .filter(function (sel) { var value = sel[0], label = sel[1]; - if (!value) { return false; } + if (value === undefined || !label) { return false; } return label.toLowerCase().indexOf(needle.toLowerCase()) !== -1; }) .map(function (sel) { From 05c907b60be23b5cfc463147a87fe2425cfecbdd Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 30 Jan 2015 15:00:21 +0100 Subject: [PATCH 2/2] [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: