From 487c612f0ca45e48599b317b95acf19ba4f2dddd Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 12 Dec 2016 16:27:54 +0100 Subject: [PATCH] [FIX] web, orm: allow `0` as key for selection fields Before this revision, using a selection field with as possible keys `0`, such as `require_payment` in `website_quote`, resulted to the records field values to be stored as `NULL` instead of `0` in the database. This leads to the inability: - To distinguish records with this selection field not set or set to `0` (as both are stored as `NULL`) - To search for records with the field set to `0` (as they are considered not set) For instance, while having `website_quote` installed, search for sales orders with `Payment` set to `Not mandatory on website quote validation`: It won't return any result, even if you have some. opw-697454 --- addons/web/static/src/js/views/form_widgets.js | 3 ++- odoo/fields.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/form_widgets.js b/addons/web/static/src/js/views/form_widgets.js index 988a3f4d699..de98f633399 100644 --- a/addons/web/static/src/js/views/form_widgets.js +++ b/addons/web/static/src/js/views/form_widgets.js @@ -955,7 +955,8 @@ var FieldRadio = common.AbstractField.extend(common.ReinitializeFieldMixin, { }, get_value: function () { var value = this.get('value'); - return ((value instanceof Array)? value[0] : value) || false; + value = ((value instanceof Array)? value[0] : value); + return _.isUndefined(value) ? false : value; }, render_value: function () { var self = this; diff --git a/odoo/fields.py b/odoo/fields.py index 427b6c6aa02..2a73ca94daf 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -1744,6 +1744,14 @@ class Selection(Field): return item[1] return False + def convert_to_column(self, value, record): + """ Convert ``value`` from the ``write`` format to the SQL format. """ + if value is None or value is False: + return None + if isinstance(value, unicode): + return value.encode('utf8') + return str(value) + class Reference(Selection): type = 'reference'