Hi...see my comments within your message below:

On Apr 25, 2017 10:16, "Ul" <[email protected]> wrote:

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 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.

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

--
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.

-- 
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/CAJ0%2BmOqwL7rBXUdGYt0mcew%3D55CfGntY7xmUPQ94sWfNdZOJYg%40mail.gmail.com.

Reply via email to