Commit 34ee54aa authored by Julien Muchembled's avatar Julien Muchembled

Move local function out of a loop to avoid excessive indentation

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34643 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent faab72c9
...@@ -163,44 +163,28 @@ class AmountGeneratorMixin: ...@@ -163,44 +163,28 @@ class AmountGeneratorMixin:
raise ValueError( raise ValueError(
'context must implement IMovementCollection, IAmount or IAmountList') 'context must implement IMovementCollection, IAmount or IAmountList')
# Each amount in amount_list creates a new amount to take into account # First define the method that will browses recursively
# We thus need to start with a loop on amount_list # the amount generator lines and accumulate applicable values
for delivery_amount in amount_list: def accumulateAmountList(amount_generator_line):
# Initialize base_amount with per amount properties amount_generator_line_list = amount_generator_line.contentValues(
amount_property_dict = self._getAmountPropertyDict(delivery_amount, portal_type=self.getPortalAmountGeneratorLineTypeList())
amount_list=amount_list, rounding=rounding) # Recursively feed base_amount
base_amount.update(amount_property_dict) if len(amount_generator_line_list):
amount_generator_line_list.sort(key=lambda x: x.getIntIndex())
# Initialize base_amount with total_price for each amount applications for amount_generator_line in amount_generator_line_list:
#for application in delivery_amount.getBaseApplicationList(): # Acquired from Resource - XXX-JPS ? accumulateAmountList(amount_generator_line)
application_list = delivery_amount.getBaseContributionList() # or getBaseApplicationList ? return
if application_list: # Try to collect cells and aggregate their mapped properties
total_price = delivery_amount.getTotalPrice() # using resource + variation as aggregation key or base_application
for application in application_list: # Acquired from Resource - seems more normal # for intermediate lines
base_amount[application] = total_price amount_generator_cell_list = amount_generator_line.contentValues(
portal_type=self.getPortalAmountGeneratorCellTypeList())
# Browse recursively the trade model and accumulate if not amount_generator_cell_list:
# applicable values - first define the recursive method # Consider the line as the unique cell
def accumulateAmountList(amount_generator_line): amount_generator_cell_list = [amount_generator_line]
amount_generator_line_list = amount_generator_line.contentValues( resource_amount_aggregate = {} # aggregates final line information
portal_type=self.getPortalAmountGeneratorLineTypeList()) value_amount_aggregate = {} # aggregates intermediate line information
# Recursively feed base_amount for amount_generator_cell in amount_generator_cell_list:
if len(amount_generator_line_list):
amount_generator_line_list.sort(key=lambda x: x.getIntIndex())
for amount_generator_line in amount_generator_line_list:
accumulateAmountList(amount_generator_line)
return
# Try to collect cells and aggregate their mapped properties
# using resource + variation as aggregation key or base_application
# for intermediate lines
amount_generator_cell_list = amount_generator_line.contentValues(
portal_type=self.getPortalAmountGeneratorCellTypeList())
if not amount_generator_cell_list:
# Consider the line as the unique cell
amount_generator_cell_list = [amount_generator_line]
resource_amount_aggregate = {} # aggregates final line information
value_amount_aggregate = {} # aggregates intermediate line information
for amount_generator_cell in amount_generator_cell_list:
getBaseApplication = \ getBaseApplication = \
getattr(amount_generator_cell, 'getBaseApplication', None) getattr(amount_generator_cell, 'getBaseApplication', None)
if (getBaseApplication is None or if (getBaseApplication is None or
...@@ -258,49 +242,64 @@ class AmountGeneratorMixin: ...@@ -258,49 +242,64 @@ class AmountGeneratorMixin:
# For intermediate calculations, # For intermediate calculations,
# base_contribution_list MUST be defined # base_contribution_list MUST be defined
property_dict['base_contribution_list'] = base_contribution_list property_dict['base_contribution_list'] = base_contribution_list
for property_dict in resource_amount_aggregate.itervalues(): for property_dict in resource_amount_aggregate.itervalues():
base_application = property_dict.pop('base_application') base_application = property_dict.pop('base_application')
# property_dict should include # property_dict should include
# resource - VAT service or a Component in MRP # resource - VAT service or a Component in MRP
# quantity - quantity in component in MRP, (what else XXX) # quantity - quantity in component in MRP, (what else XXX)
# variation params - color, size, employer share, etc. # variation params - color, size, employer share, etc.
# price - empty (like in Transformation) price of a product # price - empty (like in Transformation) price of a product
# (ex. a Stamp) or tax ratio (ie. price per value units) # (ex. a Stamp) or tax ratio (ie. price per value units)
# base_contribution_list - needed to produce reports with # base_contribution_list - needed to produce reports with
# getTotalPrice # getTotalPrice
# #
# Quantity is used as a multiplier (like in transformations for MRP) # Quantity is used as a multiplier (like in transformations for MRP)
# net_converted_quantity is used preferrably to quantity since we # net_converted_quantity is used preferrably to quantity since we
# need values converted to the default management unit # need values converted to the default management unit
# If no quantity is provided, we consider that the value is 1.0 # If no quantity is provided, we consider that the value is 1.0
# (XXX is it OK ?) XXX-JPS Need careful review with taxes # (XXX is it OK ?) XXX-JPS Need careful review with taxes
property_dict['quantity'] = base_amount[base_application] * \ property_dict['quantity'] = base_amount[base_application] * \
property_dict.pop('net_converted_quantity', property_dict.pop('net_converted_quantity',
property_dict.get('quantity', 1.0)) property_dict.get('quantity', 1.0))
# Create an Amount object # Create an Amount object
# XXX-JPS Could we use a movement for safety ? # XXX-JPS Could we use a movement for safety ?
amount = newTempAmount(portal, property_dict.pop('id'), amount = newTempAmount(portal, property_dict.pop('id'),
**property_dict) **property_dict)
if rounding: if rounding:
# We hope here that rounding is sufficient at line level # We hope here that rounding is sufficient at line level
amount = portal_roundings.getRoundingProxy(amount, amount = portal_roundings.getRoundingProxy(amount,
context=amount_generator_line) context=amount_generator_line)
result.append(amount) result.append(amount)
for base_application, property_dict in \ for base_application, property_dict in value_amount_aggregate.iteritems():
value_amount_aggregate.iteritems(): # property_dict should include
# property_dict should include # base_contribution_list - needed to produce reports with
# base_contribution_list - needed to produce reports with # getTotalPrice
# getTotalPrice # quantity - quantity in component in MRP, (what else XXX)
# quantity - quantity in component in MRP, (what else XXX) # price - empty (like in Transformation) price of a product
# price - empty (like in Transformation) price of a product # (ex. a Stamp) or tax ratio (ie. price per value units)
# (ex. a Stamp) or tax ratio (ie. price per value units) value = base_amount[base_application] * \
value = base_amount[base_application] * \ (property_dict.get('quantity') or 1.0) * \
(property_dict.get('quantity') or 1.0) * \ (property_dict.get('price') or 1.0) # XXX-JPS is it really 1.0 ?
(property_dict.get('price') or 1.0) # XXX-JPS is it really 1.0 ? # Quantity is used as a multiplier
# Quantity is used as a multiplier # Price is used as a ratio (also a kind of multiplier)
# Price is used as a ratio (also a kind of multiplier) for base_key in property_dict['base_contribution_list']:
for base_key in property_dict['base_contribution_list']: base_amount[base_key] += value
base_amount[base_key] += value
# Each amount in amount_list creates a new amount to take into account
# We thus need to start with a loop on amount_list
for delivery_amount in amount_list:
# Initialize base_amount with per amount properties
amount_property_dict = self._getAmountPropertyDict(delivery_amount,
amount_list=amount_list, rounding=rounding)
base_amount.update(amount_property_dict)
# Initialize base_amount with total_price for each amount applications
#for application in delivery_amount.getBaseApplicationList(): # Acquired from Resource - XXX-JPS ?
application_list = delivery_amount.getBaseContributionList() # or getBaseApplicationList ?
if application_list:
total_price = delivery_amount.getTotalPrice()
for application in application_list: # Acquired from Resource - seems more normal
base_amount[application] = total_price
# Browse recursively the trade model and accumulate # Browse recursively the trade model and accumulate
# applicable values - now execute the method # applicable values - now execute the method
......
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