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