Many2One domain for reference field in field definition

104 views
Skip to first unread message

Udo Spallek

unread,
Jul 16, 2016, 11:22:19 AM7/16/16
to try...@googlegroups.com
Hi,
in a many2one field definition I want to set a domain for a
specific resource in ir.attachments. Is it possible to create such a
domain in a fields definition or do I need to use a function field?
My non working code looks like this::

class Content(ModelSQL, ModelView):
__name__ = 'content'
original_data = fields.Many2One( # 1. try
'ir.attachment', domain=[
('resource', '=', ('content', Eval('id')))])
original_data = fields.Many2One( # 2. try
'ir.attachment', domain=[
('resource', '=', (__name__, Eval('id')))])

Both tries raises the following error:

Traceback (most recent call last):
File "/usr/local/bin/trytond", line 6, in <module>
exec(compile(open(__file__).read(), __file__, 'exec'))
File "/ado/src/trytond/bin/trytond", line 80, in <module>
trytond.server.TrytonServer(options).run()
File "/ado/src/trytond/trytond/server.py", line 98, in run
Pool(db_name).init(update=self.options.update, lang=lang)
File "/ado/src/trytond/trytond/pool.py", line 140, in init
self.start()
File "/ado/src/trytond/trytond/pool.py", line 92, in start
register_classes()
File "/ado/src/trytond/trytond/modules/__init__.py", line 351, in
register_classes
mod_file, pathname, description)
File "/ado/src/collecting_society/__init__.py", line 5, in <module>
from .collecting_society import *
File "/ado/src/collecting_society/collecting_society.py", line 585,
in <module>
class Content(ModelSQL, ModelView):
File "/ado/src/collecting_society/collecting_society.py", line 614,
in Content
'ir.attachment', domain=[('resource', '=', ('content',
Eval('id')))])
File "/ado/src/trytond/trytond/model/fields/many2one.py", line 49, in
__init__
depends=depends, context=context, loading=loading)
File "/ado/src/trytond/trytond/model/fields/field.py", line 142, in
__init__
assert string, 'a string is required'
AssertionError: a string is required

It seems I need to create a string for the resource, which is a fields
reference, but how can I do this with PYSON?

Do you have experience in this?

TIA,
best Udo Spallek

Cédric Krier

unread,
Jul 16, 2016, 11:32:10 AM7/16/16
to try...@googlegroups.com
On 2016-07-16 17:22, 'Udo Spallek' via tryton wrote:
> File "/ado/src/trytond/trytond/model/fields/field.py", line 142, in
> __init__
> assert string, 'a string is required'
> AssertionError: a string is required

You have forgotten to define a string/label for each field.

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

Udo Spallek

unread,
Jul 18, 2016, 6:20:47 AM7/18/16
to try...@googlegroups.com
Sat, 16 Jul 2016 22:31:46 +0700
Cédric Krier <cedric...@b2ck.com>:

>On 2016-07-16 17:22, 'Udo Spallek' via tryton wrote:
>> File "/ado/src/trytond/trytond/model/fields/field.py", line 142, in
>> __init__
>> assert string, 'a string is required'
>> AssertionError: a string is required
>
>You have forgotten to define a string/label for each field.
>

Ouch, I need new glasses…

The following code works for me::

class Content(ModelSQL, ModelView):
__name__ = 'content'

original_data = fields.Many2One(
'ir.attachment', 'Original Data',
domain=[('resource', '=', (__name__, Eval('id')))],
states={'readonly': Eval('id', 0) < 1}, depends=['id'])

Thanks a lot.
Best Udo
Reply all
Reply to author
Forward
0 new messages