Commit c77d34e3 authored by Łukasz Nowak's avatar Łukasz Nowak

- remove finished TODOs

 - reformat to use 2 spaces indentation


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27651 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6afe4333
...@@ -46,193 +46,187 @@ def isMovement(document): ...@@ -46,193 +46,187 @@ def isMovement(document):
return is_movement return is_movement
class TradeModelLine(Predicate, XMLMatrix, Amount): class TradeModelLine(Predicate, XMLMatrix, Amount):
"""Trade Model Line is a way to represent trade transformation for movements """Trade Model Line is a way to represent trade transformation for movements"""
meta_type = 'ERP5 Trade Model Line'
TODO: portal_type = 'Trade Model Line'
- make this code readable
- use comments # Declarative security
- use doctrings security = ClassSecurityInfo()
""" security.declareObjectProtected(Permissions.AccessContentsInformation)
meta_type = 'ERP5 Trade Model Line'
portal_type = 'Trade Model Line' # Declarative interfaces
zope.interface.implements(
# Declarative security interfaces.ITransformation,
security = ClassSecurityInfo() interfaces.IVariated
security.declareObjectProtected(Permissions.AccessContentsInformation) )
# Declarative interfaces # Declarative properties
zope.interface.implements( property_sheets = ( PropertySheet.Base
interfaces.ITransformation, , PropertySheet.SimpleItem
interfaces.IVariated , PropertySheet.CategoryCore
) , PropertySheet.Amount
, PropertySheet.Price
# Declarative properties , PropertySheet.TradeModelLine
property_sheets = ( PropertySheet.Base , PropertySheet.Reference
, PropertySheet.SimpleItem , PropertySheet.Predicate
, PropertySheet.CategoryCore )
, PropertySheet.Amount
, PropertySheet.Price security.declareProtected(Permissions.AccessContentsInformation,
, PropertySheet.TradeModelLine 'getPrice')
, PropertySheet.Reference def getPrice(self):
, PropertySheet.Predicate return self._baseGetPrice()
)
def updateAggregatedAmountList(self, context, **kw):
security.declareProtected(Permissions.AccessContentsInformation, raise NotImplementedError('TODO')
'getPrice')
def getPrice(self): security.declareProtected(Permissions.AccessContentsInformation,
return self._baseGetPrice() 'getAggregatedAmountList')
def getAggregatedAmountList(self, context, movement_list = None,
def updateAggregatedAmountList(self, context, **kw): current_aggregated_amount_list = None, base_id='movement', **kw):
raise NotImplementedError('TODO') from Products.ERP5Type.Document import newTempSimulationMovement
security.declareProtected(Permissions.AccessContentsInformation, # test with predicate if this model line could be applied
'getAggregatedAmountList') if not self.test(context):
def getAggregatedAmountList(self, context, movement_list = None, # This model_line should not be applied
current_aggregated_amount_list = None, base_id='movement', **kw): return []
from Products.ERP5Type.Document import newTempSimulationMovement if movement_list is None:
movement_list = []
# test with predicate if this model line could be applied if current_aggregated_amount_list is None:
if not self.test(context): current_aggregated_amount_list = []
# This model_line should not be applied
return [] normal_resource_use_category_list = self.\
if movement_list is None: portal_preferences.getPreferredNormalResourceUseCategoryList()
movement_list = [] if normal_resource_use_category_list is None:
if current_aggregated_amount_list is None: raise ValueError('preferred_normal_resource_use_category is not ' + \
current_aggregated_amount_list = [] 'configured in System Preferences')
normal_resource_use_category_list = self.\ # if movement_list is passed as parameter, it shall be used,
portal_preferences.getPreferredNormalResourceUseCategoryList() # otherwise it is needed to look up for movements
if normal_resource_use_category_list is None: if len(movement_list) == 0:
raise ValueError('preferred_normal_resource_use_category is not ' + \ # no movements passed, need to find some
'configured in System Preferences') if isMovement(context):
# create movement lists from context
# if movement_list is passed as parameter, it shall be used, movement_list = [context]
# otherwise it is needed to look up for movements
if len(movement_list) == 0:
# no movements passed, need to find some
if isMovement(context):
# create movement lists from context
movement_list = [context]
else:
# create movement list for delivery's movements
movement_list = []
for movement in context.getMovementList():
# XXX: filtering shall be in getMovementList
# add only movement which are input (i.e. resource use category
# is in the normal resource use preference list). Output will
# be recalculated
movement_resource = movement.getResourceValue()
if movement_resource is not None:
if movement_resource.getUse() in \
normal_resource_use_category_list:
movement_list.append(movement)
aggregated_amount_list = AggregatedAmountList()
base_application_list = self.getBaseApplicationList()
self_id = self.getParentValue().getId() + '_' + self.getId()
tmp_movement_list = [q for q in current_aggregated_amount_list \
if q.getReference() == self.getReference() ]
if len(tmp_movement_list) > 0:
tmp_movement_list = tmp_movement_list[:1] # list is needed in case of
# having cells
update = 1
else: else:
common_params = { # create movement list for delivery's movements
'causality': self.getRelativeUrl(), movement_list = []
'resource': self.getResource(), for movement in context.getMovementList():
'reference': self.getReference(), # XXX: filtering shall be in getMovementList
'base_application_list': base_application_list, # add only movement which are input (i.e. resource use category
'base_contribution_list': self.getBaseContributionList(), # is in the normal resource use preference list). Output will
'start_date': context.getStartDate(), # be recalculated
'stop_date': context.getStopDate(), movement_resource = movement.getResourceValue()
'create_line': self.isCreateLine(), if movement_resource is not None:
'trade_phase_list': self.getTradePhaseList(), if movement_resource.getUse() in \
} normal_resource_use_category_list:
update = 0 movement_list.append(movement)
base_category_list = self.getVariationBaseCategoryList()
category_list_list = [] aggregated_amount_list = AggregatedAmountList()
for base_cat in base_category_list: base_application_list = self.getBaseApplicationList()
category_list = self.getVariationCategoryList(
base_category_list=base_cat) self_id = self.getParentValue().getId() + '_' + self.getId()
category_list_list.append(category_list)
cartesian_product = cartesianProduct(category_list_list) tmp_movement_list = [q for q in current_aggregated_amount_list \
# look for cells if categories are used if q.getReference() == self.getReference() ]
if len(category_list_list) > 0: if len(tmp_movement_list) > 0:
for cell_coordinates in cartesian_product: tmp_movement_list = tmp_movement_list[:1] # list is needed in case of
cell = self.getCell(base_id=base_id, *cell_coordinates) # having cells
if cell is None: update = 1
raise ValueError("Can't find the cell corresponding to those "+\ else:
"cells coordinates : %s" % cell_coordinates) common_params = {
tmp_movement = newTempSimulationMovement(self.getPortalObject(), 'causality': self.getRelativeUrl(),
self_id) 'resource': self.getResource(),
tmp_movement.edit( 'reference': self.getReference(),
variation_base_category_list = cell.getVariationBaseCategoryList(), 'base_application_list': base_application_list,
variation_category_list = cell.getVariationCategoryList(), 'base_contribution_list': self.getBaseContributionList(),
price = cell.getPrice(), 'start_date': context.getStartDate(),
quantity = cell.getQuantity(0.0), 'stop_date': context.getStopDate(),
**common_params 'create_line': self.isCreateLine(),
) 'trade_phase_list': self.getTradePhaseList(),
tmp_movement_list.append(tmp_movement) }
else: update = 0
tmp_movement = newTempSimulationMovement(self.getPortalObject(), base_category_list = self.getVariationBaseCategoryList()
self_id, category_list_list = []
quantity = self.getQuantity(0.0), for base_cat in base_category_list:
price = self.getPrice(), category_list = self.getVariationCategoryList(
**common_params base_category_list=base_cat)
) category_list_list.append(category_list)
tmp_movement_list.append(tmp_movement) cartesian_product = cartesianProduct(category_list_list)
modified = 0 # look for cells if categories are used
for tmp_movement in tmp_movement_list: if len(category_list_list) > 0:
if len(self.getVariationCategoryList()) == 0 and \ for cell_coordinates in cartesian_product:
self.getQuantity(None) is None or \ cell = self.getCell(base_id=base_id, *cell_coordinates)
len(self.getVariationCategoryList()) and \
tmp_movement.getQuantity(None) is None:
# if the quantity is not defined, take it by searching all movements
# that used this base_amount
for movement in movement_list:
if set(base_application_list)\
.intersection(set(movement.getBaseContributionList())) and \
len(movement.getVariationCategoryList()) == 0 or \
set(movement.getVariationCategoryList()).intersection( \
set(tmp_movement.getVariationCategoryList())):
# at least one base application is in base contributions and
# if the movement have no variation category, it's the same as
# if he have all variation categories
quantity = tmp_movement.getQuantity(0.0)
modified = 1
tmp_movement.setQuantity(quantity + movement.getTotalPrice())
else:
# if the quantity is defined, use it
modified = 1
if tmp_movement.getPrice() in (0, None):
# if price is not defined, it the same as 100 %
tmp_movement.setPrice(1)
# check if slices are used
salary_range_list = tmp_movement.getVariationCategoryList(\
base_category_list='salary_range') #XXX hardcoded values
salary_range = len(salary_range_list) and salary_range_list[0] or None
if salary_range is not None:
# slice are used
model = self.getParentValue()
cell = model.getCell(salary_range)
if cell is None: if cell is None:
raise ValueError("Can't find the cell corresponding to those "+\ raise ValueError("Can't find the cell corresponding to those "+\
"cells coordinates : %s" % salary_range) "cells coordinates : %s" % cell_coordinates)
model_slice_min = cell.getQuantityRangeMin() tmp_movement = newTempSimulationMovement(self.getPortalObject(),
model_slice_max = cell.getQuantityRangeMax() self_id)
base_application = tmp_movement.getQuantity(0.0) tmp_movement.edit(
if base_application-model_slice_min>0: variation_base_category_list = cell.getVariationBaseCategoryList(),
if base_application <= model_slice_max: variation_category_list = cell.getVariationCategoryList(),
tmp_movement.setQuantity(base_application-model_slice_min) price = cell.getPrice(),
elif model_slice_max: quantity = cell.getQuantity(0.0),
tmp_movement.setQuantity(model_slice_max-model_slice_min) **common_params
)
if not update and modified: tmp_movement_list.append(tmp_movement)
# no movements were updated, but something was modified, so new else:
# movement appeared tmp_movement = newTempSimulationMovement(self.getPortalObject(),
aggregated_amount_list.append(tmp_movement) self_id,
quantity = self.getQuantity(0.0),
return aggregated_amount_list price = self.getPrice(),
**common_params
)
tmp_movement_list.append(tmp_movement)
modified = 0
for tmp_movement in tmp_movement_list:
if len(self.getVariationCategoryList()) == 0 and \
self.getQuantity(None) is None or \
len(self.getVariationCategoryList()) and \
tmp_movement.getQuantity(None) is None:
# if the quantity is not defined, take it by searching all movements
# that used this base_amount
for movement in movement_list:
if set(base_application_list)\
.intersection(set(movement.getBaseContributionList())) and \
len(movement.getVariationCategoryList()) == 0 or \
set(movement.getVariationCategoryList()).intersection( \
set(tmp_movement.getVariationCategoryList())):
# at least one base application is in base contributions and
# if the movement have no variation category, it's the same as
# if he have all variation categories
quantity = tmp_movement.getQuantity(0.0)
modified = 1
tmp_movement.setQuantity(quantity + movement.getTotalPrice())
else:
# if the quantity is defined, use it
modified = 1
if tmp_movement.getPrice() in (0, None):
# if price is not defined, it the same as 100 %
tmp_movement.setPrice(1)
# check if slices are used
salary_range_list = tmp_movement.getVariationCategoryList(\
base_category_list='salary_range') #XXX hardcoded values
salary_range = len(salary_range_list) and salary_range_list[0] or None
if salary_range is not None:
# slice are used
model = self.getParentValue()
cell = model.getCell(salary_range)
if cell is None:
raise ValueError("Can't find the cell corresponding to those "+\
"cells coordinates : %s" % salary_range)
model_slice_min = cell.getQuantityRangeMin()
model_slice_max = cell.getQuantityRangeMax()
base_application = tmp_movement.getQuantity(0.0)
if base_application-model_slice_min>0:
if base_application <= model_slice_max:
tmp_movement.setQuantity(base_application-model_slice_min)
elif model_slice_max:
tmp_movement.setQuantity(model_slice_max-model_slice_min)
if not update and modified:
# no movements were updated, but something was modified, so new
# movement appeared
aggregated_amount_list.append(tmp_movement)
return aggregated_amount_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