From 73c4195fe3c11329544507f07d626b4053b57e86 Mon Sep 17 00:00:00 2001 From: Artem Kostyuk Date: Tue, 20 Feb 2018 12:48:30 +0200 Subject: [PATCH] [MIG] web_tree_many2one_clickable: Migration to 11.0 --- web_tree_many2one_clickable/README.rst | 36 ++----- web_tree_many2one_clickable/__init__.py | 1 - web_tree_many2one_clickable/__manifest__.py | 11 +- .../data/ir_config_parameter.xml | 12 --- .../src/js/web_tree_many2one_clickable.js | 102 +++--------------- .../asset.xml => static/src/xml/assets.xml} | 5 +- 6 files changed, 26 insertions(+), 141 deletions(-) delete mode 100644 web_tree_many2one_clickable/data/ir_config_parameter.xml rename web_tree_many2one_clickable/{views/asset.xml => static/src/xml/assets.xml} (52%) diff --git a/web_tree_many2one_clickable/README.rst b/web_tree_many2one_clickable/README.rst index 511ff4b7..7899e7b0 100644 --- a/web_tree_many2one_clickable/README.rst +++ b/web_tree_many2one_clickable/README.rst @@ -1,4 +1,4 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 @@ -6,42 +6,21 @@ Clickable many2one fields for tree views ======================================== -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. - -Installation -============ - -Install it the regular way. +This addon forces Odoo to use many2one widget on a many2one fields in +tree views. This allows users to open linked resources from trees directly, +without accessing the form. Configuration ============= -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`. +After installation, all many2one and reference fields will be clickable by default. Usage ===== -For the widget option, you need to add `widget="many2one_clickable"` attribute -in the XML field definition in the tree view. - -For example: - -`` - -will open the linked partner in a form view. - -If system parameter `web_tree_many2one_clickable.default` is `true` and you -need to disable one field, then use `widget="many2one_unclickable"` - .. 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/10.0 + :target: https://runbot.odoo-community.org/runbot/162/11.0 Bug Tracker @@ -50,7 +29,7 @@ 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. +help us smash it by providing a detailed and welcomed feedback. Credits @@ -63,6 +42,7 @@ Contributors * Pedro M. Baeza * Antonio Espinosa * Sodexis +* Artem Kostyuk Maintainer ---------- diff --git a/web_tree_many2one_clickable/__init__.py b/web_tree_many2one_clickable/__init__.py index 2977e4d6..d9d1f13d 100644 --- a/web_tree_many2one_clickable/__init__.py +++ b/web_tree_many2one_clickable/__init__.py @@ -1,2 +1 @@ -# -*- coding: utf-8 -*- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/web_tree_many2one_clickable/__manifest__.py b/web_tree_many2one_clickable/__manifest__.py index 47efc5f0..f4a92f8a 100644 --- a/web_tree_many2one_clickable/__manifest__.py +++ b/web_tree_many2one_clickable/__manifest__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2013 Therp BV (). # Copyright 2015 Pedro M. Baeza # Copyright 2015 Antonio Espinosa @@ -8,21 +7,19 @@ { "name": "Clickable many2one fields for tree views", "summary": "Open the linked resource when clicking on their name", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "category": "Hidden", - "website": "https://odoo-community.org/", + "website": "https://github.com/OCA/web", "author": "Therp BV, " "Tecnativa, " + "Camptocamp, " "Odoo Community Association (OCA)", "license": "AGPL-3", - "application": False, "installable": True, "depends": [ 'web', ], "data": [ - 'data/ir_config_parameter.xml', - 'views/asset.xml', + 'static/src/xml/assets.xml', ], - "installable": True, } diff --git a/web_tree_many2one_clickable/data/ir_config_parameter.xml b/web_tree_many2one_clickable/data/ir_config_parameter.xml deleted file mode 100644 index 9466714f..00000000 --- a/web_tree_many2one_clickable/data/ir_config_parameter.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - 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 6ef9fe96..47ef9d56 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,99 +1,21 @@ /* Copyright 2013 Therp BV (). * Copyright 2015 Pedro M. Baeza * Copyright 2016 Antonio Espinosa - # Copyright 2017 Sodexis + * Copyright 2017 Sodexis + * Copyright 2018 Camptocamp SA * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ -odoo.define('web_tree_many2one_clickable.many2one_clickable', function(require) { -"use strict"; +odoo.define('web_tree_many2one_clickable.many2one_clickable', function (require) { + var ListRenderer = require('web.ListRenderer'); -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; - -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: 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); - } - return _.str.sprintf( - '%(name)s', - values - ); + ListRenderer.include({ + _renderBodyCell: function (record, node, colIndex, options) { + if (!node.attrs.widget && this.state.fields[node.attrs.name].type === 'many2one') { + // no explicit widget provided on a many2one field, + // force `many2one` widget + node.attrs.widget = 'many2one'; } - } else { - return this._super(row_data, options); + return this._super(record, node, colIndex, options); } - }, + }); }); - -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; - }, - -}); - -list_widget_registry.add('field.many2one_clickable', ListView.Column); -list_widget_registry.add('field.many2one_unclickable', ListView.Column); - -}); // odoo.define diff --git a/web_tree_many2one_clickable/views/asset.xml b/web_tree_many2one_clickable/static/src/xml/assets.xml similarity index 52% rename from web_tree_many2one_clickable/views/asset.xml rename to web_tree_many2one_clickable/static/src/xml/assets.xml index 58d00130..a926e09f 100644 --- a/web_tree_many2one_clickable/views/asset.xml +++ b/web_tree_many2one_clickable/static/src/xml/assets.xml @@ -3,10 +3,9 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> -