domain for field.Reference

124 views
Skip to first unread message

Ul

unread,
Apr 25, 2017, 12:16:03 PM4/25/17
to try...@googlegroups.com
Hello,

i have a Problem with domains on a fields.Reference:

I want to restrict the value of a Many2One field depending on a
fields.Reference in the target.

The target is a stock.lot that i extended with a field.Reference called
'origin'.

Now i want to restrict the lots in a M2O-field in another Model to a
certain lot.origin.

One try was giving the value of the Reverence as a tuple:

supplier_lot = fields.Many2One('stock.lot', 'Supplier Lot',
domain=[ ('origin', '=',
('party.party', Eval('context', {}).get('supplier', -1))
),
('product', '=', Eval('product'))
])

This way it works fine when creating:
- only the right Lots are sugested in the search
- creating new lots the origin fields are filled with the right values
- the new lot is saved to all right with the right origin
but when i want to save the record with the field 'supplier_lot'
containing the domain, i get a popup stating that i cant save because of
a domain mismach in this field. Did i miss anything here, or is this a
bug? Unfortunaltelly i was not able to spot the very place this domain
is validated and fails.

The other try was using a fouth parameter in the domain with even worse
result:

supplier_lot = fields.Many2One('stock.lot', 'Supplier Lot',
domain=[ ('origin', '=',
Eval('context', {}).get('supplier', -1),
'party.party'
),
('product', '=', Eval('product'))
])
this way i get an Error in the Server when i start typing in the
'supplier_lot'-field, when it is trying to find sugestions:

Traceback (most recent call last):
File
"/home/uha4/Computer/programmieren/python/trytond/trytond/protocols/dispatcher.py",
line 160, in _dispatch
result = rpc.result(meth(*c_args, **c_kwargs))
File
"/home/uha4/Computer/programmieren/python/trytond/trytond/model/modelstorage.py",
line 381, in search_read
records = cls.search(domain, offset=offset, limit=limit, order=order)
File
"/home/uha4/Computer/programmieren/python/trytond/trytond/model/modelsql.py",
line 1120, in search
tables, expression = cls.search_domain(domain)
File
"/home/uha4/Computer/programmieren/python/trytond/trytond/model/modelsql.py",
line 1299, in search_domain
expression = convert(domain)
File
"/home/uha4/Computer/programmieren/python/trytond/trytond/model/modelsql.py",
line 1297, in convert
domain[1:] if domain[0] == 'AND' else domain)))
File
"/home/uha4/Computer/programmieren/python/trytond/trytond/model/modelsql.py",
line 1296, in <genexpr>
return And((convert(d) for d in (
File
"/home/uha4/Computer/programmieren/python/trytond/trytond/model/modelsql.py",
line 1287, in convert
expression = field.convert_domain(domain, tables, cls)
File
"/home/uha4/Computer/programmieren/python/trytond/trytond/model/fields/reference.py",
line 132, in convert_domain
return super(Reference, self).convert_domain(domain, tables, Model)
File
"/home/uha4/Computer/programmieren/python/trytond/trytond/model/fields/field.py",
line 300, in convert_domain
name, operator, value = domain
ValueError: too many values to unpack

thanks for any help...

Ulrich

PS: I'm using trytond 4.2 souces pulled from github

Mark Shane Hayden

unread,
Apr 25, 2017, 12:24:47 PM4/25/17
to try...@googlegroups.com
Hi...see my comments within your message below:

This four parameter version may seem "worse" but it is closer to the correct answer.

You need to compare on origin.id not just origin:

domain=[ ('origin.id', '=',
               Eval(...

See if that works for you.


--
You received this message because you are subscribed to the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/49e5efae-c83a-efae-defd-db507947894c%40gmx.de.

Ul

unread,
Apr 25, 2017, 12:49:32 PM4/25/17
to try...@googlegroups.com
Am 25.04.2017 um 18:24 schrieb Mark Shane Hayden:
> Hi...see my comments within your message below:
>
> You need to compare on origin.id <http://origin.id> not just origin:
>
> domain=[ ('origin.id <http://origin.id>', '=',
> Eval(...
>
> See if that works for you.
>
Thanks, like this I did get as far as with the tuple: i can find or
create the lot, but still can't save the record containing the domain
because of domain mismatch.
And now the origin field is not filled automatically when i create a new
lot according to the domain as it was with the tuple.



Karla Stenger

unread,
Apr 25, 2017, 6:06:01 PM4/25/17
to try...@googlegroups.com

​Maybe a dumb question, but:
Did you add 'product' to the depends ?​

 


--
You received this message because you are subscribed to the Google Groups "tryton" group.



--
-------------------------
Karla  Mª  Stenger  Sábat
karla....@gmail.com

Ul

unread,
Apr 26, 2017, 4:35:54 AM4/26/17
to try...@googlegroups.com
I've solved my Problem and, as often, it was hidden in a slightly
different place than expected:

In the domain i used a custom value of the context, that wasn't properly
set.
I had set it in the __setup__ method:
cls.incoming_moves.context.update({'supplier': Eval('supplier', -1)})
so the client was aware of it and filled the fields, and filtered well.
But i missed to set it in the server, so the validation failed, because
in the domain the server used to validate the record id of the reference
field wasn't set.

Anyway thanks for your help

Ulrich



Sergi Almacellas Abellana

unread,
Apr 26, 2017, 4:58:34 AM4/26/17
to try...@googlegroups.com
El 26/04/17 a les 10:34, Ul ha escrit:
> I've solved my Problem and, as often, it was hidden in a slightly
> different place than expected:
>
> In the domain i used a custom value of the context, that wasn't properly
> set.
> I had set it in the __setup__ method:
> cls.incoming_moves.context.update({'supplier': Eval('supplier', -1)})
Indeed, instead of using the context for passing the supplier data, you
should use a functional field filled by on_change that return the
correct values. And then add this field to depends, so the client
fetches and updates it.

Hope it helps.

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk
Reply all
Reply to author
Forward
0 new messages