Skip to content

Commit d0dd554

Browse files
Artem Kostyuktarteo
Artem Kostyuk
authored andcommittedMar 1, 2023
[MIG] web_tree_many2one_clickable: Migration to 11.0
1 parent c36cb88 commit d0dd554

File tree

6 files changed

+26
-141
lines changed

6 files changed

+26
-141
lines changed
 

‎web_tree_many2one_clickable/README.rst

+8-28
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,26 @@
1-
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
22
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
33
:alt: License: AGPL-3
44

55
========================================
66
Clickable many2one fields for tree views
77
========================================
88

9-
This addon provides a separate widget to allow many2one or reference fields in
10-
a tree view open the linked resource when clicking on their name.
11-
12-
You can also define a system parameter to have this behaviour for all the
13-
existing many2one fields in tree views.
14-
15-
Installation
16-
============
17-
18-
Install it the regular way.
9+
This addon forces Odoo to use many2one widget on a many2one fields in
10+
tree views. This allows users to open linked resources from trees directly,
11+
without accessing the form.
1912

2013
Configuration
2114
=============
2215

23-
After installation, all many2one and reference fields will be clickable
24-
by default. You can change this in *Configuration > Technical > Parameters > System parameters*,
25-
parameter with name `web_tree_many2one_clickable.default` setting it to `false`.
16+
After installation, all many2one and reference fields will be clickable by default.
2617

2718
Usage
2819
=====
2920

30-
For the widget option, you need to add `widget="many2one_clickable"` attribute
31-
in the XML field definition in the tree view.
32-
33-
For example:
34-
35-
`<field name="partner_id" widget="many2one_clickable" />`
36-
37-
will open the linked partner in a form view.
38-
39-
If system parameter `web_tree_many2one_clickable.default` is `true` and you
40-
need to disable one field, then use `widget="many2one_unclickable"`
41-
4221
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
4322
:alt: Try me on Runbot
44-
:target: https://runbot.odoo-community.org/runbot/162/10.0
23+
:target: https://runbot.odoo-community.org/runbot/162/11.0
4524

4625

4726
Bug Tracker
@@ -50,7 +29,7 @@ Bug Tracker
5029
Bugs are tracked on `GitHub Issues
5130
<https://github.com/OCA/web/issues>`_. In case of trouble, please
5231
check there if your issue has already been reported. If you spotted it first,
53-
help us smashing it by providing a detailed and welcomed feedback.
32+
help us smash it by providing a detailed and welcomed feedback.
5433

5534

5635
Credits
@@ -63,6 +42,7 @@ Contributors
6342
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
6443
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
6544
* Sodexis <dev@sodexis.com>
45+
* Artem Kostyuk <a.kostyuk@mobilunity.com>
6646

6747
Maintainer
6848
----------
-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# -*- coding: utf-8 -*-
21
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+4-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2013 Therp BV (<http://therp.nl>).
32
# Copyright 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
43
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
@@ -8,21 +7,19 @@
87
{
98
"name": "Clickable many2one fields for tree views",
109
"summary": "Open the linked resource when clicking on their name",
11-
"version": "10.0.1.0.0",
10+
"version": "11.0.1.0.0",
1211
"category": "Hidden",
13-
"website": "https://odoo-community.org/",
12+
"website": "https://github.com/OCA/web",
1413
"author": "Therp BV, "
1514
"Tecnativa, "
15+
"Camptocamp, "
1616
"Odoo Community Association (OCA)",
1717
"license": "AGPL-3",
18-
"application": False,
1918
"installable": True,
2019
"depends": [
2120
'web',
2221
],
2322
"data": [
24-
'data/ir_config_parameter.xml',
25-
'views/asset.xml',
23+
'static/src/xml/assets.xml',
2624
],
27-
"installable": True,
2825
}

‎web_tree_many2one_clickable/data/ir_config_parameter.xml

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,21 @@
11
/* Copyright 2013 Therp BV (<http://therp.nl>).
22
* Copyright 2015 Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
33
* Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
4-
# Copyright 2017 Sodexis <dev@sodexis.com>
4+
* Copyright 2017 Sodexis <dev@sodexis.com>
5+
* Copyright 2018 Camptocamp SA
56
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
67

7-
odoo.define('web_tree_many2one_clickable.many2one_clickable', function(require) {
8-
"use strict";
8+
odoo.define('web_tree_many2one_clickable.many2one_clickable', function (require) {
9+
var ListRenderer = require('web.ListRenderer');
910

10-
var core = require('web.core');
11-
var ListView = require('web.ListView');
12-
var Model = require('web.DataModel');
13-
14-
var _t = core._t;
15-
var QWeb = core.qweb;
16-
var list_widget_registry = core.list_widget_registry;
17-
18-
var promise;
19-
function clickable_get(callback){
20-
if (_.isUndefined(promise)) {
21-
promise = $.Deferred();
22-
new Model("ir.config_parameter")
23-
.call("get_param", ["web_tree_many2one_clickable.default", false])
24-
.done(function(value){
25-
promise.resolve(String(value).toLowerCase() === "true");
26-
})
27-
.fail(function(){
28-
promise.reject();
29-
});
30-
}
31-
return promise;
32-
}
33-
34-
ListView.Column.include({
35-
init: function(id, tag, attrs) {
36-
this._super(id, tag, attrs);
37-
if (this.widget == 'many2one_clickable') {
38-
this.use_many2one_clickable = true;
39-
} else if (this.type == 'many2one') {
40-
this.use_many2one_clickable = false;
41-
clickable_get().done($.proxy(function(value){
42-
this.use_many2one_clickable = value;
43-
}, this));
44-
}
45-
},
46-
_format: function (row_data, options) {
47-
if (this.type == 'many2one' &&
48-
(this.widget == 'many2one_unclickable' || this.use_many2one_clickable) &&
49-
!!row_data[this.id]) {
50-
var value = row_data[this.id].value;
51-
var name = value[1] ? value[1].split("\n")[0] : value[1];
52-
name = _.escape(name || options.value_if_empty);
53-
if (this.widget == 'many2one_unclickable') {
54-
return name;
55-
} else if (this.use_many2one_clickable) {
56-
var values = {
57-
model: this.relation,
58-
id: row_data[this.id].value[0],
59-
name: name,
60-
};
61-
if(this.type == 'reference' && !!row_data[this.id + '__display']) {
62-
values.model = row_data[this.id].value.split(',', 1)[0];
63-
values.id = row_data[this.id].value.split(',', 2)[1];
64-
values.name = _.escape(row_data[this.id + '__display'].value ||
65-
options.value_if_empty);
66-
}
67-
return _.str.sprintf(
68-
'<a class="oe_form_uri" data-many2one-clickable-model="%(model)s" data-many2one-clickable-id="%(id)s">%(name)s</a>',
69-
values
70-
);
11+
ListRenderer.include({
12+
_renderBodyCell: function (record, node, colIndex, options) {
13+
if (!node.attrs.widget && this.state.fields[node.attrs.name].type === 'many2one') {
14+
// no explicit widget provided on a many2one field,
15+
// force `many2one` widget
16+
node.attrs.widget = 'many2one';
7117
}
72-
} else {
73-
return this._super(row_data, options);
18+
return this._super(record, node, colIndex, options);
7419
}
75-
},
20+
});
7621
});
77-
78-
ListView.List.include({
79-
render: function() {
80-
var result = this._super(this, arguments),
81-
self = this;
82-
this.$current.delegate('a[data-many2one-clickable-model]',
83-
'click', function() {
84-
self.view.do_action({
85-
type: 'ir.actions.act_window',
86-
res_model: $(this).data('many2one-clickable-model'),
87-
res_id: $(this).data('many2one-clickable-id'),
88-
views: [[false, 'form']],
89-
});
90-
});
91-
return result;
92-
},
93-
94-
});
95-
96-
list_widget_registry.add('field.many2one_clickable', ListView.Column);
97-
list_widget_registry.add('field.many2one_unclickable', ListView.Column);
98-
99-
}); // odoo.define

‎web_tree_many2one_clickable/views/asset.xml ‎web_tree_many2one_clickable/static/src/xml/assets.xml

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
44
<odoo>
55

6-
<template id="assets_backend" name="Many2one clickable assets" inherit_id="web.assets_backend">
6+
<template id="assets_backend" name="web_tree_many2one_clickable assets" inherit_id="web.assets_backend">
77
<xpath expr="." position="inside">
8-
<script type="text/javascript"
9-
src="/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js"/>
8+
<script type="text/javascript" src="/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js"/>
109
</xpath>
1110
</template>
1211

0 commit comments

Comments
 (0)