Add shipment reference on invoice

I have a customer who requests to have on the invoice the number of shipments linked as extra references.
It is pretty easy to do by just extending get_origins to append the shipment names of the moves linked to the invoice lines.
So I’m wondering if it should be a standard behavior? For me, the shipment number is redundant with the sale reference because they appears on both document invoice and delivery order. But maybe there are some countries with specific rules about that?

1 Like

Allready done for our customers. It is very useful if you have a big sale which is shipped and invoiced in different parts. No special rules in germany, just a service for the invoiced company to ease the check between delivered and invoiced quantities.

Same here. Standard behaviour for most installs.

yes, this could certainly be standard.
would this be as additional origin references to the shipment line?

In the meanwhile, we’d also like to put a comment containing a textual representation of the shipment reference as the first line in the generated invoices (based on shipment). But it is not really clear where/how this could easily happen…
[added] and given comments can have origins, how to add the shipment line origin to the list of possible origins for an invoice comment?

I also need the shipment reference on invoice.
Could someone please give a hint which get_origins() to modify, and how to do this right?

Thanks.

class Invoice(metaclass=PoolMeta):
    __name__ = 'account.invoice'

    shipments = fields.Function(fields.Char('Shipments'), 'get_shipments')

    def get_shipments(self, name):
        shipments = []
        for line in self.lines:
            for move in line.stock_moves:
                if move.shipment:
                    shipments.append(move.shipment.rec_name)
        return ', '.join(set(filter(None, shipments)))

I think you can submit this code for account_invoice_stock module to be included in standard.

1 Like

Our use case is a little different than a simple list of shipments.
They want to see the invoices lines grouped by the shipment in which was sent.
Shipment A

  • Product 1
  • Product 3

Shipment B

  • Product 5
  • Product 9

I guess we could also have a shipments function field on the line.
But an invoice can be linked to many shipments so your grouping may not work exactly as you think.

Normally this grouping is used when the On Shipment Sent invoice method is used on sale. So each invoice line is related to a single shipment. This is quite common in Spain.
For this invoices we use a grouped lines property so we are also able to show the untaxed_amount of each shipment. I can share some sample code if somebody else is interested.

This is not a guarantee from the code. For example if you use a task queue which has some delay, you can do the shipment of a sale and the back-order while the sale has not yet been processed. This will result in a single invoice line for both shipments.