Commit aee27173 authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Romain Courteaud

Support multiple open order line with the same effective_date.

If 2 lines have the same effective date (catalog has a 1 second precision),
always return the validate and open first.

Commit: 02d06501ce38bc24d5d045968a53017d9b96b312

Changes applied from history:

http://git.erp5.org/gitweb/erp5.git/history/refs/heads/interaction-drop:/product/ERP5/Document/SubscriptionItem.py?js=1
parent 8ab25eaf
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from erp5.component.document.Item import Item from erp5.component.document.Item import Item
from erp5.component.mixin.CompositionMixin import CompositionMixin from erp5.component.mixin.CompositionMixin import CompositionMixin
...@@ -107,19 +108,24 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, ...@@ -107,19 +108,24 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin,
of resource, ie. float or unit) of resource, ie. float or unit)
""" """
result = [] result = []
catalog_tool = getToolByName(self, 'portal_catalog')
# Try to find the source open order # Try to find the source open order
open_order_movement_list = self.getAggregateRelatedValueList( for movement in catalog_tool(portal_type="Open Sale Order Line",
portal_type="Open Sale Order Line") # XXX-JPS Hard Coded default_aggregate_uid=self.getUid(),
if not open_order_movement_list: validation_state=('open', 'validated', 'archived'), # XXX-JPS hard coding
return result sort_on=(('effective_date', 'descending'),
# Do not return archived if effective dates are identical
# Now generate movements for each valid open order ('validation_state', 'descending')),
for movement in open_order_movement_list: # YXU-Why we have a list here? limit=1 # Note Luke: Support the newest Open Order which defines
if movement.getParentValue().getValidationState() in ('open', 'validated'): # XXX-JPS hard coding # something for current subscription item
): # YXU-Why we have a list here?
resource = movement.getResource() resource = movement.getResource()
start_date = movement.getStartDate() start_date = movement.getStartDate()
stop_date = movement.getStopDate() stop_date = movement.getStopDate()
if start_date is None or stop_date is None or start_date>=stop_date:
# infinity nor time back machine does not exist
continue
source = movement.getSource() source = movement.getSource()
source_section = movement.getSourceSection() source_section = movement.getSourceSection()
source_decision = movement.getSourceDecision() source_decision = movement.getSourceDecision()
...@@ -139,8 +145,6 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, ...@@ -139,8 +145,6 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin,
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 = self.newContent(temp_object=True, generated_movement = self.newContent(temp_object=True,
portal_type='Movement', portal_type='Movement',
id='subscription_%s' % id_index) id='subscription_%s' % id_index)
......
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