Party module: Search for parties — 'domain' properety works, 'fileter' — does not

I didn’t understand what is happening,

Firstly, typing in filter ‘adresses.zip: %1000%’ do nothing with the serach. It doesn’t filter out results at all.

I am using module overriding. Th following code works when you invoke search from purchase module.

   # This is a variable list like ['90210','90215','90211','90199'.....]
   range_zip_codes = fields.Function(fields.Text("ZIP List"),"get_install_range_list")

   #### This is a subset of perties that has category = installer. It also has a ZIP in the address...
   #### when install_range equal 0 I don't want to limit the search to a particular ZIP
   
    installers = fields.Many2Many('purchase.purchase-installers.party.party', 'purchase', 'installer', 
        string = 'Installers for this purchase', 
        help = 'Installers related to this sale',
        filter = [],
        domain = [
            ('categories.installer', '=', True),
            If( Eval('install_range') != '0',
                ('addresses.zip', 'in', Eval('range_zip_codes')),()
                ),
            ],
        depends=['range_zip_codes','addresses.zip'],
            )

This is where I came to. If I put ‘limiting’ code into the property filter = [....] I have two problems. Firstly, for unknown reason the Eval() function doesn’t work.
But the main problem that putting addresses.zip in that field never worked as well.

What can I do? I don’t want to use domain instead of filter, as the domain property limits installers list only with ZIP codes that are mentioned the range_zip_codes

Where do you type this? On which view? If the addresses field available on the view?

This is a known limitation, see the warning: https://docs.tryton.org/projects/server/en/latest/ref/models/fields.html#trytond.model.fields.One2Many.filter

Is that possible to add to a list view a subdomain?

Every party has a party.addresses filed (a list) that relate to addresses. Addresses have a ZIP property. Now, I used the following approach (I need ZIP code of the first address of the party only, don’t need others, even if a party have more than one office/address):

tree_zipcode = fields.Function(fields.Char('ZIP'), 'get_first_zipcode') # ZIP from category

    def get_first_zipcode(self, name):
        try:
            return self.addresses[0].zip # returns ZIP code from the first address
        except Exception as e:
            return '—'

I have three problems with this approach:

  1. there is no sorting function in the list by this field
  2. There is no search by this field
  3. I cannot use ‘filter’ or ‘domain’ as a restriction (

now, I use a domain = ['addresses.zip','in',Eval('zip_codes_list')],

I am thinking of creating a Char field and change it with… what?? How to detect that ZIP in ‘addresses’ was changed?

Constantine.

To support ordering on Function field, you must define an order method.

To be able to search on Function field, you must define a searcher.

It is not clear what you mean.

1 Like

Wow!

I missed that in docs! Thanks, will play with it tomorrow.

I want to use this “subfield” as a restriction of the domain for Many2Many, but it didn’t work. I think the reason for that is the absence of a searcher, right?

Constantine.