Order party tax identifier in party tree view

Hi,

I wonder if it’d be possible to order the function tax_identifier in the party.party tree view.

I’ve tried the code below, following other examples written in the Tryton codebase but it’d seem it’s incorrect so if someone could explain to me whats wrong and/or if it’s even possible to do such ordering I’d appreciate it.

Thanks in advance.

    @classmethod
    def order_tax_identifier(cls, tables):
        pool = Pool()
        PartyIdentifier = pool.get('party.identifier')
        table, _ = tables[None]
        if 'party_identifier' not in tables:
            party_identifier = PartyIdentifier.__table__()
            tables['party_identifier'] = {
                None: (party_identifier, table.id == party_identifier.party),
                }
        return PartyIdentifier.code.convert_order(
                'code', tables['party_identifier'], PartyIdentifier)

You can not define a join that does a Cartesian product because it will generate multiple times the same id on the base SELECT query. (in short you can not use xxx2Many)
So in case of tax identifier, you need first to write a SQL query that you will use as table that returns the tuple unique party and its right tax identifier (the first one). I guess it is doable using window functions.

I do not really the usage for such ordering

A client ‘’‘needs’‘’ it.
I wrote a searcher for it and the order_ function was more about curiosity / learning than anything.

Edit: Just noticed a searcher was already written in the party module. :man_facepalming: :man_shrugging:

The searcher is not an “exact” one because it will match any identifier of the proper type and not only the first one. But this was implemented like that on purpose.

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