From 3e79de1c60fd2a5364b85b24b7e8e4c08f0879e2 Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Fri, 27 Mar 2015 14:24:07 +0100 Subject: [PATCH 01/13] 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 4e3801eb..d49c2af0 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -58,6 +58,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()); @@ -95,7 +100,7 @@ openerp.web_m2x_options = function (instance) { // search more... if more results that 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 165caa8cee3d8d7e46f5b4c7d89cc24cb5e01fad Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Mon, 30 Mar 2015 15:55:16 +0200 Subject: [PATCH 02/13] Add options to colors many2x field depending on specified field --- web_m2x_options/static/src/js/form.js | 38 ++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index d49c2af0..52a06f35 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,6 +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 @@ -63,7 +64,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(); @@ -97,6 +102,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 that max @@ -156,8 +183,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 f6070e7cf14f158c26de2e18baae1aaaf27017dd Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Mon, 30 Mar 2015 16:06:24 +0200 Subject: [PATCH 03/13] 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 52a06f35..5171c1bf 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -115,10 +115,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 d6ba0a680a3e7c744628fba223fbf9dfe415c97a Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Mon, 30 Mar 2015 16:38:18 +0200 Subject: [PATCH 04/13] 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 5171c1bf..d3483e5f 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -116,10 +116,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 d53b4e20d2bbe1c4ef63070b48dc642919ad0332 Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Tue, 31 Mar 2015 12:00:46 +0200 Subject: [PATCH 05/13] 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 e3681641..e55f3d85 100644 --- a/web_m2x_options/README.rst +++ b/web_m2x_options/README.rst @@ -46,6 +46,18 @@ New options ``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 --------------------------- @@ -78,7 +90,7 @@ Example Your XML form view definition could contain:: ... - + ... Note From bf8b06b076b892b21edc599bca12cffbe1104a68 Mon Sep 17 00:00:00 2001 From: David Coninckx Date: Tue, 31 Mar 2015 15:47:01 +0200 Subject: [PATCH 06/13] Improved description in module manifest and in README --- web_m2x_options/README.rst | 6 +++++- web_m2x_options/__openerp__.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/web_m2x_options/README.rst b/web_m2x_options/README.rst index e55f3d85..01b2aa5e 100644 --- a/web_m2x_options/README.rst +++ b/web_m2x_options/README.rst @@ -46,6 +46,10 @@ New options ``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* @@ -90,7 +94,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 66732118..65cad97e 100644 --- a/web_m2x_options/__openerp__.py +++ b/web_m2x_options/__openerp__.py @@ -3,6 +3,39 @@ { "name": 'web_m2x_options', "version": "0.1", + "description": """ +===================================================== +Add new options for many2one and many2manytags field: +===================================================== + +- create: true/false -> disable "create" entry in dropdown panel +- 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: +-------- + +```` + +Note: +----- + +If one of those options are not set, many2one field uses default many2one +field options. + +Thanks to: +---------- + +- Nicolas JEUDY +- Valentin LAB + +""", "depends": [ 'base', 'web', From 2152ea193068cb6ea9ec2ce835be7cc6cb55f1cd Mon Sep 17 00:00:00 2001 From: ecino Date: Fri, 17 Apr 2015 13:26:53 +0200 Subject: [PATCH 07/13] 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 65cad97e..859414ec 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 b22894cc21a93876acf070b1a95ce0740d570a4a Mon Sep 17 00:00:00 2001 From: ecino Date: Fri, 17 Apr 2015 14:08:57 +0200 Subject: [PATCH 08/13] 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 | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/web_m2x_options/README.rst b/web_m2x_options/README.rst index 01b2aa5e..48a3515a 100644 --- a/web_m2x_options/README.rst +++ b/web_m2x_options/README.rst @@ -81,11 +81,16 @@ If you disable one option, you can enable it for particular field by setting "cr Number of displayed record 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 d3483e5f..3cfb88f7 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -9,8 +9,9 @@ openerp.web_m2x_options = function (instance) { _lt = instance.web._lt; var OPTIONS = ['web_m2x_options.create', - 'web_m2x_options.create_edit', - 'web_m2x_options.limit',]; + 'web_m2x_options.create_edit', + 'web_m2x_options.limit', + 'web_m2x_options.search_more',]; instance.web.form.FieldMany2One = instance.web.form.FieldMany2One.extend({ From 7a81b2fc324cbdb54a92e7df8b4071c13f308860 Mon Sep 17 00:00:00 2001 From: ecino Date: Fri, 17 Apr 2015 14:58:55 +0200 Subject: [PATCH 09/13] 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 3cfb88f7..d06ed47b 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -60,16 +60,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 5dcd044a94048cb646483142fd6ba086ba7d1d81 Mon Sep 17 00:00:00 2001 From: Emanuel Cino Date: Tue, 2 Jun 2015 14:23:13 +0200 Subject: [PATCH 10/13] Added option m2o_dialog in System parameters --- web_m2x_options/README.rst | 5 +++ web_m2x_options/static/src/js/form.js | 55 ++++++++++++++------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/web_m2x_options/README.rst b/web_m2x_options/README.rst index 48a3515a..be6e7603 100644 --- a/web_m2x_options/README.rst +++ b/web_m2x_options/README.rst @@ -77,6 +77,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 record in drop-down panel for all fields in the odoo instance @@ -89,6 +93,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 d06ed47b..7b6a5c16 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -11,36 +11,37 @@ 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({ - start: function() { - this._super.apply(this, arguments); - return this.get_options(); - }, - - get_options: function() { - var self = this; - if (!_.isUndefined(this.view) && _.isUndefined(this.view.ir_options_loaded)) { - this.view.ir_options_loaded = $.Deferred(); - this.view.ir_options = {}; - (new instance.web.Model("ir.config_parameter")) - .query(["key", "value"]).filter([['key', 'in', OPTIONS]]) - .all().then(function(records) { - _(records).each(function(record) { - self.view.ir_options[record.key] = record.value; - }); - self.view.ir_options_loaded.resolve(); - }); - return this.view.ir_options_loaded; - } - return $.when(); - }, - - show_error_displayer: function () { - if ((typeof this.options.m2o_dialog === 'undefined' && this.can_create) || - this.options.m2o_dialog) { + start: function() { + this._super.apply(this, arguments); + return this.get_options(); + }, + + get_options: function() { + var self = this; + if (!_.isUndefined(this.view) && _.isUndefined(this.view.ir_options_loaded)) { + this.view.ir_options_loaded = $.Deferred(); + this.view.ir_options = {}; + (new instance.web.Model("ir.config_parameter")) + .query(["key", "value"]).filter([['key', 'in', OPTIONS]]) + .all().then(function(records) { + _(records).each(function(record) { + self.view.ir_options[record.key] = record.value; + }); + self.view.ir_options_loaded.resolve(); + }); + return this.view.ir_options_loaded; + } + return $.when(); + }, + + 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")) { new instance.web.form.M2ODialog(this).open(); } }, From 68e79234b23027eb08aa1e2d9e90df68f4d0e857 Mon Sep 17 00:00:00 2001 From: Emanuel Cino Date: Wed, 3 Jun 2015 11:21:06 +0200 Subject: [PATCH 11/13] 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 7b6a5c16..bc4d3beb 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(); } }, @@ -63,9 +78,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 } From ea42b46b9ac06193f6073a7a64c411af760263e5 Mon Sep 17 00:00:00 2001 From: steveferry Date: Mon, 24 Aug 2015 09:44:48 +0200 Subject: [PATCH 12/13] Descritpion removed --- web_m2x_options/__openerp__.py | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/web_m2x_options/__openerp__.py b/web_m2x_options/__openerp__.py index 859414ec..66732118 100644 --- a/web_m2x_options/__openerp__.py +++ b/web_m2x_options/__openerp__.py @@ -3,39 +3,6 @@ { "name": 'web_m2x_options', "version": "0.1", - "description": """ -===================================================== -Add new options for many2one and many2manytags field: -===================================================== - -- create: true/false -> disable "create" entry in dropdown panel -- 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: --------- - -```` - -Note: ------ - -If one of those options are not set, many2one field uses default many2one -field options. - -Thanks to: ----------- - -- Nicolas JEUDY -- Valentin LAB - -""", "depends": [ 'base', 'web', From 90f2c2aea50da1c2a7e3d90b2039886a3df98805 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 28 Aug 2015 17:27:04 +0200 Subject: [PATCH 13/13] bump version of web_m2x_options --- 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 66732118..37b7dbf4 100644 --- a/web_m2x_options/__openerp__.py +++ b/web_m2x_options/__openerp__.py @@ -2,7 +2,7 @@ { "name": 'web_m2x_options', - "version": "0.1", + "version": "8.0.0.2", "depends": [ 'base', 'web',