<dtml-comment>
title:
connection_id:erp5_sql_connection
max_rows:1000
max_cache:100
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>order_id
order_type</params>
SELECT commande.id, SUM(movement.quantity) AS quantity
FROM catalog AS ligne_cde, catalog AS commande, catalog AS delivery_cell, movement

WHERE commande.id=<dtml-var "order_id">
AND commande.portal_type="<dtml-var "order_type">"

AND ligne_cde.parent_uid=commande.uid
AND (ligne_cde.portal_type="Sales Order Line"
OR ligne_cde.portal_type="Purchase Order Line"
OR ligne_cde.portal_type="Production Order Line")

AND delivery_cell.parent_uid=ligne_cde.uid
AND delivery_cell.portal_type="Delivery Cell"

AND movement.uid=delivery_cell.uid

GROUP BY commande.id
ORDER BY commande.id