Many2Many filter?

My custom production.py in my custom module

class QualityControlProduction(ModelSQL, ModelView):
    "Quality Control Production"
    __name__ = 'production'    
    inwardno = fields.Many2Many('prod.shipment.relation',
        'prodid','shipid', 'Inward')

class QualityShipmentIn(ModelSQL,ModelView):
    "Quality Shipment In"
    __name__ = "stock.shipment.in"
    inwardid = fields.Many2One('production','Inward ID')
    prodstate = fields.Boolean("In Production")


class ProdShipment(ModelSQL):    
    "Prod Shipment Relation"
    __name__ = "prod.shipment.relation"
    
    shipid = fields.Many2One('stock.shipment.in','Shipment ID',domain=[
            ('state', '=', 'done'),
            ])
    prodid = fields.Many2One('production','Production ID')

i tried domain on shipid in prod.shipment.relation but still it is not applying domain and showing aal the shipments

tried applying domain on many2many filter too like this

class QualityControlProduction(ModelSQL, ModelView):
    "Quality Control Production"
    __name__ = 'production'
    
    inwardno = fields.Many2Many('prod.shipment.relation',
        'prodid','shipid', 'Inward' ,domain=[
            ('shipid.state', '=', 'done'),
            ])

but getting this error

Traceback (most recent call last):
  File "/usr/local/lib/python37/dist-packages/trytond/wsgipy", line 116, in dispatch_request
    return endpoint(request, **requestview_args)
  File "/usr/local/lib/python37/dist-packages/trytond/protocols/dispatcherpy", line 48, in rpc
    request, database_name, *requestrpc_params)
  File "/usr/local/lib/python37/dist-packages/trytond/wsgipy", line 83, in auth_required
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python37/dist-packages/trytond/protocols/wrapperspy", line 131, in wrapper
    return func(request, pool, *args, **kwargs)
  File "/usr/local/lib/python37/dist-packages/trytond/protocols/dispatcherpy", line 181, in _dispatch
    result = rpcresult(meth(*c_args, **c_kwargs))
  File "/usr/local/lib/python37/dist-packages/trytond/model/modelsqlpy", line 1265, in search
    domain, offset=offset, limit=limit, order=order, count=count)
  File "/usr/local/lib/python37/dist-packages/trytond/model/modelstoragepy", line 473, in search
    check_domain(domain, cls, to_check)
  File "/usr/local/lib/python37/dist-packages/trytond/model/modelstoragepy", line 458, in check_domain
    check_domain(d, cls, to_check)
  File "/usr/local/lib/python37/dist-packages/trytond/model/modelstoragepy", line 458, in check_domain
    check_domain(d, cls, to_check)
  File "/usr/local/lib/python37/dist-packages/trytond/model/modelstoragepy", line 447, in check_domain
    elif hasattr(cls_fields[local], 'get_target'):
KeyError: 'shipid'

First there is a difference between domain and filter. The domain is a constraint which is checked against all records linked. The filter limits which records are included in the field from the relation table.

Second the domain for a Many2Many is applied directly on the target. So in your example it should be: [('state', '=', 'done')].

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.