From cbe5d731647a968169f5055f03a10ce90a028af8 Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Fri, 27 Mar 2015 14:24:07 +0100 Subject: [PATCH 01/11] Add an option to m2x_options to force enable/disable search more button --- web_m2x_options/static/src/js/form.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index e4540567..0975a069 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -60,6 +60,11 @@ openerp.web_m2x_options = function (instance) { if (typeof this.options.limit === 'number') { this.limit = this.options.limit; } + + // add options search_more to force enable or disable search_more button + if(typeof this.options.search_more === 'boolean') { + this.search_more = this.options.search_more + } var dataset = new instance.web.DataSet(this, this.field.relation, self.build_context()); @@ -100,7 +105,7 @@ openerp.web_m2x_options = function (instance) { // search more... if more results than max - if (values.length > self.limit) { + if (values.length > self.limit || self.search_more) { values = values.slice(0, self.limit); values.push({ label: _t("Search More..."), From 014542a91dc8ef32427e57488f1b4085670326e8 Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Mon, 30 Mar 2015 15:55:16 +0200 Subject: [PATCH 02/11] Add options to colors many2x field depending on specified field --- web_m2x_options/static/src/js/form.js | 39 +++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index 0975a069..30b09b30 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -12,7 +12,7 @@ openerp.web_m2x_options = function (instance) { 'web_m2x_options.create_edit', 'web_m2x_options.limit',]; - instance.web.form.FieldMany2One.include({ + instance.web.form.FieldMany2One = instance.web.form.FieldMany2One.extend({ start: function() { this._super.apply(this, arguments); @@ -45,7 +45,7 @@ openerp.web_m2x_options = function (instance) { }, get_search_result: function (search_val) { - + var Objects = new instance.web.Model(this.field.relation); var def = $.Deferred(); var self = this; // add options limit used to change number of selections record @@ -65,7 +65,11 @@ openerp.web_m2x_options = function (instance) { if(typeof this.options.search_more === 'boolean') { this.search_more = this.options.search_more } - + + // add options field_color and colors to color item(s) depending on field_color value + this.field_color = this.options.field_color + this.colors = this.options.colors + var dataset = new instance.web.DataSet(this, this.field.relation, self.build_context()); var blacklist = this.get_search_blacklist(); @@ -102,6 +106,28 @@ openerp.web_m2x_options = function (instance) { id: x[0], }; }); + + // Search result value colors + + if (self.colors && self.field_color) { + var value_ids = []; + for (var index in values) { + value_ids.push(values[index].id); + } + + // RPC request to get field_color from Objects + Objects.query([self.field_color]) + .filter([['id', 'in', value_ids]]) + .all().done(function (objects) { + console.log(objects); + for (var index in objects) { + var value = values[index]; + var color = self.colors[objects[index].state] || 'black'; + value.label = ''+value.label+''; + } + def.resolve(values); + }); + } // search more... if more results than max @@ -162,8 +188,11 @@ openerp.web_m2x_options = function (instance) { classname: 'oe_m2o_dropdown_option' }); } - - def.resolve(values); + + // Check if colors specified to wait for RPC + if (!(self.field_color && self.colors)){ + def.resolve(values); + } }); return def; From 3df84555c97015f9a25d69d5815b1dabded2c7d7 Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Mon, 30 Mar 2015 16:06:24 +0200 Subject: [PATCH 03/11] Remove hardcoded state to use option "field_color" and some logs --- web_m2x_options/static/src/js/form.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index 30b09b30..fcdf7608 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -119,10 +119,10 @@ openerp.web_m2x_options = function (instance) { Objects.query([self.field_color]) .filter([['id', 'in', value_ids]]) .all().done(function (objects) { - console.log(objects); for (var index in objects) { var value = values[index]; - var color = self.colors[objects[index].state] || 'black'; + // Find color with field value as key + var color = self.colors[objects[index][self.field_color]] || 'black'; value.label = ''+value.label+''; } def.resolve(values); From 77b84341d88d32b9a0f3a9556174465c923adcac Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Mon, 30 Mar 2015 16:38:18 +0200 Subject: [PATCH 04/11] Fix issue when query result not in the same order as values --- web_m2x_options/static/src/js/form.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index fcdf7608..f5823623 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -120,10 +120,17 @@ openerp.web_m2x_options = function (instance) { .filter([['id', 'in', value_ids]]) .all().done(function (objects) { for (var index in objects) { - var value = values[index]; - // Find color with field value as key - var color = self.colors[objects[index][self.field_color]] || 'black'; - value.label = ''+value.label+''; + for (var index_value in values) { + if (values[index_value].id == objects[index].id) { + // Find value in values by comparing ids + var value = values[index_value]; + + // Find color with field value as key + var color = self.colors[objects[index][self.field_color]] || 'black'; + value.label = ''+value.label+''; + break; + } + } } def.resolve(values); }); From 328f9736ee9242b3de3ce7b630ad781f4138d950 Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Tue, 31 Mar 2015 12:00:46 +0200 Subject: [PATCH 05/11] Add new options to README --- web_m2x_options/README.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/web_m2x_options/README.rst b/web_m2x_options/README.rst index ef7d2841..b9768549 100644 --- a/web_m2x_options/README.rst +++ b/web_m2x_options/README.rst @@ -46,6 +46,18 @@ New option ``limit`` *int* (Default: openerp default value is ``7``) Number of displayed record in drop-down panel + +``field_color`` *string* + + A string to define the field used to define color. + This option has to be used with colors. + +``colors`` *dictionary* + + A dictionary to link field value with a HTML color. + This option has to be used with field_color. + + ir.config_parameter options @@ -79,7 +91,7 @@ Example Your XML form view definition could contain:: ... - + ... Note From ad2e3412fe611eedfc3c10f99dff45474e923955 Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Tue, 31 Mar 2015 15:47:01 +0200 Subject: [PATCH 06/11] Improved description in module manifest and in README --- web_m2x_options/README.rst | 6 +++++- web_m2x_options/__openerp__.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/web_m2x_options/README.rst b/web_m2x_options/README.rst index b9768549..d4704dec 100644 --- a/web_m2x_options/README.rst +++ b/web_m2x_options/README.rst @@ -46,6 +46,10 @@ New option ``limit`` *int* (Default: openerp default value is ``7``) Number of displayed record in drop-down panel + +``search_more`` *boolean* + + Used to force disable/enable search more button. ``field_color`` *string* @@ -91,7 +95,7 @@ Example Your XML form view definition could contain:: ... - + ... Note diff --git a/web_m2x_options/__openerp__.py b/web_m2x_options/__openerp__.py index 22c05935..867ca47d 100644 --- a/web_m2x_options/__openerp__.py +++ b/web_m2x_options/__openerp__.py @@ -12,12 +12,16 @@ Add new options for many2one and many2manytags field: - create_edit: true/false -> disable "create and edit" entry in dropdown panel - limit: 10 (int) -> change number of selected record return in dropdown panel - m2o_dialog: true/false -> disable quick create M20Dialog triggered on error. +- search_more: true/false -> force disable/enable search more button. +- field_color -> define the field used to define color. +- colors -> link field values to a HTML color. + Example: -------- ```` +'create_edit': false, 'field_color':'state', colors:{'active':'green'}}"/>`` Note: ----- From fd41bc484daef89e80e9ebbb3e981ff6aeb64b32 Mon Sep 17 00:00:00 2001 From: ecino Date: Fri, 17 Apr 2015 13:26:53 +0200 Subject: [PATCH 07/11] Correct typo in example --- web_m2x_options/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_m2x_options/__openerp__.py b/web_m2x_options/__openerp__.py index 867ca47d..6192a784 100644 --- a/web_m2x_options/__openerp__.py +++ b/web_m2x_options/__openerp__.py @@ -21,7 +21,7 @@ Example: -------- ```` +'create_edit': false, 'field_color':'state', 'colors':{'active':'green'}}"/>`` Note: ----- From ea18922466aab63081e1faaad09f7f685edca3be Mon Sep 17 00:00:00 2001 From: ecino Date: Fri, 17 Apr 2015 14:08:57 +0200 Subject: [PATCH 08/11] Add help in README how to set default value for search_more option. --- web_m2x_options/README.rst | 5 +++++ web_m2x_options/static/src/js/form.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/web_m2x_options/README.rst b/web_m2x_options/README.rst index d4704dec..0fa46e05 100644 --- a/web_m2x_options/README.rst +++ b/web_m2x_options/README.rst @@ -82,11 +82,16 @@ If you disable one option, you can enable it for particular field by setting "cr Number of displayed records in drop-down panel for all fields in the odoo instance +``web_m2x_options.search_more`` *boolean* (Default: default value is ``False``) + + Whether the field should always show "Search more..." entry or not. + To add these parameters go to Configuration -> Technical -> Parameters -> System Parameters and add new parameters like: - web_m2x_options.create: False - web_m2x_options.create_edit: False - web_m2x_options.limit: 10 +- web_m2x_options.search_more: True Example diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index f5823623..8459f25f 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -10,7 +10,8 @@ openerp.web_m2x_options = function (instance) { var OPTIONS = ['web_m2x_options.create', 'web_m2x_options.create_edit', - 'web_m2x_options.limit',]; + 'web_m2x_options.limit', + 'web_m2x_options.search_more',]; instance.web.form.FieldMany2One = instance.web.form.FieldMany2One.extend({ From da0d67ae8e44075f28c89b373bdf9c8b465bb1b6 Mon Sep 17 00:00:00 2001 From: ecino Date: Fri, 17 Apr 2015 14:58:55 +0200 Subject: [PATCH 09/11] Adujst search_more option to accept True or true values. --- web_m2x_options/static/src/js/form.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index 8459f25f..208e7e92 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -61,16 +61,18 @@ openerp.web_m2x_options = function (instance) { if (typeof this.options.limit === 'number') { this.limit = this.options.limit; } - + // add options search_more to force enable or disable search_more button - if(typeof this.options.search_more === 'boolean') { - this.search_more = this.options.search_more + var search_more_defined = !_.isUndefined(this.options.search_more) + if((search_more_defined && this.options.search_more.toLowerCase() === "true") || + !(search_more_defined && this.options.search_more.toLowerCase() === "false") && (self.view.ir_options['web_m2x_options.search_more'] === "True")) { + this.search_more = true } - + // add options field_color and colors to color item(s) depending on field_color value this.field_color = this.options.field_color this.colors = this.options.colors - + var dataset = new instance.web.DataSet(this, this.field.relation, self.build_context()); var blacklist = this.get_search_blacklist(); From df72269a7395961b3f5d02ae3f38af85875559b6 Mon Sep 17 00:00:00 2001 From: Emanuel Cino Date: Tue, 2 Jun 2015 14:23:13 +0200 Subject: [PATCH 10/11] Added option m2o_dialog in System parameters --- web_m2x_options/README.rst | 5 +++++ web_m2x_options/static/src/js/form.js | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/web_m2x_options/README.rst b/web_m2x_options/README.rst index 0fa46e05..d7200121 100644 --- a/web_m2x_options/README.rst +++ b/web_m2x_options/README.rst @@ -78,6 +78,10 @@ If you disable one option, you can enable it for particular field by setting "cr Whether to display "Create and Edit..." entry in dropdown panel for all fields in the odoo instance. +``web_m2x_options.m2o_dialog`` *boolean* (Default: depends if user have create rights) + + Whether to display the many2one dialog in case of validation error for all fields in the odoo instance. + ``web_m2x_options.limit`` *int* (Default: openerp default value is ``7``) Number of displayed records in drop-down panel for all fields in the odoo instance @@ -90,6 +94,7 @@ To add these parameters go to Configuration -> Technical -> Parameters -> System - web_m2x_options.create: False - web_m2x_options.create_edit: False +- web_m2x_options.m2o_dialog: False - web_m2x_options.limit: 10 - web_m2x_options.search_more: True diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index 208e7e92..d2fb48da 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -11,7 +11,8 @@ openerp.web_m2x_options = function (instance) { var OPTIONS = ['web_m2x_options.create', 'web_m2x_options.create_edit', 'web_m2x_options.limit', - 'web_m2x_options.search_more',]; + 'web_m2x_options.search_more', + 'web_m2x_options.m2o_dialog',]; instance.web.form.FieldMany2One = instance.web.form.FieldMany2One.extend({ @@ -39,8 +40,8 @@ openerp.web_m2x_options = function (instance) { }, show_error_displayer: function () { - if ((typeof this.options.m2o_dialog === 'undefined' && this.can_create) || - this.options.m2o_dialog) { + if (((typeof this.options.m2o_dialog === 'undefined' && this.can_create) || + this.options.m2o_dialog) && (!this.view.ir_options['web_m2x_options.search_more'] === "False")) { new instance.web.form.M2ODialog(this).open(); } }, From 05b0ec7c4b99a0be51fc1aff9e81b2ff6153df48 Mon Sep 17 00:00:00 2001 From: Emanuel Cino Date: Wed, 3 Jun 2015 11:21:06 +0200 Subject: [PATCH 11/11] Add function to lookup for options either set to true/false/True/False --- web_m2x_options/static/src/js/form.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index d2fb48da..b2e9819a 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -39,9 +39,24 @@ openerp.web_m2x_options = function (instance) { return $.when(); }, + is_option_set: function(option) { + if (_.isUndefined(option)) { + return false + } + var is_string = typeof option === 'string' + var is_bool = typeof option === 'boolean' + if (is_string) { + return option === 'true' || option === 'True' + } else if (is_bool) { + return option + } + return false + }, + show_error_displayer: function () { - if (((typeof this.options.m2o_dialog === 'undefined' && this.can_create) || - this.options.m2o_dialog) && (!this.view.ir_options['web_m2x_options.search_more'] === "False")) { + if(this.is_option_set(this.options.m2o_dialog) || + _.isUndefined(this.options.m2o_dialog) && this.is_option_set(this.view.ir_options['web_m2x_options.m2o_dialog']) || + this.can_create && _.isUndefined(this.options.m2o_dialog) && _.isUndefined(this.view.ir_options['web_m2x_options.m2o_dialog'])) { new instance.web.form.M2ODialog(this).open(); } }, @@ -64,9 +79,7 @@ openerp.web_m2x_options = function (instance) { } // add options search_more to force enable or disable search_more button - var search_more_defined = !_.isUndefined(this.options.search_more) - if((search_more_defined && this.options.search_more.toLowerCase() === "true") || - !(search_more_defined && this.options.search_more.toLowerCase() === "false") && (self.view.ir_options['web_m2x_options.search_more'] === "True")) { + if (this.is_option_set(this.options.search_more) || _.isUndefined(this.options.search_more) && this.is_option_set(self.view.ir_options['web_m2x_options.search_more'])) { this.search_more = true }