<dtml-comment>
title:
connection_id:erp5_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params></params>
SELECT modele.id, SUM(movement.quantity) AS quantity
FROM catalog AS ligne_livr, catalog AS modele, catalog AS livraison, 
catalog AS commande, category AS cat1, category AS cat2, category AS cat3, movement

WHERE ligne_livr.portal_type="Delivery Line"
AND livraison.portal_type="Samples Packing List"
AND ligne_livr.parent_uid=livraison.uid
AND livraison.delivery_state='expediee'

AND livraison.uid=cat3.uid
AND commande.uid=cat3.category_uid
AND cat3.base_category_uid = <dtml-var "portal_categories.causality.uid">
AND commande.portal_type="Samples Order"
AND commande.order_state="active"

AND cat2.uid=modele.uid
AND ( cat2.category_uid = <dtml-var "portal_categories.collection['2004'].Coramy.Planches.uid">
OR cat2.category_uid = <dtml-var "portal_categories.collection['2004'].Etudes.uid"> )

AND modele.uid=cat1.category_uid
AND ligne_livr.uid=cat1.uid
AND cat1.base_category_uid=<dtml-var "portal_categories.resource.uid">

AND movement.uid=ligne_livr.uid

GROUP BY modele.id
ORDER BY modele.id