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: