# Define ordering for a Function field with many origins

**URL:** https://discuss.tryton.org/t/define-ordering-for-a-function-field-with-many-origins/2996
**Category:** Developer
**Created:** [July 8, 2020, 4:08pm UTC](https://discuss.tryton.org/t/define-ordering-for-a-function-field-with-many-origins/2996 "2020-07-08T16:08:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)
#### Post date: [July 8, 2020, 4:08pm UTC](https://discuss.tryton.org/t/define-ordering-for-a-function-field-with-many-origins/2996/1 "2020-07-08T16:08:22Z")

</div>

I’m trying to define the ordering method of a custom Function field in invoice line. This field has a getter method that gets value from different models depending on invoice line origin.  
Let’s explain it more in detail:

- the function field is an “origin\_date” and is visible in standalone invoice lines.
- when the origin is a purchase, the value is the purchase\_date of the purchase
- when the origin is an stock move, the value is the effective date of the move.

Define the ordering for each case is clear to me, but not how to combine them.  
Is it possible? Any help will be appreciated.

---

<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: [July 8, 2020, 4:22pm UTC](https://discuss.tryton.org/t/define-ordering-for-a-function-field-with-many-origins/2996/2 "2020-07-08T16:22:15Z")

</div>

You probably need to use a [`CASE`](https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-CASE) clause based on multiple LEFT joins.

---

<div class="post-metadata">

### Author: ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)
#### Post date: [July 8, 2020, 8:53pm UTC](https://discuss.tryton.org/t/define-ordering-for-a-function-field-with-many-origins/2996/3 "2020-07-08T20:53:54Z")

</div>

That is! Thanks a lot.

---

<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: [August 7, 2020, 8:53pm UTC](https://discuss.tryton.org/t/define-ordering-for-a-function-field-with-many-origins/2996/4 "2020-08-07T20:53:55Z")

</div>

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