Skip to content

Commit dcacee1

Browse files
committed
[ADD] web_tree_many2one_clickable
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. 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. 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 `true`. Usage ===== For the widget option, you need to add `widget="many2one_clickable"` attribute in the XML field definition in the tree view. For example: `<field name="partner_id" widget="many2one_clickable" />` will open the linked partner in a form view. Known issues / Roadmap ====================== * 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.
1 parent 56697a1 commit dcacee1

File tree

6 files changed

+237
-0
lines changed

6 files changed

+237
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Clickable many2one fields for tree views
2+
========================================
3+
4+
This addon provides a separate widget to allow many2one fields in a tree view
5+
open the linked resource when clicking on their name.
6+
7+
You can also define a system parameter to have this behaviour for all the
8+
existing many2one fields in tree views.
9+
10+
Installation
11+
============
12+
13+
Install it the regular way.
14+
15+
Configuration
16+
=============
17+
18+
If you want to have all many2one fields clickable by default, you have to
19+
define in *Configuration > Technical > Parameters > System parameters*, a new
20+
parameter with name `web_tree_many2one_clickable.default` and with value
21+
`true`.
22+
23+
Usage
24+
=====
25+
26+
For the widget option, you need to add `widget="many2one_clickable"` attribute
27+
in the XML field definition in the tree view.
28+
29+
For example:
30+
31+
`<field name="partner_id" widget="many2one_clickable" />`
32+
33+
will open the linked partner in a form view.
34+
35+
Known issues / Roadmap
36+
======================
37+
38+
* You cannot deactivate clickable behaviour for an specific many2one field if
39+
you configure the system parameter.
40+
* The value of the system parameter is retrieved for each many2one field
41+
present in the view instead of only once.
42+
43+
Credits
44+
=======
45+
46+
Contributors
47+
------------
48+
49+
* Therp BV
50+
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
51+
52+
Maintainer
53+
----------
54+
55+
.. image:: http://odoo-community.org/logo.png
56+
:alt: Odoo Community Association
57+
:target: http://odoo-community.org
58+
59+
This module is maintained by the OCA.
60+
61+
OCA, or the Odoo Community Association, is a nonprofit organization whose
62+
mission is to support the collaborative development of Odoo features and
63+
promote its widespread use.
64+
65+
To contribute to this module, please visit http://odoo-community.org.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# This module copyright (C) 2013 Therp BV (<http://therp.nl>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# This module copyright
6+
# (C) 2013 Therp BV (<http://therp.nl>).
7+
# (c) 2015 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
8+
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
9+
#
10+
# This program is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU Affero General Public License as
12+
# published by the Free Software Foundation, either version 3 of the
13+
# License, or (at your option) any later version.
14+
#
15+
# This program is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU Affero General Public License for more details.
19+
#
20+
# You should have received a copy of the GNU Affero General Public License
21+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
#
23+
##############################################################################
24+
{
25+
"name": "Clickable many2one fields for tree views",
26+
"version": "1.0",
27+
"author": "Therp BV, "
28+
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
29+
"Odoo Community Association (OCA)",
30+
"category": "Dependency",
31+
"depends": [
32+
'web',
33+
],
34+
"data": [
35+
'views/asset.xml',
36+
],
37+
"installable": True,
38+
}
Loading
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//-*- coding: utf-8 -*-
2+
//############################################################################
3+
//
4+
// OpenERP, Open Source Management Solution
5+
// This module copyright
6+
// (C) 2013 Therp BV (<http://therp.nl>).
7+
// (c) 2015 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
8+
// Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
9+
//
10+
// This program is free software: you can redistribute it and/or modify
11+
// it under the terms of the GNU Affero General Public License as
12+
// published by the Free Software Foundation, either version 3 of the
13+
// License, or (at your option) any later version.
14+
//
15+
// This program is distributed in the hope that it will be useful,
16+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
// GNU Affero General Public License for more details.
19+
//
20+
// You should have received a copy of the GNU Affero General Public License
21+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
//
23+
//############################################################################
24+
25+
openerp.web_tree_many2one_clickable = function(instance, local)
26+
{
27+
instance.web.list.Column.include({
28+
/*
29+
Load config parameter at init and store it in an accessible variable.
30+
*/
31+
init: function(id, tag, attrs) {
32+
this._super(id, tag, attrs);
33+
if (this.widget == 'many2one_clickable') {
34+
this.use_many2one_clickable = true;
35+
} else if (this.type == 'many2one') {
36+
this.get_options();
37+
}
38+
},
39+
40+
get_options: function() {
41+
if (_.isUndefined(this.ir_option_clickable_loaded)) {
42+
var self = this; // Needed for binding the instance
43+
this.ir_option_clickable_loaded = $.Deferred();
44+
this.use_many2one_clickable = false;
45+
(new instance.web.Model("ir.config_parameter"))
46+
.query(["value"])
47+
.filter([['key', '=', 'web_tree_many2one_clickable.default']])
48+
.first()
49+
.then(function(param) {
50+
self.use_many2one_clickable = (param.value == 'true');
51+
self.ir_option_clickable_loaded.resolve();
52+
});
53+
return this.ir_option_clickable_loaded;
54+
}
55+
return $.when();
56+
},
57+
58+
_format: function (row_data, options)
59+
{
60+
if (this.use_many2one_clickable) {
61+
return _.str.sprintf('<a class="oe_form_uri" data-many2one-clickable-model="%s" data-many2one-clickable-id="%s">%s</a>',
62+
this.relation,
63+
row_data[this.id].value[0],
64+
_.escape(row_data[this.id].value[1] || options.value_if_empty));
65+
}
66+
else {
67+
return this._super(row_data, options);
68+
}
69+
},
70+
71+
});
72+
73+
/* many2one_clickable widget */
74+
75+
instance.web.list.columns.add(
76+
'field.many2one_clickable',
77+
'instance.web_tree_many2one_clickable.Many2OneClickable');
78+
79+
instance.web_tree_many2one_clickable.Many2OneClickable = openerp.web.list.Column.extend({
80+
});
81+
82+
/* click action */
83+
84+
instance.web.ListView.List.include({
85+
render: function()
86+
{
87+
var result = this._super(this, arguments),
88+
self = this;
89+
this.$current.delegate('a[data-many2one-clickable-model]',
90+
'click', function()
91+
{
92+
self.view.do_action({
93+
type: 'ir.actions.act_window',
94+
res_model: jQuery(this).data('many2one-clickable-model'),
95+
res_id: jQuery(this).data('many2one-clickable-id'),
96+
views: [[false, 'form']],
97+
});
98+
});
99+
return result;
100+
},
101+
});
102+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<openerp>
3+
<data>
4+
5+
<template id="assets_backend" name="Many2one clickable assets" inherit_id="web.assets_backend">
6+
<xpath expr="." position="inside">
7+
<script type="text/javascript" src="/web_tree_many2one_clickable/static/src/js/web_tree_many2one_clickable.js"></script>
8+
</xpath>
9+
</template>
10+
11+
</data>
12+
</openerp>

0 commit comments

Comments
 (0)