Commit c0536a0c authored by Jean-Paul Smets's avatar Jean-Paul Smets

new


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@283 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3a44ed2e
## Script (Python) "ActivityTool_postError"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=error
##title=
##
context.portal_activities.setTitle(context.portal_activities.title + '\p' + error)
## Script (Python) "AppliedRule_cleanOrphanedOrder"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# Use this script to test if simulation state is acceptable
def hasDelivery(ps_item):
for m in ps_item.objectValues():
if len(m.getCategoryMembershipList('delivery')) > 0:
return 1
for a in m.objectValues():
if hasDelivery(a):
return 1
return 0
def getDeliveryList(ps_item):
result = {}
for m in ps_item.objectValues():
for d in m.getDeliveryValueList():
if d is not None:
result[d.getRelativeUrl()] = 1
for a in m.objectValues():
result.update( getDeliveryList(a))
return result
# ----------------------------------------------------------
# First make sure all simulation movements point to an order
ar = context
r = ar.getSpecialiseValue()
if r is not None:
if r.getPortalType() == "Order Rule":
if ar.getCausalityValue() is None:
# Additional test need to check this is an order rule
print " Applied Rule %s has no order" % ar.getId()
print " Previously was: %s" % ar.getCausality()
if hasDelivery(ar):
print " Applied Rule %s has some delivered movements" % ar.getId()
print " deliveries: %s" % ' '.join(getDeliveryList(ar).keys())
elif ar.getId() not in ('zero_stock', ):
print " Delete %s" % ar.getId()
context.portal_simulation.deleteContent(ar.getId())
return printed
## Script (Python) "DateTime_getFormattedDate"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=date_time=None
##title=
##
from DateTime import DateTime
if date_time == None :
date_time = DateTime()
return "%2.2d/%2.2d/%s" % (date_time.day(), date_time.month(), date_time.year())
## Script (Python) "Delivery_reindexAll"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
error_list = []
return_list = []
context.portal_catalog.catalog_object(context.portal_categories,None)
base_url = '/'.join(context.getPhysicalPath())
print "#### Indexing categories ####"
for id in list(context.portal_categories.objectIds()):
context.portal_activities.newMessage('SQLDict', '%s/portal_categories/%s' % (base_url, id), {}, 'recursiveImmediateReindexObject')
# We index simulation first to make sure we can calculate tests
print "#### Indexing simulation ####"
for id in list(context.portal_simulation.objectIds()):
context.portal_activities.newMessage('SQLDict', '%s/portal_simulation/%s' % (base_url, id), {}, 'immediateReindexObject')
for folder in context.portal_url.getPortalObject().objectValues(("ERP5 Folder",)):
print "#### Indexing contents inside folder %s ####" % folder.id
for id in list(folder.objectIds()):
context.portal_activities.newMessage('SQLDict', '%s/%s/%s' % (base_url, folder.getId(), id), {}, 'recursiveImmediateReindexObject')
return printed
## Script (Python) "Delivery_rescueOrphanedMovement"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=fix=0
##title=
##
# Example code:
order_uid_list = context.getCausalityUidList() # XXX We may need to filter portal_type
# Check each existing movement in delivery
attached_to_movement = []
for m in context.getMovementList():
# simulation_movement = m.getDeliveryRelatedValueList()
# Is there any orphaned movement
result = context.Delivery_zGetOrphanedMovementList(order_uid_list = order_uid_list,
resource_uid = m.getResourceUid(),
variation_text = m.getVariationText())
if len(result) > 0:
for orphaned in result:
print "Found orphaned movement %s attached to %s" % (orphaned.relative_url, m.getRelativeUrl())
attached_to_movement.append(orphaned.relative_url)
if fix:
simulation_movement = orphaned.getObject()
quantity = simulation_movement.getQuantity()
simulation_movement.setDeliveryValue(m)
m.setQuantity(quantity)
print " Fixed orphaned movement %s attached to %s with quantity %s" % (orphaned.relative_url, m.getRelativeUrl(), quantity)
# Check each orphaned movement
result = context.Delivery_zGetOrphanedMovementList( order_uid_list = order_uid_list )
for orphaned in result:
if orphaned.relative_url not in attached_to_movement:
print "Found orphaned movement %s which required new line/cell" % orphaned.relative_url
return printed
<dtml-comment>
title:
connection_id:MySQL
max_rows:1000
max_cache:100
cache_time:0
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params>order_uid_list:list
resource_uid
variation_text</params>
SELECT
catalog.*,
movement.quantity,
movement.target_quantity,
movement.resource_uid,
movement.variation_text,
movement.source_uid,
movement.destination_uid,
movement.start_date,
movement.stop_date,
movement.target_start_date,
movement.target_stop_date
FROM
movement AS related_order_line,
movement,
catalog AS related_order,
category AS movement_c,
catalog LEFT JOIN category ON (category.uid=catalog.uid
AND category.base_category_uid = <dtml-var "portal_categories.delivery.getUid()">)
LEFT JOIN catalog as related_delivery ON related_delivery.uid = category.category_uid
WHERE
related_delivery.uid is NULL
AND
catalog.portal_type = "Simulation Movement"
AND
catalog.uid = movement_c.uid
AND
movement_c.category_uid = related_order_line.uid
AND
movement_c.base_category_uid = <dtml-var "portal_categories.order.getUid()">
AND
related_order_line.delivery_uid = related_order.uid
AND
catalog.uid = movement.uid
AND
related_order.simulation_state = 'confirmed'
<dtml-if order_uid_list>AND <dtml-in order_uid_list>related_order.uid = <dtml-sqlvar sequence-item type="int"> <dtml-if sequence-end><dtml-else> OR </dtml-if> </dtml-in>
</dtml-if><dtml-if resource_uid>AND movement.resource_uid = <dtml-sqlvar resource_uid type="int">
</dtml-if><dtml-if variation_text>AND movement.variation_text = <dtml-sqlvar variation_text type="string">
</dtml-if>
\ No newline at end of file
<dtml-comment>
title:
connection_id:MySQL
max_rows:10000
max_cache:100
cache_time:0
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params>order_uid_list:list
resource_uid
variation_text</params>
SELECT
catalog.*,
movement.quantity,
movement.target_quantity,
movement.resource_uid,
movement.variation_text,
movement.source_uid,
movement.destination_uid,
movement.start_date,
movement.stop_date,
movement.target_start_date,
movement.target_stop_date
FROM
movement ,
catalog AS related_order,
catalog AS resource,
catalog AS parent,
catalog LEFT JOIN category ON (category.uid=catalog.uid
AND category.base_category_uid = <dtml-var "portal_categories.delivery.getUid()">)
LEFT JOIN catalog as related_delivery ON related_delivery.uid = category.category_uid
WHERE
related_delivery.uid is NULL
AND
catalog.portal_type = "Simulation Movement"
AND
movement.delivery_uid = related_order.uid
AND
catalog.uid = movement.uid
AND
related_order.simulation_state = 'confirmed'
AND
movement.resource_uid = resource.uid
AND
catalog.parent_uid = parent.uid
AND ((parent.id = "default_transformation_sourcing_rule"
AND (resource.portal_type = "Composant" OR resource.portal_type = "Tissu"))
OR (parent.id = "default_transformation_rule"
AND (resource.portal_type = "Modele" OR resource.portal_type = "Composant" OR resource.portal_type = "Tissu" OR resource.portal_type = "Category")))
<dtml-if order_uid_list>AND <dtml-in order_uid_list>related_order.uid = <dtml-sqlvar sequence-item type="int"> <dtml-if sequence-end><dtml-else> OR </dtml-if> </dtml-in>
</dtml-if><dtml-if resource_uid>AND movement.resource_uid = <dtml-sqlvar resource_uid type="int">
</dtml-if><dtml-if variation_text>AND movement.variation_text = <dtml-sqlvar variation_text type="string">
</dtml-if>
\ No newline at end of file
<dtml-comment>
title:
connection_id:MySQL
max_rows:1000
max_cache:100
cache_time:0
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params>resource_uid
variation_text
source_uid
destination_uid
start_date
stop_date
target_start_date
target_stop_date</params>
SELECT
catalog.*
FROM
catalog, movement
WHERE
catalog.uid = movement.uid
AND movement.is_accountable = 1
AND catalog.portal_type <> "Simulation Movement"
<dtml-if resource_uid>AND movement.resource_uid = <dtml-sqlvar resource_uid type="int">
</dtml-if><dtml-if variation_text>AND movement.variation_text = <dtml-sqlvar variation_text type="string">
</dtml-if><dtml-if source_uid>AND movement.source_uid = <dtml-sqlvar source_uid type="int">
</dtml-if><dtml-if destination_uid>AND movement.destination_uid = <dtml-sqlvar destination_uid type="int">
</dtml-if><dtml-if start_date>AND movement.start_date = <dtml-sqlvar start_date type="string">
</dtml-if><dtml-if stop_date>AND movement.stop_date = <dtml-sqlvar stop_date type="string">
</dtml-if><dtml-if target_start_date>AND movement.start_date = <dtml-sqlvar target_start_date type="string">
</dtml-if><dtml-if target_stop_date>AND movement.stop_date = <dtml-sqlvar target_stop_date type="string">
</dtml-if>
\ No newline at end of file
## Script (Python) "Order_cleanDuplicates"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# Use this script to test if simulation state is acceptable
def hasDelivery(ps_item):
for m in ps_item.objectValues():
if len(m.getCategoryMembershipList('delivery')) > 0:
return 1
for a in m.objectValues():
if hasDelivery(a):
return 1
return 0
def getDeliveryList(ps_item):
result = {}
for m in ps_item.objectValues():
for d in m.getDeliveryValueList():
if d is not None:
result[d.getRelativeUrl()] = 1
for a in m.objectValues():
result.update( getDeliveryList(a))
return result
of = context
if of.getSimulationState() not in ('draft', 'cancelled', 'auto_planned'):
ps = of.getCausalityRelatedValueList(portal_type="Applied Rule")
if len(ps) == 0:
print " Missing PS for Order %s of type %s" % (of.getId(), of.getPortalType())
print " Reexpand order %s" % of.getId()
of.edit()
elif len(ps) > 1:
print " Too many PS for Order %s of type %s" % (of.getId(), of.getPortalType())
no_delivery = []
delivery = []
for ps_item in ps:
if hasDelivery(ps_item):
print " PS %s has some delivered movements" % ps_item.getId()
delivery.append(ps_item)
else:
print " PS %s has no delivered movements" % ps_item.getId()
no_delivery.append(ps_item)
# manage_delObjects
if len(delivery) > 0:
# Only erase no_delivery if one item has delivery
for ps_item in no_delivery:
print " Delete PS %s" % ps_item.getId()
parent = ps_item.aq_parent
parent.deleteContent(ps_item.getId())
else:
# Keep at least one
for ps_item in no_delivery[1:]:
print " Delete PS %s" % ps_item.getId()
id = ps_item.getId()
parent = ps_item.aq_parent
parent.deleteContent(ps_item.getId())
if len(delivery) > 1:
# We erase the Applied Rule but keep
# some excessive packing lists which may have been generated
# THIS BREAKS CONSISTENCY
for ps_item in delivery[1:]:
print " Delete PS %s with BREAKS CONSISTENCY" % ps_item.getId()
id = ps_item.getId()
parent = ps_item.aq_parent
#parent.deleteContent(ps_item.getId())
return printed
## Script (Python) "PortalSimulation_cleanup"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
process = context.portal_activities.newActiveProcess()
base_url = '/'.join(context.portal_url.getPortalObject().getPhysicalPath())
# ----------------------------------------------------------
# First make sure all simulation movements point to an order
print "-- Checking simulation"
for id in context.portal_simulation.objectIds():
print " AppliedRule_cleanOrphadedOrder %s" % id
context.portal_activities.newMessage('SQLDict', '%s/portal_simulation/%s' % (base_url, id), process, {}, 'AppliedRule_cleanOrphanedOrder')
# ----------------------------------------------------------
# Next make sure all orders in > planned state have at most one applied rule
for module_id in ('ordre_fabrication','commande_achat','commande_vente',):
for id in context[module_id].objectIds():
print " Order_cleanDuplicates %s/%s" % (module_id , id)
context.portal_activities.newMessage('SQLDict', '%s/%s/%s' % (base_url, module_id, id), process, {}, 'Order_cleanDuplicates')
# ----------------------------------------------------------
# Next make sure all movements in a delivery of material point to simulation
# ----------------------------------------------------------
# Next make sure all movements in a delivery of material point to simulation
return printed
<dtml-comment>
title:
connection_id:MySQL
max_rows:1000
max_cache:100
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>section
strict_membership</params>
SELECT DISTINCT
movement.resource_uid,
movement.variation_text
FROM
movement, stock, catalog as section, category
WHERE
stock.uid = movement.uid
AND stock.section_uid = section.uid
AND section.uid = category.category_uid
AND category.base_category_uid = <dtml-sqlvar "portal_categories.group.getUid()" type="int">
AND section.relative_url = <dtml-sqlvar section type="string">
<dtml-if strict_membership>AND category.strict_membership=1</dtml-if>
\ No newline at end of file
<?xml version="1.0" encoding="iso-8859-1"?>
<form>
<title>Validate</title>
<name>base_folder_workflow_action</name>
<action>folder_workflow_status_modify</action>
<enctype></enctype>
<method>POST</method>
<pt>form_view_dialog</pt>
<groups>
<group>
<title>Default</title>
<fields>
<field><id>my_comment</id> <type>TextAreaField</type>
<values>
<alternate_name></alternate_name>
<css_class></css_class>
<default></default>
<description></description>
<external_validator></external_validator>
<extra></extra>
<height type="int">5</height>
<hidden type="int">0</hidden>
<max_length></max_length>
<max_linelength></max_linelength>
<max_lines></max_lines>
<required type="int">0</required>
<title>Commentaires</title>
<width type="int">40</width>
</values>
<tales>
<default>python:''</default>
</tales>
<messages>
<message name="external_validator_failed">The input failed the external validator.</message>
<message name="required_not_found">Input is required but no input given.</message>
<message name="too_many_lines">You entered too many lines.</message>
<message name="line_too_long">A line was too long.</message>
<message name="too_long">You entered too many characters.</message>
</messages>
</field>
</fields>
</group>
<group>
<title>hidden</title>
<fields>
<field><id>my_workflow_action</id> <type>StringField</type>
<values>
<alternate_name></alternate_name>
<css_class></css_class>
<default></default>
<description></description>
<display_maxwidth></display_maxwidth>
<display_width type="int">20</display_width>
<external_validator></external_validator>
<extra></extra>
<hidden type="int">1</hidden>
<max_length></max_length>
<required type="int">0</required>
<title>x</title>
<truncate type="int">0</truncate>
</values>
<tales>
<default>python:here.REQUEST.workflow_action</default>
</tales>
<messages>
<message name="external_validator_failed">The input failed the external validator.</message>
<message name="required_not_found">Input is required but no input given.</message>
<message name="too_long">Too much input was given.</message>
</messages>
</field>
<field><id>my_workflow_id</id> <type>StringField</type>
<values>
<alternate_name></alternate_name>
<css_class></css_class>
<default></default>
<description></description>
<display_maxwidth></display_maxwidth>
<display_width type="int">20</display_width>
<external_validator></external_validator>
<extra></extra>
<hidden type="int">1</hidden>
<max_length></max_length>
<required type="int">0</required>
<title>x</title>
<truncate type="int">0</truncate>
</values>
<tales>
<default>python:here.REQUEST.workflow_id</default>
</tales>
<messages>
<message name="external_validator_failed">The input failed the external validator.</message>
<message name="required_not_found">Input is required but no input given.</message>
<message name="too_long">Too much input was given.</message>
</messages>
</field>
</fields>
</group>
</groups>
</form>
\ No newline at end of file
## Script (Python) "folder_workflow_status_modify"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=form_id,dialog_id,selection_name
##title=
##
from Products.Formulator.Errors import ValidationError, FormValidationError
request=context.REQUEST
error_message = ''
try:
# Validate the form
form = getattr(context,dialog_id)
form.validate_all_to_request(request)
kw = {}
for f in form.get_fields():
k = f.id
k = k[3:]
v = getattr(request,k,None)
if v is not None:
kw[k] = v
selection_list = context.portal_selections.callSelectionFor(selection_name, context=context)
for selection_item in selection_list:
o = selection_item.getObject()
workflow_action = kw['workflow_action']
action_list = o.portal_workflow.getActionsFor(o)
action_list = filter(lambda x:x.has_key('id'), action_list )
action_id_list = map(lambda x:x['id'], action_list)
if workflow_action in action_id_list:
o.portal_workflow.doActionFor(
o,
workflow_action,
wf_id=kw['workflow_id'],
**kw)
# We will check if there's an error_message
history_data = None
try:
history_data = o.portal_workflow.getInfoFor(ob=o, name='history')
except:
pass
redirect_url = None
if history_data is not None:
last_history_data = history_data[len(history_data)-1]
this_error = last_history_data.get('error_message')
if this_error != None and this_error != '':
error_message += this_error + "-"
except FormValidationError, validation_errors:
# Pack errors into the request
field_errors = form.ErrorFields(validation_errors)
request.set('field_errors', field_errors)
return form(request)
except ValueError, value_error:
# Pack errors into the request
redirect_url = '%s/%s?%s%s' % ( context.absolute_url(), form_id
, 'portal_status_message=',value_error
)
context.REQUEST[ 'RESPONSE' ].redirect( redirect_url )
else:
if error_message != None and error_message != '':
redirect_url = '%s/%s?%s' % ( context.absolute_url(), form_id
, 'portal_status_message=%s' % error_message
)
pass
if redirect_url is None:
redirect_url = '%s/%s?%s' % ( context.absolute_url(), form_id
, 'portal_status_message=Status+changed.'
)
context.REQUEST[ 'RESPONSE' ].redirect( redirect_url )
<dtml-comment>
title:
connection_id:MySQL
max_rows:100000
max_cache:10
cache_time:60
class_name:
class_file:
</dtml-comment>
<params></params>
SELECT DISTINCT
distinct item.uid
FROM
catalog AS item
LEFT JOIN category
ON (category.category_uid=item.uid
AND category.base_category_uid = <dtml-var "portal_categories.aggregate.getUid()">)
LEFT JOIN stock
ON (stock.uid = category.uid)
WHERE item.portal_type = "Piece Tissu"
AND stock.node_uid = <dtml-var "portal_categories.site.Stock_MP.Gravelines.getUid()">
AND stock.quantity < 0
\ No newline at end of file
<dtml-comment>
title:
connection_id:MySQL
max_rows:500
max_cache:100
cache_time:60
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params></params>
SELECT
*
FROM
catalog
WHERE
portal_type = "Piece Tissu"
<dtml-in PieceTissu_searchConsumedList>AND uid <> <dtml-sqlvar uid type="int">
</dtml-in>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment