Here is my code for the proposal, I posted above. It shows how to collect the shipping dates of every article starting from invoice.line
, when using the module sale_invoice_grouping.
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.
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 for this issue.