Sales Order Delivery Status (computed)

This is stolen from an Odoo Help answer, so credit is due to Paresh Wagh and David from dajac.

The requirement is to be able to see whether a sales order has been partially or fully delivered. This is important (amongst other reasons) if you will wait till an order is fully delivered before you invoice.

Computed Fields can be added in Odoo Studio or directly (by enabling “Developer” mode and going to Settings / Technical / Fields)

Start by adding a field (type = “char” )

If you used Odoo Studio, select the field you added and then click on “More”

  1. Stored
    • Set to TRUE so that it can be used in filters and grouping – note that the value of the computed field will only be changed if the value of one of the dependent fields changes.
    • You can set it to FALSE if you don’t need to use it in filters or grouping. This means Odoo will recalculate it when it is displayed.
  2. Dependencies
    • Enter a list of field names, separated by commas:
      • order_line.product_uom_qty, order_line.qty_delivered
  3. Compute (Python code)
for record in self:
    qty_sum = sum(line.product_uom_qty for line in record.order_line)
    del_sum = sum(line.qty_delivered for line in record.order_line)
    if del_sum == 0:
        record['x_studio_delivery_status'] = "New"
    elif qty_sum > del_sum:
        record['x_studio_delivery_status'] = "Partial"
    else:
        record['x_studio_delivery_status'] = "Done"
  • This is fairly simple Python code.
    • The first two lines calculate the total quantity ordered and delivered by reading all the sales order lines for this sales order.
    • Then check the status
      • If nothing has been delivered, status is “New”
      • If the delivery quantity is less than ordered, status is “Partial”
      • Otherwise (delivery quantity is greater than or equal to ordered quantity), status is “Done”.

It is simple code, but Python is very particular about how code is indented, and if you get it wrong then you will get rather unhelpful error messages.

If you are a Python programmer you can easily enhance the logic as required.

And if you are a Python programmer, please let me know how to exclude order lines for services and consumable items (because there is no “delivery”).

Other examples of Computed Fields

  1. Computed Field with count of POS orders
  2. Use Automated Actions to stop users archiving products
  3. Use a computed field to set field attributes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s