diff --git a/web_m2x_options/README.rst b/web_m2x_options/README.rst index 2b1fafdb..db777208 100644 --- a/web_m2x_options/README.rst +++ b/web_m2x_options/README.rst @@ -6,10 +6,12 @@ Add new options for many2one field Description ----------- -This modules modifies "many2one" form fields so as to add some new display +This modules modifies "many2one" and "many2manytags" form fields so as to add some new display control options. -** New: support many2manytags widget ! ** +**New: support many2manytags widget !** + +**New: support global option management with ir.config_parameter !** Options provided includes possibility to remove "Create..." and/or "Create and Edit..." entries from many2one drop down. You can also change default number of @@ -23,7 +25,7 @@ if the current user have no permission rights to create the related object. Requirements ------------ -Was tested on openerp v7.0 +Was tested on openerp saas-3, saas-4 branch New option @@ -45,6 +47,30 @@ New option Number of displayed record in drop-down panel +ir.config_parameter options +--------------------------- + +Now you can disable "Create..." and "Create and Edit..." entry for all fields in the odoo instance. +If you disable one option, you can enable it for particular field by setting "create: True" option directly on the field definition. + +``web_m2x_options.create`` *boolean* (Default: depends if user have create rights) + + Whether to display the "Create..." entry in dropdown panel for all fields in the odoo instance. + +``web_m2x_options.create_edit`` *boolean* (Default: depends if user have create rights) + + Whether to display "Create and Edit..." entry in dropdown panel 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 + +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 + Example ------- diff --git a/web_m2x_options/__openerp__.py b/web_m2x_options/__openerp__.py index d568f85d..085b35e7 100644 --- a/web_m2x_options/__openerp__.py +++ b/web_m2x_options/__openerp__.py @@ -16,13 +16,13 @@ Add new options for many2one and many2manytags field: Example: -------- -```` + Note: ----- -If one of those options are not set, many2one field uses default many2one +if one of those options are not set, many2one field use default many2one field options. Thanks to: diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index 00885a09..4e3801eb 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/web_m2x_options/static/src/js/form.js @@ -8,9 +8,36 @@ openerp.web_m2x_options = function (instance) { _t = instance.web._t, _lt = instance.web._lt; + var OPTIONS = ['web_m2x_options.create', + 'web_m2x_options.create_edit', + 'web_m2x_options.limit',]; + instance.web.form.FieldMany2One.include({ - show_error_displayer: function () { + 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) { new instance.web.form.M2ODialog(this).open(); @@ -18,11 +45,15 @@ openerp.web_m2x_options = function (instance) { }, get_search_result: function (search_val) { - var def = $.Deferred(); var self = this; // add options limit used to change number of selections record // returned. + if (_.isUndefined(this.view)) + return this._super.apply(this, arguments); + if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) { + this.limit = parseInt(this.view.ir_options['web_m2x_options.limit']); + } if (typeof this.options.limit === 'number') { this.limit = this.options.limit; @@ -47,10 +78,7 @@ openerp.web_m2x_options = function (instance) { "check_access_rights", ["create", false]); } - $.when(search_result, create_rights).then(function (_data, _can_create) { - var data = _data[0]; - - var can_create = _can_create ? _can_create[0] : null; + $.when(search_result, create_rights).then(function (data, can_create) { self.can_create = can_create; // for ``.show_error_displayer()`` self.last_search = data; @@ -88,7 +116,8 @@ openerp.web_m2x_options = function (instance) { return x[1]; }); - if ((typeof self.options.create === 'undefined' && can_create) || + if ((_.isUndefined(self.options.create) && _.isUndefined(self.view.ir_options['web_m2x_options.create']) && can_create) || + (_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create'] == "True") || self.options.create) { if (search_val.length > 0 && @@ -108,7 +137,8 @@ openerp.web_m2x_options = function (instance) { // create... - if ((typeof self.options.create_edit === 'undefined' && can_create) || + if ((_.isUndefined(self.options.create_edit) && _.isUndefined(self.view.ir_options['web_m2x_options.create_edit']) && can_create) || + (_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create_edit'] == "True") || self.options.create_edit) { values.push({ @@ -137,6 +167,28 @@ openerp.web_m2x_options = function (instance) { new instance.web.form.M2ODialog(this).open(); } }, + + start: function() { + this._super.apply(this, arguments); + return this.get_options(); + }, + + get_options: function() { + var self = this; + if (_.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; + }, /** * Call this method to search using a string. @@ -147,6 +199,10 @@ openerp.web_m2x_options = function (instance) { // add options limit used to change number of selections record // returned. + + if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) { + this.limit = parseInt(this.view.ir_options['web_m2x_options.limit']); + } if (typeof this.options.limit === 'number') { this.limit = this.options.limit; @@ -186,7 +242,8 @@ openerp.web_m2x_options = function (instance) { } // quick create - if ((typeof self.options.create === 'undefined') || + if ((_.isUndefined(self.options.create) && _.isUndefined(self.view.ir_options['web_m2x_options.create'])) || + (_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create'] == 'True') || self.options.create) { var raw_result = _(data.result).map(function(x) {return x[1];}); @@ -204,7 +261,8 @@ openerp.web_m2x_options = function (instance) { // create... - if ((typeof self.options.create_edit === 'undefined') || + if ((_.isUndefined(self.options.create_edit === 'undefined') && _.isUndefined(self.view.ir_options['web_m2x_options.create_edit'])) || + (_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create_edit'] == 'True') || self.options.create_edit) { values.push({