# Order party tax identifier in party tree view

**URL:** https://discuss.tryton.org/t/order-party-tax-identifier-in-party-tree-view/5739
**Category:** Developer
**Tags:** party
**Created:** [December 3, 2022, 8:43am UTC](https://discuss.tryton.org/t/order-party-tax-identifier-in-party-tree-view/5739 "2022-12-03T08:43:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hodeinavarro](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/hodeinavarro/32/1185_2.png) [@hodeinavarro](https://discuss.tryton.org/u/hodeinavarro)
#### Post date: [December 3, 2022, 8:43am UTC](https://discuss.tryton.org/t/order-party-tax-identifier-in-party-tree-view/5739/1 "2022-12-03T08:43:27Z")

</div>

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.

```python
    @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)

```

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [December 3, 2022, 12:23pm UTC](https://discuss.tryton.org/t/order-party-tax-identifier-in-party-tree-view/5739/2 "2022-12-03T12:23:54Z")

</div>

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](https://www.postgresql.org/docs/current/tutorial-window.html).

_I do not really the usage for such ordering_

---

<div class="post-metadata">

### Author: ![hodeinavarro](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/hodeinavarro/32/1185_2.png) [@hodeinavarro](https://discuss.tryton.org/u/hodeinavarro)
#### Post date: [December 3, 2022, 7:36pm UTC](https://discuss.tryton.org/t/order-party-tax-identifier-in-party-tree-view/5739/3 "2022-12-03T19:36:28Z")

</div>

> [@ced](#):
>
> 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. 🤦‍♂️ 🤷‍♂️

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [December 3, 2022, 8:21pm UTC](https://discuss.tryton.org/t/order-party-tax-identifier-in-party-tree-view/5739/4 "2022-12-03T20:21:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [January 2, 2023, 8:22pm UTC](https://discuss.tryton.org/t/order-party-tax-identifier-in-party-tree-view/5739/5 "2023-01-02T20:22:11Z")

</div>

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