<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_cde, catalog AS modele, catalog AS commande, category AS cat1, category AS cat2, movement
WHERE commande.portal_type="Samples Order"
AND commande.order_state="active"
AND ligne_cde.parent_uid=commande.uid
AND ligne_cde.portal_type="Sample Order Line"

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

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 movement.uid=ligne_cde.uid

GROUP BY modele.id
ORDER BY modele.id