<dtml-comment>
title:
connection_id:erp5_sql_connection
max_rows:1000
max_cache:100
cache_time:0
class_name:DeliveryListBrain
class_file:InventoryBrain.py
</dtml-comment>
<params>order_related_movement_uid_list:list
query
at_date</params>
SELECT
	resource.uid,
	resource.path,
	SUM(movement.target_quantity) as target_quantity,
	SUM(movement.quantity) as quantity,
	node.title AS node_title,
	node.relative_url AS node_relative_url,
	section.title AS section_title,
	section.relative_url AS section_relative_url,
	resource.title AS resource_title,
	resource.uid AS resource_uid,
	resource.relative_url AS resource_relative_url,
	movement.variation_text AS variation_text,
	catalog.simulation_state AS simulation_state
<dtml-if at_date>,<dtml-sqlvar at_date type="string" > as at_date
</dtml-if>
<dtml-if query>,<dtml-sqlvar query type="string"> as query
</dtml-if>
FROM
	catalog AS transformation_rule,
	catalog AS resource,
	catalog,
	stock,
	catalog AS node,
	catalog AS section,
	movement
WHERE
	transformation_rule.id = "default_transformation_rule"
AND	node.uid = stock.node_uid
AND	section.uid = stock.section_uid
AND	stock.uid = catalog.uid
<dtml-if order_related_movement_uid_list>
AND	(<dtml-in order_related_movement_uid_list>transformation_rule.parent_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if></dtml-in>)
</dtml-if>
AND	catalog.parent_uid = transformation_rule.uid
AND	movement.uid = catalog.uid
AND	movement.resource_uid = resource.uid
AND	(resource.portal_type = "Composant" OR resource.portal_type = "Tissu")
GROUP BY
	resource.uid, movement.variation_text
ORDER BY
	resource.title, movement.variation_text	