Commit b13ff9a6 authored by Romain Courteaud's avatar Romain Courteaud

erp5_open_trade: SubscriptionItem: many improvements

* copy all aggregate values
* expand source/destination project defined on the open order
* expand source/destination payment
* support Open Order Cell
* if there is no stop_date, block the generation to today
parent aee27173
...@@ -39,6 +39,7 @@ from erp5.component.mixin.MovementGeneratorMixin import MovementGeneratorMixin ...@@ -39,6 +39,7 @@ from erp5.component.mixin.MovementGeneratorMixin import MovementGeneratorMixin
from Products.ERP5.mixin.periodicity import PeriodicityMixin from Products.ERP5.mixin.periodicity import PeriodicityMixin
from Products.ERP5Type.Base import Base from Products.ERP5Type.Base import Base
from erp5.component.interface.IMovementGenerator import IMovementGenerator from erp5.component.interface.IMovementGenerator import IMovementGenerator
from DateTime import DateTime
@zope.interface.implementer(IMovementGenerator,) @zope.interface.implementer(IMovementGenerator,)
class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin,
...@@ -99,6 +100,29 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, ...@@ -99,6 +100,29 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin,
# Default implementation bellow can be overriden by subclasses # Default implementation bellow can be overriden by subclasses
return {} return {}
def _getLatestOpenOrderPath(self):
catalog_tool = getToolByName(self, 'portal_catalog')
# Try to find the source open order
line_list = catalog_tool(
portal_type=["Open Sale Order Line", "Open Sale Order Cell"],
aggregate__uid=self.getUid(),
validation_state=('open', 'validated', 'archived'), # XXX-JPS hard coding
sort_on=(('effective_date', 'descending'),
# Do not return archived if effective dates are identical
('validation_state', 'descending')),
limit=1 # Note Luke: Support the newest Open Order which defines
# something for current subscription item
)
"""
if line.hasCellContent(base_id='path'):
movement_list = line.getCellValueList(base_id='path')
else:
movement_list = [line]
"""
if len(line_list) == 1:
return line_list[0]
return None
def _getInputMovementList(self, movement_list=None, rounding=None): def _getInputMovementList(self, movement_list=None, rounding=None):
""" """
Generate the list of input movements by looking at all Generate the list of input movements by looking at all
...@@ -108,38 +132,45 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, ...@@ -108,38 +132,45 @@ 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 movement = self._getLatestOpenOrderPath()
for movement in catalog_tool(portal_type="Open Sale Order Line", if movement is not None:
default_aggregate_uid=self.getUid(),
validation_state=('open', 'validated', 'archived'), # XXX-JPS hard coding
sort_on=(('effective_date', 'descending'),
# Do not return archived if effective dates are identical
('validation_state', 'descending')),
limit=1 # Note Luke: Support the newest Open Order which defines
# 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()
# if there is no stop_date, block the generation
# to today
stop_date = movement.getStopDate() stop_date = movement.getStopDate()
if start_date is None or stop_date is None or start_date>=stop_date: if (start_date == stop_date) or (stop_date is None):
# stop_date seems acquired from start_date
stop_date = DateTime()
if (start_date is None) or (stop_date < start_date):
# infinity nor time back machine does not exist # infinity nor time back machine does not exist
continue return result
source = movement.getSource() source = movement.getSource()
source_section = movement.getSourceSection() source_section = movement.getSourceSection()
source_project = movement.getSourceProject()
source_decision = movement.getSourceDecision() source_decision = movement.getSourceDecision()
source_payment = movement.getSourcePayment()
destination = movement.getDestination() destination = movement.getDestination()
destination_section = movement.getDestinationSection() destination_section = movement.getDestinationSection()
destination_project = movement.getDestinationProject()
destination_decision = movement.getDestinationDecision() destination_decision = movement.getDestinationDecision()
destination_payment = movement.getDestinationPayment()
quantity = movement.getQuantity() quantity = movement.getQuantity()
quantity_unit = movement.getQuantityUnit() quantity_unit = movement.getQuantityUnit()
price = movement.getPrice() price = movement.getPrice()
price_currency = movement.getPriceCurrency() price_currency = movement.getPriceCurrency()
# XXX no acquisition
base_application_list = movement.getBaseApplicationList() base_application_list = movement.getBaseApplicationList()
base_contribution_list = movement.getBaseContributionList() base_contribution_list = movement.getBaseContributionList()
# XXX no acquisition
use_list = movement.getUseList() use_list = movement.getUseList()
# XXX no acquisition
aggregate_list = movement.getAggregateList()
variation_category_list = movement.getVariationCategoryList()
# XXX no acquisition
specialise = movement.getSpecialise() specialise = movement.getSpecialise()
current_date = start_date current_date = start_date
id_index = 0 id_index = 0
...@@ -148,7 +179,7 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, ...@@ -148,7 +179,7 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin,
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)
generated_movement._edit( aggregate_value=self, generated_movement._edit( aggregate_list=aggregate_list,
resource=resource, resource=resource,
quantity=quantity, quantity=quantity,
quantity_unit=quantity_unit, quantity_unit=quantity_unit,
...@@ -158,14 +189,19 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, ...@@ -158,14 +189,19 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin,
stop_date=next_date, stop_date=next_date,
source=source, source=source,
source_section=source_section, source_section=source_section,
source_project=source_project,
source_decision=source_decision, source_decision=source_decision,
source_payment=source_payment,
destination=destination, destination=destination,
destination_section=destination_section, destination_section=destination_section,
destination_project=destination_project,
destination_decision=destination_decision, destination_decision=destination_decision,
destination_payment=destination_payment,
specialise=specialise, specialise=specialise,
base_application_list=base_application_list, base_application_list=base_application_list,
base_contribution_list=base_contribution_list, base_contribution_list=base_contribution_list,
use_list=use_list use_list=use_list,
variation_category_list=variation_category_list
) )
result.append(generated_movement) result.append(generated_movement)
current_date = next_date current_date = next_date
...@@ -175,91 +211,91 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, ...@@ -175,91 +211,91 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin,
# XXX BELOW HACKS # XXX BELOW HACKS
def getResource(self): def getResource(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getResource() return open_order_line.getResource()
def getStartDate(self): def getStartDate(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getStartDate() return open_order_line.getStartDate()
def getStopDate(self): def getStopDate(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getStopDate() return open_order_line.getStopDate()
def getSource(self): def getSource(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getSource() return open_order_line.getSource()
def getSourceSection(self): def getSourceSection(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getSourceSection() return open_order_line.getSourceSection()
def getDestination(self): def getDestination(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getDestination() return open_order_line.getDestination()
def getDestinationSection(self): def getDestinationSection(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getDestinationSection() return open_order_line.getDestinationSection()
def getQuantity(self): def getQuantity(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getQuantity() return open_order_line.getQuantity()
def getQuantityUnit(self, checked_permission=None): def getQuantityUnit(self, checked_permission=None):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getQuantityUnit(checked_permission=checked_permission) return open_order_line.getQuantityUnit(checked_permission=checked_permission)
def getPrice(self, context=None): def getPrice(self, context=None):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getPrice() return open_order_line.getPrice()
def getPriceCurrency(self): def getPriceCurrency(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getPriceCurrency() return open_order_line.getPriceCurrency()
def getSpecialise(self): def getSpecialise(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getSpecialise() return open_order_line.getSpecialise()
def getSpecialiseList(self): def getSpecialiseList(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return [] return []
return open_order_line.getSpecialiseList() return open_order_line.getSpecialiseList()
def getSpecialiseValue(self): def getSpecialiseValue(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return None return None
return open_order_line.getSpecialiseValue() return open_order_line.getSpecialiseValue()
def getSpecialiseValueList(self): def getSpecialiseValueList(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is None: if open_order_line is None:
return [] return []
return open_order_line.getSpecialiseValueList() return open_order_line.getSpecialiseValueList()
...@@ -275,7 +311,8 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, ...@@ -275,7 +311,8 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin,
checked_permission=None, checked_permission=None,
**kw): **kw):
if category == 'specialise': if category == 'specialise':
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self._getLatestOpenOrderPath()
if open_order_line is not None:
return open_order_line._getCategoryMembershipList(category, spec=spec, filter=filter, return open_order_line._getCategoryMembershipList(category, spec=spec, filter=filter,
portal_type=portal_type, base=base, keep_default=keep_default, portal_type=portal_type, base=base, keep_default=keep_default,
checked_permission=checked_permission, **kw) 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