Tree view with many parents

39 views
Skip to first unread message

Udo Spallek

unread,
Nov 22, 2014, 3:06:25 AM11/22/14
to tryto...@googlegroups.com
Hello,

what is the best way in Tryton to view a tree with many parents per
entry?


Goal
----
We have an Artist class which can be a person or a band/group/project.
Bands could be made of other Artists.
I would like to see a tree view with Artists, which can have many
Bands as a parent. So one and the same Artist can be member of many
bands, like this:

* Arto Tunçboyacıyan (solo artist person)
* Daron Malakianv (solo artist person)
* Serj Tankian (solo artist person)
* System of a Down (band)
* Serj Tankian
* Daron Malakianv
* Scars on Broadway (band)
* Daron Malakian
* Serart (project)
* Serj Tankian
* Arto Tunçboyacıyan


Status Quo
----------
In Tryton we have the tree view which is able to show parent-children
relationships as a graph. But this view seems to be limited to have
only one parent relation.

The general setup in Tryton 3.2 for a tree view is like this:

class Artist(ModelSQL, ModelView):
'Artist'
__name__ = 'artist.artist'
name = fields.Char('Name', required=True)
parent = fields.Many2One(
'artist.artist', 'Parent', select=True, states=STATES,
depends=DEPENDS)
children = fields.One2Many(
'artist.artist', 'parent', 'Children', states=STATES,
depends=DEPENDS) active = fields.Boolean('Active')

XML:

<record model="ir.ui.view" id="artist_tree_view">
<field name="model">artist.artist</field>
<field name="type">tree</field>
<field name="field_childs">children</field>
<field name="name">artist_tree</field>
</record>
<record model="ir.action.act_window" id="act_artist_tree">
<field name="name">Artists</field>
<field name="res_model">artist.artist</field>
<field name="domain">[]</field>
<field name="search_value">[]</field>
</record>
<record model="ir.action.act_window.view" id="act_artist_tree1">
<field name="view" ref="artist_tree_view"/>
<field name="act_window" ref="act_artist_tree"/>
</record>
<menuitem action="act_artist_tree" id="menu_artist_tree"
sequence="20"/>

I feel there is a need for an Many2Many relation, but I do not get a
clue. Any Ideas are welcome.

TIA and regards
Udo Spallek

Cédric Krier

unread,
Nov 22, 2014, 4:20:04 AM11/22/14
to tryto...@googlegroups.com
On 22 Nov 09:06, Udo Spallek wrote:
> I feel there is a need for an Many2Many relation, but I do not get a
> clue. Any Ideas are welcome.

treeview doesn't require a parent field and you can use a M2M as
children.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Udo Spallek

unread,
Nov 22, 2014, 6:08:59 AM11/22/14
to tryto...@googlegroups.com
Sat, 22 Nov 2014 10:18:18 +0100
Cédric Krier <cedric...@b2ck.com>:

>On 22 Nov 09:06, Udo Spallek wrote:
>> I feel there is a need for an Many2Many relation, but I do not get a
>> clue. Any Ideas are welcome.
>
>treeview doesn't require a parent field and you can use a M2M as
>children.

This works[1] with some problems[2]. But thank you a lot.
I needed a patch[3] to avoid the following error:
But maybe I did something wrong in the API. When you can confirm there
is indeed an issue, I'll start an issue/review.

Cheers Udo

[1] My setup::

class Artist(ModelSQL, ModelView):
'Artist'
__name__ = 'artist.artist'
name = fields.Char('Name', required=True)
children = fields.Many2Many(
'artist.artist-artist.artist', 'artist_parent',
'artist_child', 'Children', states=STATES,
depends=DEPENDS)

class ArtistArtist(ModelSQL):
'Artist - Artist'
__name__ = 'artist.artist-artist.artist'
_table = 'artist_artist_rel'
artist_parent = fields.Many2One(
'artist.artist', 'Artist Parent', required=True, select=True)
artist_child = fields.Many2One(
'artist.artist', 'Artist Child', required=True, select=True)

XML is the same as in the initial post.

[2] The error::
ERROR:tryton.common.common:Traceback (most recent call last):
File "/trytond/protocols/jsonrpc.py", line 125, in _marshaled_dispatch
response['result'] = dispatch_method(method, params)
File "/trytond/protocols/jsonrpc.py", line 158, in _dispatch
res = dispatch(*args)
File "/trytond/protocols/dispatcher.py", line 158, in dispatch
result = rpc.result(meth(*c_args, **c_kwargs))
File "/trytond/model/modelview.py", line 240, in fields_view_get
result['field_childs'])
File "/trytond/model/modelview.py", line 339, in _view_look_dom_arch
fields_def.setdefault(field.field, {'name': field.field})
AttributeError: 'Many2Many' object has no attribute 'field'

'Many2Many' object has no attribute 'field'


[3] Patch for trytond 3.2::
diff --git a/trytond/model/modelview.py b/trytond/model/modelview.py
index 4847a4e..4642644 100644
--- a/trytond/model/modelview.py
+++ b/trytond/model/modelview.py
@@ -334,7 +334,8 @@ class ModelView(Model):
fields_def.setdefault(field_children, {'name':
field_children}) if field_children in cls._fields:
field = cls._fields[field_children]
- fields_def.setdefault(field.field, {'name':
field.field})
+ if field._type != 'many2many':
+ fields_def.setdefault(field.field, {'name':
field.field})
for field_name in fields_def.keys():
if field_name in cls._fields:

Cédric Krier

unread,
Nov 22, 2014, 8:55:04 AM11/22/14
to tryto...@googlegroups.com
On 22 Nov 12:08, Udo Spallek wrote:
> Sat, 22 Nov 2014 10:18:18 +0100
> Cédric Krier <cedric...@b2ck.com>:
>
> >On 22 Nov 09:06, Udo Spallek wrote:
> >> I feel there is a need for an Many2Many relation, but I do not get a
> >> clue. Any Ideas are welcome.
> >
> >treeview doesn't require a parent field and you can use a M2M as
> >children.
>
> This works[1] with some problems[2]. But thank you a lot.
> I needed a patch[3] to avoid the following error:
> But maybe I did something wrong in the API. When you can confirm there
> is indeed an issue, I'll start an issue/review.

Yes, this is something not done in base module and so not tested.

Udo Spallek

unread,
Nov 23, 2014, 3:22:26 AM11/23/14
to tryto...@googlegroups.com
Sat, 22 Nov 2014 14:51:59 +0100
Cédric Krier <cedric...@b2ck.com>:
>On 22 Nov 12:08, Udo Spallek wrote:
>> Sat, 22 Nov 2014 10:18:18 +0100
>> Cédric Krier <cedric...@b2ck.com>:
>> This works[1] with some problems[2]. But thank you a lot.
>> I needed a patch[3] to avoid the following error:
>> But maybe I did something wrong in the API. When you can confirm
>> there is indeed an issue, I'll start an issue/review.
>Yes, this is something not done in base module and so not tested.

cool, exploring the unknown :-)
https://bugs.tryton.org/issue4358
Reply all
Reply to author
Forward
0 new messages