search zip code on party

26 views
Skip to first unread message

Simon Klemenc

unread,
Oct 12, 2016, 5:09:40 AM10/12/16
to tryton-dev
Hi,

I found a very old thread on this, but it seems all the docs covering this have disappeared.

So, in order to search parties by zip code, i need to make a function field for the party and a function field searcher function?
Is there an example i can have a look?

The other idea would be to do something like this:

def search_rec_name(cls, name, clause):
domain = super(Party, cls).search_rec_name(name, clause)
Address = Pool().get("party.address")
addresses = Address.search([("zip", "=", clause[2]), ("active", "=", True)])
parties = [address.party.id for address in addresses]
domain.append(("id", "in" parties))

Anyone has the same implemented?
Party lookup by zip code is a very important demand at the company i work for...

best regards,
simon

Clemens Hupka

unread,
Oct 12, 2016, 9:10:56 AM10/12/16
to tryton-dev

Am Mittwoch, 12. Oktober 2016 11:09:40 UTC+2 schrieb Simon Klemenc:
Hi,

I found a very old thread on this, but it seems all the docs covering this have disappeared.

So, in order to search parties by zip code, i need to make a function field for the party and a function field searcher function?
Is there an example i can have a look?

The other idea would be to do something like this:

def search_rec_name(cls, name, clause):
domain = super(Party, cls).search_rec_name(name, clause)
Address = Pool().get("party.address")
addresses = Address.search([("zip", "=", clause[2]), ("active", "=", True)])
parties = [address.party.id for address in addresses]
domain.append(("id", "in" parties))

Anyone has the same implemented?

I have tried it once but finally did not use it.

If i remember well, it worked this way (but i haven't tested it again) in class Party:

    @classmethod
    def search(cls, domain, offset=0, limit=None, order=None, count=False, query=False):
        newdom = []
        for item in domain:
            if item[0]=="address":
                newdom.append([u"address.zip"], item[1], item[2])
            else:
                newdom.append(item)
        return super(Party, cls).search(newdom, offset=offset, limit=limit, order=order, count=count, query=query)

In this case if you enter "address: put-zip-code-here" it should give you all parties with this zip code...

Party lookup by zip code is a very important demand at the company i work for...

best regards,
simon

Hope this helps,

Kind regards,
Clemens.
 

Cédric Krier

unread,
Oct 12, 2016, 9:40:04 AM10/12/16
to tryton-dev
On 2016-10-12 06:10, Clemens Hupka wrote:
> If i remember well, it worked this way (but i haven't tested it again) in
> class Party:
>
> @classmethod
> def search(cls, domain, offset=0, limit=None, order=None, count=False,
> query=False):
> newdom = []
> for item in domain:
> if item[0]=="address":
> newdom.append([u"address.zip"], item[1], item[2])
> else:
> newdom.append(item)
> return super(Party, cls).search(newdom, offset=offset, limit=limit,
> order=order, count=count, query=query)
>
> In this case if you enter "address: put-zip-code-here" it should give you
> all parties with this zip code...

Indeed it is not a good practice to override ModelStorage.search.
And by the way, it is not needed because the rec_name search on address
already search for zip (city and party). So if you put the addresses on
the party list view (could be tree_invisible), you will be able to
search with this filter:

Addresses: <zip>

Of course it could show you also party with a city containing the zip
code. So if you really want to have strict search than you should search
on the addresses but we do not have a relate to open the parties from
there. I think this will be a good improvement.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
Reply all
Reply to author
Forward
0 new messages