# Picklist / invoice et al: sort order of items

**URL:** <https://discuss.tryton.org/t/picklist-invoice-et-al-sort-order-of-items/5637>\
**Category:** User\
**Created:** [October 25, 2022, 10:25am UTC](https://discuss.tryton.org/t/picklist-invoice-et-al-sort-order-of-items/5637 "2022-10-25T10:25:57Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![mstma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/m/d78d45/32.png) [@mstma](https://discuss.tryton.org/u/mstma)\
**Post date:** [October 16, 2023, 6:25pm UTC](https://discuss.tryton.org/t/picklist-invoice-et-al-sort-order-of-items/5637/8 "2023-10-16T18:25:07Z")

</div>

Here is my code for the proposal, I posted [above](https://discuss.tryton.org/t/picklist-invoice-et-al-sort-order-of-items/5637/6). It shows how to collect the shipping dates of every article starting from `invoice.line`, when using the module sale\_invoice\_grouping.

```auto
import re
from proteus import config, Model 

config = config.set_trytond(database_uri)

mInvoice = Model.get('account.invoice')
mInvoiceLine = Model.get('account.invoice.line')
mSaleLine = Model.get('sale.line')

invoice, = mInvoice.find(['id','=',id2find])
for invoiceline in invoice.lines:
    origin = str(invoiceline.origin)
    if not invoiceline.type == "line":
        continue
    result = re.match("sale\.line\,[0-9]+", origin)
    if not result:
        continue
    table, record = origin.split(",")
    saleline, = mSaleLine.find(['id','=',record])
    sale = saleline.sale
	# save the necessary items in a dictionary
	# or object to sort and set the field sequence
	# in the the object invoiceline in a further step
	# - invoiceline
	# - sale.sale_date
	# - saleline.shipping_date

```

After sorting the items, the field `sequence` can be set and saved.

```auto
i = 1
for invoiceline in listWithInvoiceLines:
	invoiceline.sequence = i
	invoiceline.save()
	i = i + 1

```

After reloading the view of the invoice in the client, the invoice lines are shown in the new order.

When using the module `sale_shippment_costs` besides, an issue occurs: The field `sale.line.shipping_date` in the automatically generated carrier products is always set to the actual date (`datetime.date.today()`). @herrdeh has open [new thread](https://discuss.tryton.org/t/invoice-date-of-shipment-product/6588) for this issue.

---

_[View the full topic](https://discuss.tryton.org/t/picklist-invoice-et-al-sort-order-of-items/5637)._
