From e33e281e36cfc061c3ca0395c49ce50a7ca25aa3 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 30 Aug 2016 11:14:41 +0200 Subject: [PATCH 1/2] [ADD] support reference fields in many2one_clickable widget --- web_tree_many2one_clickable/README.rst | 10 ++++----- .../src/js/web_tree_many2one_clickable.js | 21 ++++++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/web_tree_many2one_clickable/README.rst b/web_tree_many2one_clickable/README.rst index 4ce9c82a..daafb2c2 100644 --- a/web_tree_many2one_clickable/README.rst +++ b/web_tree_many2one_clickable/README.rst @@ -1,8 +1,8 @@ Clickable many2one fields for tree views ======================================== -This addon provides a separate widget to allow many2one fields in a tree view -open the linked resource when clicking on their name. +This addon provides a separate widget to allow many2one or reference fields in +a tree view open the linked resource when clicking on their name. You can also define a system parameter to have this behaviour for all the existing many2one fields in tree views. @@ -15,9 +15,9 @@ Install it the regular way. Configuration ============= -If you want to have all many2one fields clickable by default, you have to -define in *Configuration > Technical > Parameters > System parameters*, a new -parameter with name `web_tree_many2one_clickable.default` and with value +If you want to have all many2one and reference fields clickable by default, you +have to define in *Configuration > Technical > Parameters > System parameters*, +a new parameter with name `web_tree_many2one_clickable.default` and with value `true`. Usage diff --git a/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js b/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js index 6c8e365e..810d4de0 100644 --- a/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js +++ b/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js @@ -59,11 +59,22 @@ openerp.web_tree_many2one_clickable = function(instance, local) _format: function (row_data, options) { - if (this.use_many2one_clickable) { - return _.str.sprintf('%s', - this.relation, - row_data[this.id].value[0], - _.escape(row_data[this.id].value[1] || options.value_if_empty)); + if (this.use_many2one_clickable && !!row_data[this.id]) { + var values = { + model: this.relation, + id: row_data[this.id].value[0], + name: _.escape(row_data[this.id].value[1] || options.value_if_empty), + } + if(this.type == 'reference' && !!row_data[this.id + '__display']) + { + values.model = row_data[this.id].value.split(',', 1)[0]; + values.id = row_data[this.id].value.split(',', 2)[1]; + values.name = _.escape(row_data[this.id + '__display'].value || options.value_if_empty); + } + return _.str.sprintf( + '%(name)s', + values + ); } else { return this._super(row_data, options); From b7484338f563103c418f1a6a8873511caf48ca67 Mon Sep 17 00:00:00 2001 From: Antonio Espinosa Date: Fri, 28 Oct 2016 20:33:48 +0200 Subject: [PATCH 2/2] [MIG] web_tree_many2one_clickable --- web_tree_many2one_clickable/README.rst | 38 ++-- web_tree_many2one_clickable/__init__.py | 20 +- web_tree_many2one_clickable/__openerp__.py | 40 ++-- .../data/ir_config_parameter.xml | 12 ++ .../src/js/web_tree_many2one_clickable.js | 180 ++++++++---------- web_tree_many2one_clickable/views/asset.xml | 19 +- 6 files changed, 141 insertions(+), 168 deletions(-) create mode 100644 web_tree_many2one_clickable/data/ir_config_parameter.xml diff --git a/web_tree_many2one_clickable/README.rst b/web_tree_many2one_clickable/README.rst index daafb2c2..ecaa0a3c 100644 --- a/web_tree_many2one_clickable/README.rst +++ b/web_tree_many2one_clickable/README.rst @@ -1,3 +1,8 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +======================================== Clickable many2one fields for tree views ======================================== @@ -15,10 +20,9 @@ Install it the regular way. Configuration ============= -If you want to have all many2one and reference fields clickable by default, you -have to define in *Configuration > Technical > Parameters > System parameters*, -a new parameter with name `web_tree_many2one_clickable.default` and with value -`true`. +After installation, all many2one and reference fields will be clickable +by default. You can change this in *Configuration > Technical > Parameters > System parameters*, +parameter with name `web_tree_many2one_clickable.default` setting it to `false`. Usage ===== @@ -32,22 +36,21 @@ For example: will open the linked partner in a form view. -Known issues / Roadmap -====================== +If system parameter `web_tree_many2one_clickable.default` is `true` and you +need to disable one field, then use `widget="many2one_unclickable"` -* You cannot deactivate clickable behaviour for an specific many2one field if - you configure the system parameter. -* The value of the system parameter is retrieved for each many2one field - present in the view instead of only once. +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/162/9.0 Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. -In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback -`here `_. +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. Credits @@ -58,13 +61,14 @@ Contributors * Therp BV * Pedro M. Baeza +* Antonio Espinosa Maintainer ---------- -.. image:: http://odoo-community.org/logo.png +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :target: https://odoo-community.org This module is maintained by the OCA. @@ -72,4 +76,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_tree_many2one_clickable/__init__.py b/web_tree_many2one_clickable/__init__.py index f6974117..2977e4d6 100644 --- a/web_tree_many2one_clickable/__init__.py +++ b/web_tree_many2one_clickable/__init__.py @@ -1,20 +1,2 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2013 Therp BV (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/web_tree_many2one_clickable/__openerp__.py b/web_tree_many2one_clickable/__openerp__.py index f634d711..bd004034 100644 --- a/web_tree_many2one_clickable/__openerp__.py +++ b/web_tree_many2one_clickable/__openerp__.py @@ -1,38 +1,26 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright -# (C) 2013 Therp BV (). -# (c) 2015 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) -# Pedro M. Baeza -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright 2013 Therp BV (). +# Copyright 2015 Pedro M. Baeza +# Copyright 2015 Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + { "name": "Clickable many2one fields for tree views", - "version": "8.0.1.0.0", + "summary": "Open the linked resource when clicking on their name", + "version": "9.0.1.0.0", + "category": "Hidden", + "website": "https://odoo-community.org/", "author": "Therp BV, " - "Serv. Tecnol. Avanzados - Pedro M. Baeza, " + "Tecnativa, " "Odoo Community Association (OCA)", - "category": "Dependency", + "license": "AGPL-3", + "application": False, + "installable": True, "depends": [ 'web', ], "data": [ + 'data/ir_config_parameter.xml', 'views/asset.xml', ], - 'installable': False, } diff --git a/web_tree_many2one_clickable/data/ir_config_parameter.xml b/web_tree_many2one_clickable/data/ir_config_parameter.xml new file mode 100644 index 00000000..9466714f --- /dev/null +++ b/web_tree_many2one_clickable/data/ir_config_parameter.xml @@ -0,0 +1,12 @@ + + + + + + + web_tree_many2one_clickable.default + true + + + diff --git a/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js b/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js index 810d4de0..eed856a4 100644 --- a/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js +++ b/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js @@ -1,115 +1,101 @@ -//-*- coding: utf-8 -*- -//############################################################################ -// -// OpenERP, Open Source Management Solution -// This module copyright -// (C) 2013 Therp BV (). -// (c) 2015 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) -// Pedro M. Baeza -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . -// -//############################################################################ +/* Copyright 2013 Therp BV (). + * Copyright 2015 Pedro M. Baeza + * Copyright 2016 Antonio Espinosa + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ -openerp.web_tree_many2one_clickable = function(instance, local) -{ - instance.web.list.Column.include({ - /* - Load config parameter at init and store it in an accessible variable. - */ - init: function(id, tag, attrs) { - this._super(id, tag, attrs); - if (this.widget == 'many2one_clickable') { - this.use_many2one_clickable = true; - } else if (this.type == 'many2one') { - this.get_options(); - } - }, +odoo.define('web_tree_many2one_clickable.many2one_clickable', function(require) { +"use strict"; - get_options: function() { - if (_.isUndefined(this.ir_option_clickable_loaded)) { - var self = this; // Needed for binding the instance - this.ir_option_clickable_loaded = $.Deferred(); - this.use_many2one_clickable = false; - (new instance.web.Model("ir.config_parameter")) - .query(["value"]) - .filter([['key', '=', 'web_tree_many2one_clickable.default']]) - .first() - .then(function(param) { - if (param) { - self.use_many2one_clickable = (param.value.toLowerCase() == 'true'); - } - self.ir_option_clickable_loaded.resolve(); - }); - return this.ir_option_clickable_loaded; - } - return $.when(); - }, +var _ = require('_'); +var $ = require('$'); + +var core = require('web.core'); +var ListView = require('web.ListView'); +var Model = require('web.DataModel'); + +var _t = core._t; +var QWeb = core.qweb; +var list_widget_registry = core.list_widget_registry; - _format: function (row_data, options) - { - if (this.use_many2one_clickable && !!row_data[this.id]) { +var promise; +function clickable_get(callback){ + if (_.isUndefined(promise)) { + promise = $.Deferred(); + new Model("ir.config_parameter") + .call("get_param", ["web_tree_many2one_clickable.default", false]) + .done(function(value){ + promise.resolve(String(value).toLowerCase() === "true"); + }) + .fail(function(){ + promise.reject(); + }); + } + return promise; +} + +ListView.Column.include({ + init: function(id, tag, attrs) { + this._super(id, tag, attrs); + if (this.widget == 'many2one_clickable') { + this.use_many2one_clickable = true; + } else if (this.type == 'many2one') { + this.use_many2one_clickable = false; + clickable_get().done($.proxy(function(value){ + this.use_many2one_clickable = value; + }, this)); + } + }, + _format: function (row_data, options) { + if (this.type == 'many2one' && + (this.widget == 'many2one_unclickable' || this.use_many2one_clickable) && + !!row_data[this.id]) { + var value = row_data[this.id].value; + var name = value[1] ? value[1].split("\n")[0] : value[1]; + name = _.escape(name || options.value_if_empty); + if (this.widget == 'many2one_unclickable') { + return name; + } else if (this.use_many2one_clickable) { var values = { model: this.relation, id: row_data[this.id].value[0], - name: _.escape(row_data[this.id].value[1] || options.value_if_empty), - } - if(this.type == 'reference' && !!row_data[this.id + '__display']) - { + name: name, + }; + if(this.type == 'reference' && !!row_data[this.id + '__display']) { values.model = row_data[this.id].value.split(',', 1)[0]; values.id = row_data[this.id].value.split(',', 2)[1]; - values.name = _.escape(row_data[this.id + '__display'].value || options.value_if_empty); + values.name = _.escape(row_data[this.id + '__display'].value || + options.value_if_empty); } return _.str.sprintf( '%(name)s', values ); } - else { - return this._super(row_data, options); - } - }, - - }); - - /* many2one_clickable widget */ + } else { + return this._super(row_data, options); + } + }, +}); - instance.web.list.columns.add( - 'field.many2one_clickable', - 'instance.web_tree_many2one_clickable.Many2OneClickable'); +ListView.List.include({ + render: function() { + var result = this._super(this, arguments), + self = this; + this.$current.delegate('a[data-many2one-clickable-model]', + 'click', function() { + self.view.do_action({ + type: 'ir.actions.act_window', + res_model: $(this).data('many2one-clickable-model'), + res_id: $(this).data('many2one-clickable-id'), + views: [[false, 'form']], + }); + }); + return result; + }, - instance.web_tree_many2one_clickable.Many2OneClickable = openerp.web.list.Column.extend({ - }); +}); - /* click action */ +list_widget_registry.add('field.many2one_clickable', ListView.Column); +list_widget_registry.add('field.many2one_unclickable', ListView.Column); - instance.web.ListView.List.include({ - render: function() - { - var result = this._super(this, arguments), - self = this; - this.$current.delegate('a[data-many2one-clickable-model]', - 'click', function() - { - self.view.do_action({ - type: 'ir.actions.act_window', - res_model: jQuery(this).data('many2one-clickable-model'), - res_id: jQuery(this).data('many2one-clickable-id'), - views: [[false, 'form']], - }); - }); - return result; - }, - }); -} +}); // odoo.define diff --git a/web_tree_many2one_clickable/views/asset.xml b/web_tree_many2one_clickable/views/asset.xml index 9f221396..58d00130 100644 --- a/web_tree_many2one_clickable/views/asset.xml +++ b/web_tree_many2one_clickable/views/asset.xml @@ -1,12 +1,13 @@ - - + + - +