Commit 85b031fb authored by Yingjie Xu's avatar Yingjie Xu Committed by Łukasz Nowak

Merged Open Order periodic simulation work.

Now it is possible to have Hosting Subscription as causality of Root Applied
Rule. It will generate simulation movements to cover defined period of
subscription.

Work by Yingjie Xu and Romain Courteaud.

Squashed commit of the following:

commit 97b7b4366c2ad77a42c4c924fd1379623432f712
Merge: 97cdd11 c092cb6f
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Thu Dec 15 17:15:53 2011 +0100

    Merge remote-tracking branch 'origin/master' into open_order_simulation

commit 97cdd11897c8203cd8ee6dd5e586f9118e39fdfb
Author: Romain Courteaud <romain@nexedi.com>
Date:   Thu Dec 15 16:01:24 2011 +0100

    Remove OpenOrderMovementGroup.

    OrderMovementGroup can now handle Subscription Item as causality.

commit 32b648c32da868955723d82047c3975728fbf666
Merge: 54508f4 9cdf7a81
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Wed Dec 14 17:03:58 2011 +0100

    Merge remote-tracking branch 'origin/master' into open_order_simulation

commit 54508f4973b0ef6526fff63b135410d00f8a9bfe
Merge: 2aa3ebe ab3ed488
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Tue Dec 13 15:45:55 2011 +0100

    Merge remote-tracking branch 'origin/master' into open_order_simulation

commit 2aa3ebe00c730b6cfa894bbdc4bcef14e6166269
Merge: 46fea37 d4400416
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Fri Dec 9 14:24:24 2011 +0100

    Merge remote-tracking branch 'origin/master' into open_order_simulation

commit 46fea37bcece360f412765ec035c631e250b18c8
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Dec 8 18:31:37 2011 +0100

    Add open order movement group class.

commit 7e6719d05f4dfa24478955bdd90a42e6e97acac7
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Dec 8 18:31:19 2011 +0100

    Fix allowed content type.

commit 20de320d675ed471bc44eb0b36b200aacf02ef80
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Dec 8 18:11:11 2011 +0100

    Add open order movement group and allow delivery builder access it.

commit eb95e06a311ca8815db73ec1b986c4f6cbd8b9a6
Merge: 72f669e 90b9a274
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Wed Dec 7 07:18:22 2011 +0100

    Merge branch 'master' into open_order_simulation

commit 72f669e1d5a9d48b595f719fd40b6bd96e5ba11a
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Mon Dec 5 16:57:40 2011 +0100

    Property should be fetch from parent simulation.

commit 504fd655711b7267ee14a234efedbdd4f066f491
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Mon Dec 5 16:46:40 2011 +0100

    Revert "Subscription Item does have order value, use explanation value instead."

    This reverts commit 8a9635f5209285b3e1d836dbf3365c2ef2cc7123.

commit 8a9635f5209285b3e1d836dbf3365c2ef2cc7123
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Mon Dec 5 16:19:50 2011 +0100

    Subscription Item does have order value, use explanation value instead.

commit ca5063ced202e5337140c9a92d5901c1cc96fab9
Merge: b1787b5 89aee418
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Dec 5 11:44:05 2011 +0100

    Merge branch 'master' into open_order_simulation

commit b1787b512efcd2d5f7a8c8ce873902e41c2d1c4c
Merge: d2b1a05 3ada0969
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Sat Dec 3 02:17:44 2011 +0100

    Merge branch 'master' into open_order_simulation

commit d2b1a05f4463ede8238d4d17014428e6cd88d055
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Dec 2 14:18:11 2011 +0100

    Fix date calculation.

commit 60692404c4a7a8d5c43f44eb2c27d98a5fddcce1
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Dec 1 12:47:47 2011 +0100

    Fix date calculation

commit 438adb2377fc26841a63c65896ccab2722d97946
Merge: 7945d45 f10ebb36
Author: Łukasz Nowak <luke@nexedi.com>
Date:   Mon Nov 28 13:56:43 2011 +0100

    Merge branch 'master' into open_order_simulation

commit 7945d45342fdc1f09b0de05c7352823545326d99
Merge: 6a69b7a 48124c43
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Sat Nov 26 18:16:07 2011 +0100

    Merge branch 'master' into open_order_simulation

commit 6a69b7a8349a1c56f553d26da992738ef5dc5b48
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 25 18:36:43 2011 +0100

    Return default value is no aggregated open order line exist.

commit 4c749bdde0465838cf7663eca587e1282b1f9374
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 22 13:23:09 2011 +0100

    Use getRuleReference, remove hard-coded value.

commit d52a204cddffff01ce0e7d294813ed0411c7766c
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 22 13:03:24 2011 +0100

    Hard code root applied rule now.

commit c9a909b584a73503beef933bcae45b59689ece32
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 22 13:02:10 2011 +0100

    Do not expand too early: before bp/stc is applied

commit 575005dd3972ec573675818ee380381de2331a2d
Author: Romain Courteaud <romain@nexedi.com>
Date:   Mon Nov 21 17:50:39 2011 +0100

    Force failures on some machines.

    Needed as interface inheritance is broken.

commit 80d5e37bb0665318d3cd800d336104493b0f21f4
Merge: 0cf8377 4c8b7ee5
Author: Romain Courteaud <romain@nexedi.com>
Date:   Fri Nov 18 13:46:44 2011 +0100

    Merge remote-tracking branch 'origin/master' into open_order_simulation

commit 0cf83778a9c51dd4252701347d9d04857819ce43
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 10:51:16 2011 +0100

    Revert "Do not expand if sale trade condition does not exist."

    This reverts commit ea06e261c689614af80590276ba15586abda1348.

    This shall not happen now, in another way, we should defines when to expand carefully.

commit 67dd1f0be80b11d4cd9ab3cee82c87f8ea471811
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 06:18:14 2011 +0100

    Revert "Trigger unit tests."

    This reverts commit 81a2502885a06cd13dde7aee797717b7e897a8b2.

commit 81a2502885a06cd13dde7aee797717b7e897a8b2
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 05:24:03 2011 +0100

    Trigger unit tests.

commit 4149abb483270439c5158aae9330b9c6e86097b0
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 05:13:18 2011 +0100

    Do not overwrite _setCategoryMembership

commit a8a225178d48186b912609a7e6d915a4e747aece
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 04:43:04 2011 +0100

    Do not delegate category other than specialise to open order line.

commit 1e00bd784ea2827c954a9f7e13ce01178d6c8a7a
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 04:30:30 2011 +0100

    Revert "For unit tests only, record call stack."

    This reverts commit a2671846ce735ea666e34091ac416bbf20c6ce15.

commit a2671846ce735ea666e34091ac416bbf20c6ce15
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 04:01:28 2011 +0100

    For unit tests only, record call stack.

commit 42f622b53ae51a068d0f959e744f24b0811c0786
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 03:56:20 2011 +0100

    Revert "Trigger unit tests."

    This reverts commit a522b1cde84ef18f3f7b8d92dcbb895172d96993.

commit a522b1cde84ef18f3f7b8d92dcbb895172d96993
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 02:45:06 2011 +0100

    Trigger unit tests.

commit ea06e261c689614af80590276ba15586abda1348
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 01:42:41 2011 +0100

    Do not expand if sale trade condition does not exist.

commit eea82556c875bab1274d79739644a5bab3dbb77b
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 01:17:15 2011 +0100

    Typo

commit f5af7b62aac3c495de50c0a8be532a9cf53f6680
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Fri Nov 18 00:27:53 2011 +0100

    Typo

commit f72a279c01a4b2fa7c06cf10258fd1eb433e9a0b
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Nov 17 22:46:13 2011 +0100

    get/set category membership.

commit 95c9d0729008bf9ed735f9e21b3e1008de5fbcf8
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Nov 17 21:40:59 2011 +0100

    fetch specialise value/value_list from open order line.

commit 9710f2ccc9be866198941ce71830fa653dab0a88
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Nov 17 17:39:24 2011 +0100

    Revert "This modification is used for testing. Should be reverted soon."

    This reverts commit 92e56f6ee437bc8c1504476f1c329230500ea613.

commit d7cab105694a2e8257fa346861391b77c32a2b22
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Nov 17 17:38:38 2011 +0100

    Expand method should have more power.

commit 92e56f6ee437bc8c1504476f1c329230500ea613
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Nov 17 16:02:52 2011 +0100

    This modification is used for testing. Should be reverted soon.

commit d71fcf1d48f5bd465098115b9770228715df5c4f
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Nov 17 11:01:26 2011 +0100

    Try new way to fetch category membership list from subscription item.

commit f3f3be5cdfce5d9a5475c057bff61f25809834b2
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Nov 17 10:50:59 2011 +0100

    Revert "These two are Movement."

    This reverts commit 235863c75040e7cb4a64486d6b9f1364fe53dc03.

commit 3a1894b6a2a497e172e7006bafb404817a9de50b
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Nov 17 10:50:17 2011 +0100

    Revert "Open Order is also a subclass of CompositionMixin."

    This reverts commit 699805e6750a7ba2ea019bce4627ecfc0fff0a54.

commit 6175d1bfd6a0e27f37735655a8cd8653bee96cf0
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Wed Nov 16 15:53:18 2011 +0100

    Proxy specialise value to related open order line.

commit 235863c75040e7cb4a64486d6b9f1364fe53dc03
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Wed Nov 16 11:07:28 2011 +0100

    These two are Movement.

commit b981d71f00ea39f29c8ab3ac6cfce49404910784
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Wed Nov 16 10:42:03 2011 +0100

    Revert "This is commit is used to trigger unit test bot."

    This reverts commit ae878074e8d981daf5e6215a2b8ff0b226914e81.

commit ae878074e8d981daf5e6215a2b8ff0b226914e81
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Wed Nov 16 10:41:16 2011 +0100

    This is commit is used to trigger unit test bot.

commit 699805e6750a7ba2ea019bce4627ecfc0fff0a54
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 15 14:47:20 2011 -0700

    Open Order is also a subclass of CompositionMixin.

commit e850630030a88c7986c08c3ae73e57d276b6b9cd
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 15 18:08:47 2011 +0100

    Override CompositionMixin so asComposedDocuemtn works properly on SI.

commit a2340f512b418e346a8135fb8ea45d2da8546316
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 15 16:51:26 2011 +0100

    Subclass composition mixin.

commit 6779322f13ebd0e05f7e44ea8a8755cb26bf4791
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 15 14:55:59 2011 +0100

    Typo

commit 57c90b14c8d472e5d33929a95acb7e72b61ec00e
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 15 11:59:42 2011 +0100

    Obtain many properties from aggregated open sale order line.

commit d547baeb1e4acaf966bd59605eca670435de98b3
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 15 11:34:09 2011 +0100

    Add price currency to simulation.

commit b215fee3ee46f78b8cfa3e9fd22dc2a2bbf14958
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 15 11:31:11 2011 +0100

    Remove trailing whitespaces.

commit e9b31fd9d0de1e5fc6095dabba5ad5645ad84473
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Mon Nov 14 16:21:59 2011 +0100

    Proxy manager role temporarily.

commit 325308ac3e26a98091689b9b773669afdf080c2e
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 8 18:06:32 2011 +0100

    Revert "Normalize datetime to 00:00"

    This reverts commit b56a572fb430ae6d9611dae2bd8ecfca687fe40f.

    This one should not be changed here.

commit b56a572fb430ae6d9611dae2bd8ecfca687fe40f
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Nov 8 17:28:57 2011 +0100

    Normalize datetime to 00:00

commit 44f6c6ee8522ea407c5a5a3f18125dad2c6d6a97
Author: Romain Courteaud <romain@nexedi.com>
Date:   Tue Nov 8 14:55:00 2011 +0100

    Fetch date information from Open Sale Order Line

commit 3725c719c555124841f34b38ef83a260d1b3084c
Author: Romain Courteaud <romain@nexedi.com>
Date:   Tue Nov 8 14:33:03 2011 +0100

    Copy/Paste code from Delivery to create the applied rule

commit 1276774789db8a2f55ec09aece3d1846e82b0601
Author: Romain Courteaud <romain@nexedi.com>
Date:   Tue Nov 8 14:24:22 2011 +0100

    Add getRuleReference on Subscription Item

commit 3d9f1304ed9749105b95d904defa5b70275016bb
Merge: f23828d 82f3de6e
Author: Romain Courteaud <romain@nexedi.com>
Date:   Tue Nov 8 13:27:48 2011 +0100

    Merge remote-tracking branch 'origin/master' into open_order_simulation

commit f23828df3c3995e92255330ff4ab9a546573edb5
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Mon Nov 7 23:45:05 2011 +0100

    Revert to old Subscription Item.

commit 0d9299134dc72e20ba433a9bc2286828fd8d315d
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Oct 27 11:01:42 2011 +0200

    Update rule selection method.

commit 1a0fcf9cd8f9fc176a64d4cf4684dc2abaf1aa7b
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Oct 27 06:06:31 2011 +0200

    Implement IExpandableItem interface.

commit 58f7ca0a6421729b94d63e415a3641af621d35b3
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Oct 27 05:26:47 2011 +0200

    Simulation Error is missing.

commit 314d6ecf375c273d578fc794ae3bfa9885d0a637
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Oct 27 05:08:09 2011 +0200

    Typo.

commit 92167ea712528ad199c259d64da4d665fdde3e62
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Thu Oct 27 04:45:55 2011 +0200

    Rewrite subscription item.

commit 0183acaabdc2d27906b5434ae3a48d13bdea3f4e
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Tue Oct 25 13:04:01 2011 +0200

    Remove useless log.

commit 1e9d7b9d4282a9bb38f9cacf5e129efeb53e98e5
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Mon Oct 24 17:55:52 2011 +0200

    Adapt Subscription Item with current business process. However, it should be decoupled later.

commit ba6f52255a4d4d618c13ead14d1b05ed9995f2cc
Author: Yingjie Xu <yxu@nexedi.com>
Date:   Mon Oct 24 11:47:33 2011 +0200

    Update ignorant files list.
parent c092cb6f
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<ZopeData> <ZopeData>
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<global name="ERP5TypeInformation" module="Products.ERP5Type.ERP5Type"/> <global name="Base Type" module="erp5.portal_type"/>
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
...@@ -111,6 +111,18 @@ to Simulation Movements related to a limited set of existing Deliveries.</string ...@@ -111,6 +111,18 @@ to Simulation Movements related to a limited set of existing Deliveries.</string
<key> <string>type_class</string> </key> <key> <string>type_class</string> </key>
<value> <string>SimulatedDeliveryBuilder</string> </value> <value> <string>SimulatedDeliveryBuilder</string> </value>
</item> </item>
<item>
<key> <string>type_interface</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>type_mixin</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
...@@ -122,7 +134,9 @@ to Simulation Movements related to a limited set of existing Deliveries.</string ...@@ -122,7 +134,9 @@ to Simulation Movements related to a limited set of existing Deliveries.</string
<dictionary> <dictionary>
<item> <item>
<key> <string>domain_name</string> </key> <key> <string>domain_name</string> </key>
<value> <none/> </value> <value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>property_name</string> </key> <key> <string>property_name</string> </key>
...@@ -139,7 +153,9 @@ to Simulation Movements related to a limited set of existing Deliveries.</string ...@@ -139,7 +153,9 @@ to Simulation Movements related to a limited set of existing Deliveries.</string
<dictionary> <dictionary>
<item> <item>
<key> <string>domain_name</string> </key> <key> <string>domain_name</string> </key>
<value> <none/> </value> <value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>property_name</string> </key> <key> <string>property_name</string> </key>
......
1002 1005
\ No newline at end of file
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
for open_order_line in context.contentValues():\n for open_order_line in context.contentValues():\n
for path in [open_order_line] + open_order_line.getCellValueList():\n for path in [open_order_line] + open_order_line.getCellValueList():\n
for item in path.getAggregateValueList():\n for item in path.getAggregateValueList():\n
if item.providesIExpandable():\n if item.providesIExpandableItem(): # XXX hack to make it fails\n
subscription_item_dict[item] = 1\n subscription_item_dict[item] = 1\n
\n \n
# XXX tag / after tag !\n # XXX tag / after tag !\n
...@@ -72,6 +72,14 @@ for item in subscription_item_dict:\n ...@@ -72,6 +72,14 @@ for item in subscription_item_dict:\n
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>OpenOrder_updateSimulation</string> </value> <value> <string>OpenOrder_updateSimulation</string> </value>
......
102 104
\ No newline at end of file
...@@ -102,6 +102,8 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin): ...@@ -102,6 +102,8 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
# deliveryValue # deliveryValue
# * price_currency from the top level simulation movement's # * price_currency from the top level simulation movement's
# orderValue # orderValue
resource = input_movement.getPriceCurrency()
if resource is None:
invoice_line = input_movement.getDeliveryValue() invoice_line = input_movement.getDeliveryValue()
if invoice_line is None: if invoice_line is None:
resource = None resource = None
......
...@@ -55,7 +55,4 @@ class OrderMovementGroup(MovementGroup): ...@@ -55,7 +55,4 @@ class OrderMovementGroup(MovementGroup):
return # This is a temp movement return # This is a temp movement
# This is a simulation movement # This is a simulation movement
getCausality = getRootAppliedRule().getCausality getCausality = getRootAppliedRule().getCausality
return (getCausality(portal_type=movement.getPortalOrderTypeList()) or return getCausality()
# In some cases (ex. DeliveryRule), there is no order
# we may consider a PackingList as the order in the OrderGroup
getCausality(portal_type=movement.getPortalDeliveryTypeList()))
...@@ -34,12 +34,15 @@ from Products.CMFCore.utils import getToolByName ...@@ -34,12 +34,15 @@ from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Errors import SimulationError from Products.ERP5Type.Errors import SimulationError
from Products.ERP5.Document.Item import Item from Products.ERP5.Document.Item import Item
from Products.ERP5.mixin.composition import CompositionMixin
from Products.ERP5.mixin.rule import MovementGeneratorMixin from Products.ERP5.mixin.rule import MovementGeneratorMixin
from Products.ERP5.mixin.periodicity import PeriodicityMixin from Products.ERP5.mixin.periodicity import PeriodicityMixin
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5Type.Base import Base
from zLOG import LOG from zLOG import LOG
class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin): class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, PeriodicityMixin):
""" """
A SubscriptionItem is an Item which expands itself A SubscriptionItem is an Item which expands itself
into simulation movements which represent the item future. into simulation movements which represent the item future.
...@@ -72,6 +75,7 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin): ...@@ -72,6 +75,7 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin):
) )
# IExpandable interface implementation # IExpandable interface implementation
@UnrestrictedMethod # YXU - Is it a good permission setting?
def expand(self, applied_rule_id=None, activate_kw=None, **kw): def expand(self, applied_rule_id=None, activate_kw=None, **kw):
""" """
Lookup start / stop properties in related Open Order Lookup start / stop properties in related Open Order
...@@ -81,6 +85,10 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin): ...@@ -81,6 +85,10 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin):
if self.getValidationState() in ('draft', ): # XXX-JPS harcoded if self.getValidationState() in ('draft', ): # XXX-JPS harcoded
return return
# do not expand if no bp/stc is applied
if self.getSpecialiseValue() is None:
return
# use hint if provided (but what for ?) XXX-JPS # use hint if provided (but what for ?) XXX-JPS
if applied_rule_id is not None: if applied_rule_id is not None:
portal_simulation = getToolByName(self, 'portal_simulation') portal_simulation = getToolByName(self, 'portal_simulation')
...@@ -112,6 +120,93 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin): ...@@ -112,6 +120,93 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin):
""" """
return False return False
def getRuleReference(self):
"""Returns an appropriate rule reference.
XXX Copy/Paste from delivery
"""
method = self._getTypeBasedMethod('getRuleReference')
if method is not None:
return method()
else:
raise SimulationError('%s_getRuleReference script is missing.'
% self.getPortalType().replace(' ', ''))
@UnrestrictedMethod # XXX-JPS What is this ?
def updateAppliedRule(self, rule_reference=None, rule_id=None, **kw):
"""
Create a new Applied Rule if none is related, or call expand
on the existing one.
The chosen applied rule will be the validated rule with reference ==
rule_reference, and the higher version number.
"""
if rule_id is not None:
from warnings import warn
warn('rule_id to updateAppliedRule is deprecated; use rule_reference instead',
DeprecationWarning)
rule_reference = rule_id
if rule_reference is None:
return
portal_rules = getToolByName(self, 'portal_rules')
res = portal_rules.searchFolder(reference=rule_reference,
validation_state="validated", sort_on='version',
sort_order='descending') # XXX validated is Hardcoded !
if len(res) > 0:
rule_id = res[0].getId()
else:
raise ValueError, 'No such rule as %r is found' % rule_reference
self._createAppliedRule(rule_id, **kw)
def _createAppliedRule(self, rule_id, activate_kw=None, **kw):
"""
Create a new Applied Rule is none is related, or call expand
on the existing one.
"""
# Look up if existing applied rule
my_applied_rule_list = self.getCausalityRelatedValueList(
portal_type='Applied Rule')
my_applied_rule = None
if len(my_applied_rule_list) == 0:
if self.isSimulated():
# No need to create a DeliveryRule
# if we are already in the simulation process
pass
else:
# Create a new applied order rule (portal_rules.order_rule)
portal_rules = getToolByName(self, 'portal_rules')
portal_simulation = getToolByName(self, 'portal_simulation')
my_applied_rule = portal_rules[rule_id].\
constructNewAppliedRule(portal_simulation,
activate_kw=activate_kw)
# Set causality
my_applied_rule.setCausalityValue(self)
# We must make sure this rule is indexed
# now in order not to create another one later
my_applied_rule.reindexObject(activate_kw=activate_kw, **kw)
elif len(my_applied_rule_list) == 1:
# Re expand the rule if possible
my_applied_rule = my_applied_rule_list[0]
else:
raise SimulationError('Delivery %s has more than one applied'
' rule.' % self.getRelativeUrl())
my_applied_rule_id = None
expand_activate_kw = {}
if my_applied_rule is not None:
my_applied_rule_id = my_applied_rule.getId()
expand_activate_kw['after_path_and_method_id'] = (
my_applied_rule.getPath(),
['immediateReindexObject', 'recursiveImmediateReindexObject'])
# We are now certain we have a single applied rule
# It is time to expand it
self.activate(activate_kw=activate_kw, **expand_activate_kw).expand(
applied_rule_id=my_applied_rule_id,
activate_kw=activate_kw, **kw)
def _getRootAppliedRule(self, tested_base_category_list=None, def _getRootAppliedRule(self, tested_base_category_list=None,
activate_kw=None): activate_kw=None):
""" """
...@@ -131,8 +226,11 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin): ...@@ -131,8 +226,11 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin):
# Create a new applied order rule (portal_rules.order_rule) # Create a new applied order rule (portal_rules.order_rule)
portal_rules = getToolByName(self, 'portal_rules') portal_rules = getToolByName(self, 'portal_rules')
portal_simulation = getToolByName(self, 'portal_simulation') portal_simulation = getToolByName(self, 'portal_simulation')
if self.getRuleReference() is None:
rule_value_list = portal_rules.searchRuleList(self, rule_value_list = portal_rules.searchRuleList(self,
tested_base_category_list=tested_base_category_list) tested_base_category_list=tested_base_category_list)
else:
rule_value_list = [portal_rules[self.getRuleReference()]]
if len(rule_value_list) > 1: if len(rule_value_list) > 1:
raise SimulationError('Expandable Document %s has more than one' raise SimulationError('Expandable Document %s has more than one'
' matching rule.' % self.getRelativeUrl()) ' matching rule.' % self.getRelativeUrl())
...@@ -177,35 +275,35 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin): ...@@ -177,35 +275,35 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin):
if not open_order_movement_list: if not open_order_movement_list:
return result return result
# Find out which parent open orders
explanation_uid_list = map(lambda x:x.getParentUid(), open_order_movement_list) # Instead, should call getDeliveryValue or equivalent
open_order_list = catalog_tool.searchResults(uid = explanation_uid_list,
validation_state = 'validated') # XXX-JPS hard coding
# Now generate movements for each valid open order # Now generate movements for each valid open order
for movement in open_order_movement_list: for movement in open_order_movement_list: # YXU-Why we have a list here?
if movement.getParentValue().getValidationState() in ('open', 'validated'): # XXX-JPS hard coding if movement.getParentValue().getValidationState() in ('open', 'validated'): # XXX-JPS hard coding
resource = movement.getResource() resource = movement.getResource()
start_date = movement.getStartDateRangeMin() # Is this appropriate ? start_date = movement.getStartDate()
stop_date = movement.getStartDateRangeMax() # Is this appropriate ? stop_date = movement.getStopDate()
source = movement.getSource() source = movement.getSource()
source_section = movement.getSourceSection() source_section = movement.getSourceSection()
destination = movement.getDestination() destination = movement.getDestination()
destination_section = movement.getDestinationSection() # XXX More arrows ? use context instead ? destination_section = movement.getDestinationSection()
quantity = self.getQuantity() # Is it so ? XXX-JPS quantity = movement.getQuantity()
quantity_unit = movement.getQuantityUnit() quantity_unit = movement.getQuantityUnit()
price = movement.getPrice() price = movement.getPrice()
price_currency = movement.getPriceCurrency()
specialise = movement.getSpecialise() specialise = movement.getSpecialise()
current_date = self.getNextPeriodicalDate(start_date) current_date = start_date
id_index = 0 id_index = 0
while current_date < stop_date: while current_date < stop_date:
next_date = self.getNextPeriodicalDate(current_date) next_date = self.getNextPeriodicalDate(current_date)
if next_date > stop_date:
next_date = stop_date
generated_movement = newTempMovement(self, 'subscription_%s' % id_index) generated_movement = newTempMovement(self, 'subscription_%s' % id_index)
generated_movement._edit( aggregate_value=self, generated_movement._edit( aggregate_value=self,
resource=resource, resource=resource,
quantity=quantity, quantity=quantity,
quantity_unit=quantity_unit, quantity_unit=quantity_unit,
price=price, price=price,
price_currency=price_currency,
start_date=current_date, start_date=current_date,
stop_date=next_date, stop_date=next_date,
source=source, source=source,
...@@ -213,11 +311,111 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin): ...@@ -213,11 +311,111 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin):
destination=destination, destination=destination,
destination_section=destination_section, destination_section=destination_section,
specialise=specialise, specialise=specialise,
# delivery_value=movement # ??? to be confirmed - if we want order step or not
) )
result.append(generated_movement) result.append(generated_movement)
current_date = next_date current_date = next_date
id_index += 1 id_index += 1
# And now return result
return result return result
# XXX BELOW HACKS
def getResource(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getResource()
def getStartDate(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getStartDate()
def getStopDate(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getStopDate()
def getSource(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getSource()
def getSourceSection(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getSourceSection()
def getDestination(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getDestination()
def getDestinationSection(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getDestinationSection()
def getQuantity(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getQuantity()
def getQuantityUnit(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getQuantityUnit()
def getPrice(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getPrice()
def getPriceCurrency(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getPriceCurrency()
def getSpecialise(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getSpecialise()
def getSpecialiseList(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return []
return open_order_line.getSpecialiseList()
def getSpecialiseValue(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return None
return open_order_line.getSpecialiseValue()
def getSpecialiseValueList(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
if open_order_line is None:
return []
return open_order_line.getSpecialiseValueList()
def _getCategoryMembershipList(self, category, spec=(), filter=None,
portal_type=(), base=0, keep_default=1, checked_permission=None, **kw):
if category == 'specialise':
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
return open_order_line._getCategoryMembershipList(category, spec=spec, filter=filter,
portal_type=portal_type, base=base, keep_default=keep_default,
checked_permission=checked_permission, **kw)
return Base._getCategoryMembershipList(self, category, spec=spec, filter=filter,
portal_type=portal_type, base=base, keep_default=keep_default,
checked_permission=checked_permission, **kw)
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