Commit a6583a23 authored by Julien Muchembled's avatar Julien Muchembled

Clean up builder select methods

Select methods do not need to check if catalog data is up-to-date:
this is always done automatically by searchMovementList()
parent 79d617bd
......@@ -51,13 +51,11 @@
<item>
<key> <string>_body</string> </key>
<value> <string>kw[\'parent_specialise_reference\'] = \'default_payment_rule\'\n
kw[\'portal_type\'] = \'Simulation Movement\'\n
kw[\'grand_parent_simulation_state\'] = [\'started\']\n
kw[\'grand_parent_simulation_state\'] = \'started\'\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
kw[\'max_movement_date\'] = DateTime() + 30 # XXX this is an arbitrary value for experimentation\n
# this could be an alarm configuration.\n
movement_list = [x.getObject() for x in context.PaymentTransaction_zSelectMovement(**kw)]\n
return movement_list\n
return context.PaymentTransaction_zSelectMovement(src__=src__, **kw)\n
</string> </value>
</item>
<item>
......
1477
\ No newline at end of file
1478
\ No newline at end of file
......@@ -50,23 +50,12 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>kw[\'parent_specialise_portal_type\'] = [\'Invoice Transaction Rule\', \'Invoice Transaction Simulation Rule\']\n
kw[\'explanation_portal_type\'] = [\'Sale Order\', \'Sale Invoice\', \'Sale Packing List\']\n
kw[\'portal_type\'] = \'Simulation Movement\'\n
kw[\'grand_parent_simulation_state\'] = [\'started\']\n
<value> <string>kw[\'parent_specialise_portal_type\'] = \'Invoice Transaction Rule\', \'Invoice Transaction Simulation Rule\'\n
kw[\'explanation_portal_type\'] = \'Sale Order\', \'Sale Invoice\', \'Sale Packing List\'\n
kw[\'grand_parent_simulation_state\'] = \'started\'\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
movement_list = [] \n
for movement in context.InvoiceTransaction_zSelectMovement(**kw) :\n
movement = movement.getObject()\n
if movement.getDeliveryValue() is None :\n
movement_list.append(movement)\n
else :\n
from Products.ERP5Type.Log import log\n
log(script.getId(), "simulation movement %s should not have been selected !" % movement.getPath())\n
\n
return movement_list\n
return context.InvoiceTransaction_zSelectMovement(**kw)\n
</string> </value>
</item>
<item>
......
105
\ No newline at end of file
106
\ No newline at end of file
......@@ -50,19 +50,9 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>kw[\'parent_specialise_portal_type\'] = [\'Amortisation Rule\']\n
kw[\'portal_type\'] = \'Simulation Movement\'\n
\n
<value> <string>kw[\'parent_specialise_portal_type\'] = \'Amortisation Rule\'\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
context.log(\'AmortisationTransaction_selectMovement\', \'SQL\\n%s\' % context.AmortisationTransaction_zSelectMovement(src__=1, **kw))\n
\n
if src__==0:\n
movement_list = [x.getObject() for x in context.AmortisationTransaction_zSelectMovement(**kw)]\n
#context.log(\'SaleOrder_selectMovement\', \'mvt : %s\' % movement_list)\n
return movement_list\n
else:\n
return context.AmortisationTransaction_zSelectMovement(src__=1, **kw)\n
return context.AmortisationTransaction_zSelectMovement(src__=src__, **kw)\n
</string> </value>
</item>
<item>
......
178
\ No newline at end of file
179
\ No newline at end of file
......@@ -55,6 +55,9 @@
Simulation Movements can come from normal Invoice Transaction Rule\n
and same rule which is children of Trade Model Rule """\n
\n
buildSQLQuery = context.portal_catalog.buildSQLQuery\n
select = context.InvoiceTransaction_zSelectMovement\n
\n
# search for normal movements\n
kw[\'parent_specialise_reference\'] = [\'default_invoice_transaction_rule\']\n
kw[\'grand_grand_parent_specialise_reference\'] = [\n
......@@ -70,32 +73,20 @@ else:\n
\'%s Packing List\' % trade_type,\n
\'Returned %s Packing List\' % trade_type]\n
kw[\'portal_type\'] = \'Simulation Movement\'\n
kw[\'grand_parent_simulation_state\'] = [\'started\']\n
\n
search_kw = kw.copy()\n
search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
search_kw[\'grand_parent_simulation_state\'] = [\'started\']\n
search_kw.update(buildSQLQuery(**search_kw))\n
\n
normal_movement_list = [movement for movement in context.InvoiceTransaction_zSelectMovement(**search_kw)]\n
movement_list = list(select(**search_kw))\n
\n
# update query to search for movements which are children of Trade Model Rule\n
kw.pop(\'grand_parent_simulation_state\')\n
kw[\'grand_grand_parent_specialise_reference\'] = \'default_trade_model_rule\'\n
kw[\'grand_grand_grand_parent_simulation_state\'] = [\'started\']\n
\n
search_kw = kw.copy()\n
\n
search_kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
trade_model_movement_list = [movement for movement in context.InvoiceTransaction_zSelectMovement(**search_kw)]\n
kw.update(buildSQLQuery(**kw))\n
\n
movement_list = [] \n
for movement in normal_movement_list + trade_model_movement_list:\n
movement = movement.getObject()\n
if movement.getDeliveryValue() is None and movement not in movement_list :\n
movement_list.append(movement)\n
else :\n
from Products.ERP5Type.Log import log\n
log(script.getId(), "simulation movement %s should not have been selected !" % movement.getPath())\n
movement_list += select(**kw)\n
\n
return movement_list\n
</string> </value>
......
......@@ -50,23 +50,12 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>kw[\'parent_specialise_portal_type\'] = [\'Invoicing Rule\', \'Invoice Simulation Rule\']\n
kw[\'explanation_portal_type\'] = [\'Purchase Order\', \'Purchase Packing List\', \'Returned Purchase Packing List\']\n
kw[\'portal_type\'] = \'Simulation Movement\'\n
kw[\'grand_parent_simulation_state\'] = [\'started\', \'stopped\', \'delivered\']\n
<value> <string>kw[\'parent_specialise_portal_type\'] = \'Invoicing Rule\', \'Invoice Simulation Rule\'\n
kw[\'explanation_portal_type\'] = \'Purchase Order\', \'Purchase Packing List\', \'Returned Purchase Packing List\'\n
kw[\'grand_parent_simulation_state\'] = \'started\', \'stopped\', \'delivered\'\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
movement_list = [] \n
for movement in context.InvoiceTransaction_zSelectMovement(**kw) :\n
movement = movement.getObject()\n
if movement.getDeliveryValue() is None :\n
movement_list.append(movement)\n
else : \n
from Products.ERP5Type.Log import log\n
log(script.getId(), "simulation movement %s should not have been selected !" % movement.getPath())\n
\n
return movement_list\n
return context.InvoiceTransaction_zSelectMovement(**kw)\n
</string> </value>
</item>
<item>
......
......@@ -50,26 +50,13 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>kw[\'parent_specialise_portal_type\'] = [\'Trade Model Rule\', \'Trade Model Simulation Rule\']\n
kw[\'explanation_portal_type\'] = [\'Purchase Order\', \'Purchase Packing List\', \'Returned Purchase Packing List\',\n
\'Purchase Invoice Transaction\', \'Purchase Invoice\']\n
kw[\'portal_type\'] = \'Simulation Movement\'\n
kw[\'grand_parent_simulation_state\'] = [\'started\', \'stopped\', \'delivered\', \'confirmed\']\n
<value> <string>kw[\'parent_specialise_portal_type\'] = \'Trade Model Rule\', \'Trade Model Simulation Rule\'\n
kw[\'explanation_portal_type\'] = (\'Purchase Order\', \'Purchase Packing List\', \'Returned Purchase Packing List\',\n
\'Purchase Invoice Transaction\', \'Purchase Invoice\')\n
kw[\'grand_parent_simulation_state\'] = \'started\', \'stopped\', \'delivered\', \'confirmed\'\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
movement_list = [] \n
for movement in context.InvoiceTransaction_zSelectMovement(**kw):\n
movement = movement.getObject()\n
if movement.getDeliveryValue() is None :\n
movement_list.append(movement)\n
else :\n
from Products.ERP5Type.Log import log\n
log(script.getId(),\n
"simulation movement %s should not have been selected !" % movement.getPath())\n
\n
\n
return movement_list\n
return context.InvoiceTransaction_zSelectMovement(**kw)\n
</string> </value>
</item>
<item>
......
......@@ -50,24 +50,12 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>kw[\'parent_specialise_portal_type\'] = [\'Invoicing Rule\', \'Invoice Simulation Rule\']\n
kw[\'explanation_portal_type\'] = [\'Sale Order\', \'Sale Packing List\', \'Returned Sale Packing List\']\n
kw[\'portal_type\'] = \'Simulation Movement\'\n
kw[\'grand_parent_simulation_state\'] = [\'started\', \'stopped\', \'delivered\']\n
<value> <string>kw[\'parent_specialise_portal_type\'] = \'Invoicing Rule\', \'Invoice Simulation Rule\'\n
kw[\'explanation_portal_type\'] = \'Sale Order\', \'Sale Packing List\', \'Returned Sale Packing List\'\n
kw[\'grand_parent_simulation_state\'] = \'started\', \'stopped\', \'delivered\'\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
movement_list = [] \n
for movement in context.InvoiceTransaction_zSelectMovement(**kw) :\n
movement = movement.getObject()\n
if movement.getDeliveryValue() is None :\n
movement_list.append(movement)\n
else :\n
from Products.ERP5Type.Log import log\n
log("SaleInvoice_selectPackingListMovement", \\\n
"simulation movement %s should not have been selected !" % movement.getPath())\n
\n
return movement_list\n
return context.InvoiceTransaction_zSelectMovement(**kw)\n
</string> </value>
</item>
<item>
......
......@@ -50,26 +50,13 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>kw[\'parent_specialise_portal_type\'] = [\'Trade Model Rule\', \'Trade Model Simulation Rule\']\n
kw[\'explanation_portal_type\'] = [\'Sale Order\', \'Sale Packing List\', \'Returned Sale Packing List\',\n
\'Sale Invoice Transaction\', \'Sale Invoice\']\n
kw[\'portal_type\'] = \'Simulation Movement\'\n
kw[\'grand_parent_simulation_state\'] = [\'started\', \'stopped\', \'delivered\', \'confirmed\']\n
<value> <string>kw[\'parent_specialise_portal_type\'] = \'Trade Model Rule\', \'Trade Model Simulation Rule\'\n
kw[\'explanation_portal_type\'] = (\'Sale Order\', \'Sale Packing List\', \'Returned Sale Packing List\',\n
\'Sale Invoice Transaction\', \'Sale Invoice\')\n
kw[\'grand_parent_simulation_state\'] = \'started\', \'stopped\', \'delivered\', \'confirmed\'\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
movement_list = [] \n
for movement in context.InvoiceTransaction_zSelectMovement(**kw):\n
movement = movement.getObject()\n
if movement.getDeliveryValue() is None :\n
movement_list.append(movement)\n
else :\n
from Products.ERP5Type.Log import log\n
log(script.getId(),\n
"simulation movement %s should not have been selected !" % movement.getPath())\n
\n
\n
return movement_list\n
return context.InvoiceTransaction_zSelectMovement(**kw)\n
</string> </value>
</item>
<item>
......
380
\ No newline at end of file
381
\ No newline at end of file
......@@ -50,38 +50,30 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>def test(movement):\n
root_applied_rule = movement.getRootAppliedRule()\n
root_rule = root_applied_rule.getSpecialiseValue()\n
root_movement = movement.getRootSimulationMovement()\n
parent_applied_rule = movement.getParentValue()\n
parent_rule = parent_applied_rule.getSpecialiseValue()\n
return (\n
root_rule.getPortalType() in ("Production Order Rule",\n
"Production Order Root Simulation Rule") and\\\n
parent_rule.getPortalType() == "Transformation Rule" and\\\n
root_movement.getSimulationState() == "confirmed"\n
)\n
search_kw = {\n
\'explanation_portal_type\': \'Production Order\',\n
\'portal_type\': \'Simulation Movement\',\n
}\n
<value> <string>kw[\'explanation_portal_type\'] = \'Production Order\'\n
kw[\'parent_specialise_portal_type\'] = \'Transformation Rule\'\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
result = context.ProductionOrder_zSelectMovement(src__=src__, **kw)\n
if src__:\n
result\n
\n
if explanation_uid is not None:\n
search_kw[\'explanation_uid\'] = explanation_uid\n
search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
movement_list = []\n
for movement in result:\n
movement = movement.getObject()\n
root_movement = movement.getRootSimulationMovement()\n
root_rule = root_movement.getParentValue().getSpecialiseValue()\n
if root_rule.getPortalType() in ("Production Order Rule",\n
"Production Order Root Simulation Rule") \\\n
and root_movement.getSimulationState() == "confirmed":\n
movement_list.append(movement)\n
\n
if src__==0:\n
movement_list = [x.getObject() for x in context.ProductionOrder_zSelectMovement(**search_kw)]\n
movement_list = [x for x in movement_list if test(x)]\n
return movement_list\n
else:\n
return context.ProductionOrder_zSelectMovement(src__=1, **search_kw)\n
return movement_list\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>explanation_uid=None, src__=0, **kw</string> </value>
<value> <string>src__=0, **kw</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
......
......@@ -50,44 +50,34 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>def test(movement):\n
root_applied_rule = movement.getRootAppliedRule()\n
root_rule = root_applied_rule.getSpecialiseValue()\n
root_movement = movement.getRootSimulationMovement()\n
parent_applied_rule = movement.getParentValue()\n
parent_rule = parent_applied_rule.getSpecialiseValue()\n
return (\n
((root_rule.getPortalType() in ("Production Order Rule",) and\\\n
parent_rule.getPortalType() in ("Transformation Sourcing Rule",\n
"Production Order Rule")) or\\\n
(root_rule.getPortalType() in ("Production Order Root Simulation Rule",) and\\\n
parent_rule.getPortalType() in ("Transformation Sourcing Rule",\n
"Delivery Simulation Rule"))) and\\\n
root_movement.getSimulationState() == "confirmed"\n
)\n
<value> <string>kw[\'explanation_portal_type\'] = \'Production Order\'\n
\n
# XXX need to implement this part in the catalog\n
# portal type causality of root applied rule\n
search_kw = {\n
\'explanation_portal_type\': \'Production Order\',\n
\'portal_type\': \'Simulation Movement\',\n
}\n
if explanation_uid is not None:\n
search_kw[\'explanation_uid\'] = explanation_uid\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
result = context.ProductionOrder_zSelectMovement(src__=src__, **kw)\n
if src__:\n
result\n
\n
search_kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
movement_list = []\n
for movement in result:\n
movement = movement.getObject()\n
root_movement = movement.getRootSimulationMovement()\n
root_type = root_movement.getParentValue().getSpecialiseValue().getPortalType()\n
parent_type = movement.getParentValue().getSpecialiseValue().getPortalType()\n
if (root_type == "Production Order Rule" and\n
parent_type in ("Transformation Sourcing Rule",\n
"Production Order Rule") or\n
root_type == "Production Order Root Simulation Rule" and\n
parent_type in ("Transformation Sourcing Rule",\n
"Delivery Simulation Rule")) \\\n
and root_movement.getSimulationState() == "confirmed":\n
movement_list.append(movement)\n
\n
if src__==0:\n
movement_list = [x.getObject() for x in context.ProductionOrder_zSelectMovement(**search_kw)]\n
movement_list = [x for x in movement_list if test(x)]\n
return movement_list\n
else:\n
return context.ProductionOrder_zSelectMovement(src__=1, **search_kw)\n
return movement_list\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>explanation_uid=None, src__=0, **kw</string> </value>
<value> <string>src__=0, **kw</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
......
473
\ No newline at end of file
474
\ No newline at end of file
......@@ -50,40 +50,18 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>DEBUG = 0\n
LOG = lambda msg:context.log("PaySheetTransaction_selectMovement", msg)\n
<value> <string>kw[\'parent_specialise_portal_type\'] = (\'Invoice Transaction Rule\',\n
\'Invoice Transaction Simulation Rule\')\n
kw[\'explanation_portal_type\'] = \'Pay Sheet Transaction\'\n
kw[\'grand_parent_simulation_state\'] = \'confirmed\', \'started\'\n
\n
search_kw=dict(\n
parent_specialise_portal_type=[\'Invoice Transaction Rule\', \'Invoice Transaction Simulation Rule\'],\n
explanation_portal_type=[\'Pay Sheet Transaction\'],\n
portal_type=\'Simulation Movement\',\n
grand_parent_simulation_state=[\'confirmed\', \'started\'])\n
\n
if explanation_uid:\n
search_kw[\'explanation_uid\'] = explanation_uid\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**search_kw))\n
\n
if DEBUG :\n
LOG("SQL used (for %s) = %s" % (kw, context.InvoiceTransaction_zSelectMovement(src__=1, **kw)))\n
\n
movement_list = []\n
for movement in context.InvoiceTransaction_zSelectMovement(**kw) :\n
movement = movement.getObject()\n
if movement.getDeliveryValue() is None :\n
movement_list.append(movement)\n
else :\n
LOG("simulation movement %s should not have been selected !" % movement.getPath())\n
\n
if DEBUG :\n
LOG("selected movement_list : %s" % movement_list)\n
\n
return movement_list\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
return context.InvoiceTransaction_zSelectMovement(src__=src__, **kw)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>explanation_uid=None, **kw</string> </value>
<value> <string>src__=0, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
591
\ No newline at end of file
592
\ No newline at end of file
......@@ -50,32 +50,13 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>DEBUG = 1\n
from Products.ERP5Type.Log import log\n
LOG = lambda msg:log("SaleInvoice_selectPackingListMovement", msg)\n
\n
kw[\'parent_specialise_portal_type\'] = [\'Invoicing Rule\', \'Invoice Simulation Rule\']\n
kw[\'explanation_portal_type\'] = [\'Task\', \'Task Report\']\n
kw[\'portal_type\'] = \'Simulation Movement\'\n
kw[\'grand_parent_simulation_state\'] = [\'started\', \'stopped\',\'delivered\']\n
<value> <string>kw[\'parent_specialise_portal_type\'] = (\'Invoicing Rule\',\n
\'Invoice Simulation Rule\')\n
kw[\'explanation_portal_type\'] = \'Task\', \'Task Report\'\n
kw[\'grand_parent_simulation_state\'] = \'started\', \'stopped\', \'delivered\'\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
if DEBUG : \n
LOG("SQL used = %s"%context.InvoiceTransaction_zSelectMovement(src__=1, **kw))\n
\n
movement_list = [] \n
for movement in context.InvoiceTransaction_zSelectMovement(**kw) :\n
movement = movement.getObject()\n
if movement.getDeliveryValue() is None :\n
movement_list.append(movement)\n
else : \n
LOG("simulation movement %s should not have been selected !" % movement.getPath())\n
\n
if DEBUG :\n
LOG("selected movement_list : %s"%movement_list)\n
\n
return movement_list\n
return context.InvoiceTransaction_zSelectMovement(**kw)\n
</string> </value>
</item>
<item>
......
......@@ -63,12 +63,7 @@ kw[\'query\'] = ComplexQuery(\n
operator=\'and\')\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
if src__==0:\n
movement_list = [x.getObject() for x in context.Task_zSelectMovement(**kw)]\n
return movement_list\n
else:\n
return context.Order_zSelectMovement(src__=1, **kw)\n
return context.Order_zSelectMovement(src__=src__, **kw)\n
</string> </value>
</item>
<item>
......
812
\ No newline at end of file
813
\ No newline at end of file
......@@ -64,11 +64,7 @@ kw[\'query\'] = ComplexQuery(\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
if src__==0:\n
movement_list = [x.getObject() for x in context.Order_zSelectMovement(**kw)]\n
return movement_list\n
else:\n
return context.Order_zSelectMovement(src__=1, **kw)\n
return context.Order_zSelectMovement(src__=src__, **kw)\n
</string> </value>
</item>
<item>
......
......@@ -64,11 +64,7 @@ kw[\'query\'] = ComplexQuery(\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
\n
if src__==0:\n
movement_list = [x.getObject() for x in context.Order_zSelectMovement(**kw)]\n
return movement_list\n
else:\n
return context.Order_zSelectMovement(src__=1, **kw)\n
return context.Order_zSelectMovement(src__=src__, **kw)\n
</string> </value>
</item>
<item>
......
......@@ -63,15 +63,7 @@ kw[\'query\'] = ComplexQuery(\n
operator=\'and\')\n
\n
kw.update(context.portal_catalog.buildSQLQuery(**kw))\n
#from Products.ERP5Type.Log import log\n
#log(\'SaleOrder_selectMovement\', \'SQL\\n%s\' % context.Order_zSelectMovement(src__=1, **kw))\n
\n
if src__==0:\n
movement_list = [x.getObject() for x in context.Order_zSelectMovement(**kw)]\n
#log(\'SaleOrder_selectMovement\', \'mvt : %s\' % movement_list)\n
return movement_list\n
else:\n
return context.Order_zSelectMovement(src__=1, **kw)\n
return context.Order_zSelectMovement(src__=src__, **kw)\n
</string> </value>
</item>
<item>
......
1150
\ No newline at end of file
1151
\ No newline at end of file
......@@ -27,6 +27,7 @@
#
##############################################################################
from zLOG import LOG, BLATHER
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.mixin.builder import BuilderMixin, SelectMethodError
......@@ -106,38 +107,24 @@ class SimulatedDeliveryBuilder(BuilderMixin):
First, select movement matching to criteria define on Delivery Builder
Then, call script simulation_select_method to restrict movement_list
"""
movement_list = []
# We only search Simulation Movement
kw['portal_type'] = 'Simulation Movement'
# Search only child movement from this applied rule
if applied_rule_uid is not None:
if applied_rule_uid:
kw['parent_uid'] = applied_rule_uid
# XXX Add profile query
# Add resource query
if self.getResourcePortalType() not in ('', None):
kw['resourceType'] = self.getResourcePortalType()
if self.getSimulationSelectMethodId() in ['', None]:
movement_list = [x.getObject() for x in self.portal_catalog(**kw)]
else:
select_method = getattr(self.getPortalObject(), self.getSimulationSelectMethodId())
movement_list = select_method(**kw)
# XXX Use buildSQLQuery will be better
movement_list = [x for x in movement_list if \
x.getDeliveryValueList()==[] and x.isBuildable()]
portal_type = self.getResourcePortalType()
if portal_type:
kw['resource_portal_type'] = portal_type
movement_list = []
for movement in self._searchMovementList(
portal_type='Simulation Movement', **kw):
if movement.getDelivery():
LOG("searchMovementList", BLATHER,
"ignore already built simulation movement %r"
% movement.getRelativeUrl())
elif movement.isBuildable():
movement_list.append(movement)
# XXX Add predicate test
# XXX FIXME Check that there is no double in the list
# Because we can't trust simulation_select_method
# Example: simulation_select_method is not tested enough
mvt_dict = {}
for movement in movement_list:
if mvt_dict.has_key(movement):
raise SelectMethodError, \
"%s return %s twice (or more)" % \
(str(self.getSimulationSelectMethodId()),
str(movement.getRelativeUrl()))
else:
mvt_dict[movement] = 1
# Return result
return movement_list
def _setDeliveryMovementProperties(self, delivery_movement,
......
......@@ -39,8 +39,6 @@ from Products.ERP5.ExplanationCache import _getExplanationCache
from DateTime import DateTime
from Acquisition import aq_parent, aq_inner
from zLOG import LOG
class CollectError(Exception): pass
class MatrixError(Exception): pass
class DuplicatedPropertyDictKeysError(Exception): pass
......@@ -169,6 +167,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
getattr(delivery_module, delivery_module_before_building_script_id)()
def generateMovementListForStockOptimisation(self, **kw):
# XXX: unused
from Products.ERP5Type.Document import newTempMovement
movement_list = []
for attribute, method in [('node_uid', 'getDestinationUid'),
......@@ -230,36 +229,30 @@ class BuilderMixin(XMLObject, Amount, Predicate):
movement_list.append(movement)
return movement_list
@UnrestrictedMethod
def searchMovementList(self, applied_rule_uid=None, **kw):
def _searchMovementList(self, **kw):
"""
Returns a list of simulation movements (or something similar to
simulation movements) to construct a new delivery.
For compatibility, if a simulation select method id is not provided,
a list of movements for predicting future supplies is returned.
You should define a simulation select method id, then it will be used
to calculate the result.
"""
method_id = self.getSimulationSelectMethodId()
if not method_id:
# XXX compatibility
return self.generateMovementListForStockOptimisation(**kw)
select_method = getattr(self.getPortalObject(), method_id)
movement_list = select_method(**kw)
# Make sure that movements are not duplicated.
if method_id:
select_method = getattr(self.getPortalObject(), method_id)
else:
select_method = self.getPortalObject().portal_catalog
movement_list = [] # use list to preserve order
movement_set = set()
for movement in movement_list:
for movement in select_method(**kw):
movement = movement.getObject()
if movement in movement_set:
raise SelectMethodError('%s returned %s twice or more' % \
(method_id, movement.getRelativeUrl()))
else:
movement_set.add(movement)
movement_set.add(movement)
movement_list.append(movement)
return movement_list
searchMovementList = UnrestrictedMethod(_searchMovementList)
def collectMovement(self, movement_list):
"""
group movements in the way we want. Thanks to this method, we are able
......
......@@ -106,7 +106,6 @@ class DeliveryBuilder(OrderBuilder):
First, select movement matching to criteria define on DeliveryBuilder
Then, call script simulation_select_method to restrict movement_list
"""
movement_list = []
# We only search Simulation Movement
kw['portal_type'] = 'Simulation Movement'
# Search only child movement from this applied rule
......@@ -114,31 +113,12 @@ class DeliveryBuilder(OrderBuilder):
kw['parent_uid'] = applied_rule_uid
# XXX Add profile query
# Add resource query
if self.getResourcePortalType() not in ('', None):
kw['resourceType'] = self.getResourcePortalType()
if self.getSimulationSelectMethodId() in ['', None]:
movement_list = [x.getObject() for x in self.portal_catalog(**kw)]
else:
select_method = getattr(self.getPortalObject(), self.getSimulationSelectMethodId())
movement_list = select_method(**kw)
# XXX Use buildSQLQuery will be better
movement_list = [x for x in movement_list if \
x.getDeliveryValueList()==[]]
portal_type = self.getResourcePortalType()
if portal_type:
kw['resource_portal_type'] = portal_type
# XXX Add predicate test
# XXX FIXME Check that there is no double in the list
# Because we can't trust simulation_select_method
# Example: simulation_select_method is not tested enough
mvt_dict = {}
for movement in movement_list:
if mvt_dict.has_key(movement):
raise SelectMethodError, \
"%s return %s twice (or more)" % \
(str(self.getSimulationSelectMethodId()),
str(movement.getRelativeUrl()))
else:
mvt_dict[movement] = 1
# Return result
return movement_list
return [movement for movement in self._searchMovementList(**kw)
if not movement.getDelivery()]
def _setDeliveryMovementProperties(self, delivery_movement,
simulation_movement, property_dict,
......
......@@ -32,6 +32,7 @@ from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Base import Base
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5.mixin.builder import BuilderMixin
from Products.ERP5.Document.Amount import Amount
from Products.ERP5.MovementGroup import MovementGroupNode
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
......@@ -39,8 +40,6 @@ from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from DateTime import DateTime
from Acquisition import aq_parent, aq_inner, aq_base
from zLOG import LOG
class CollectError(Exception): pass
class MatrixError(Exception): pass
class DuplicatedPropertyDictKeysError(Exception): pass
......@@ -226,6 +225,8 @@ class OrderBuilder(XMLObject, Amount, Predicate):
movement_list.append(movement)
return movement_list
_searchMovementList = BuilderMixin._searchMovementList.im_func
@UnrestrictedMethod
def searchMovementList(self, applied_rule_uid=None, **kw):
"""
......@@ -237,24 +238,9 @@ class OrderBuilder(XMLObject, Amount, Predicate):
You should define a simulation select method id, then it will be used
to calculate the result.
"""
method_id = self.getSimulationSelectMethodId()
if not method_id:
# XXX compatibility
return self.generateMovementListForStockOptimisation(**kw)
select_method = getattr(self.getPortalObject(), method_id)
movement_list = select_method(**kw)
# Make sure that movements are not duplicated.
movement_set = set()
for movement in movement_list:
if movement in movement_set:
raise SelectMethodError('%s returned %s twice or more' % \
(method_id, movement.getRelativeUrl()))
else:
movement_set.add(movement)
return movement_list
if self.getSimulationSelectMethodId():
return self._searchMovementList(**kw)
return self.generateMovementListForStockOptimisation(**kw) # BBB
def collectMovement(self, movement_list):
"""
......
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