<dtml-comment>
title:
connection_id:erp5_sql_connection
max_rows:1000
max_cache:100
cache_time:0
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params>uid</params>
SELECT
	SUM(movement.target_quantity) AS target_total_quantity
FROM
	catalog AS container_cell, catalog AS container_line, movement
WHERE
	movement.delivery_uid = <dtml-sqlvar getDeliveryUid type="int">
AND
((
	container_cell.parent_uid = container_line.uid 
AND
	container_line.parent_uid = <dtml-sqlvar uid type="int">
AND
	movement.uid = container_cell.uid
AND
	container_cell.portal_type = "Container Cell"
)
OR
(
	container_line.parent_uid = <dtml-sqlvar uid type="int">
AND
	container_line.uid = container_cell.uid
AND
	movement.uid = container_cell.uid
AND
	movement.has_cell_content = 0
AND
	container_line.portal_type = "Container Line"
))
AND container_cell.portal_type <> "Container"