Commit 7a6edd5d authored by Romain Courteaud's avatar Romain Courteaud

Remove custom getAggregatedAmountList implementation and use the generic mixin

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@34814 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent caadbf43
......@@ -3,9 +3,10 @@
#
# Copyright (c) 2002 Coramy SAS and Contributors. All Rights Reserved.
# Thierry_Faucher <Thierry_Faucher@coramy.com>
# Copyright (c) 2004-2009 Nexedi SA and Contributors. All Rights Reserved.
# Copyright (c) 2004-2010 Nexedi SA and Contributors. All Rights Reserved.
# Romain Courteaud <romain@nexedi.com>
# Łukasz Nowak <luke@nexedi.com>
# Jean-Paul Smets <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
......@@ -29,25 +30,23 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from zLOG import LOG, WARNING
import zope.interface
from warnings import warn
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.Variated import Variated
from Products.ERP5.Document.Predicate import Predicate
from Products.CMFCategory.Renderer import Renderer
from Products.ERP5.AggregatedAmountList import AggregatedAmountList
from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5.Document.MappedValue import MappedValue
from zLOG import LOG, WARNING
from Products.ERP5.mixin.amount_generator import AmountGeneratorMixin
from Products.ERP5.mixin.variated import VariatedMixin
from Products.ERP5.mixin.composition import CompositionMixin
from Products.ERP5Type.XMLObject import XMLObject
class Transformation(XMLObject, Predicate, Variated):
class Transformation(MappedValue, AmountGeneratorMixin, VariatedMixin):
"""
Build of material - contains a list of transformed resources
......@@ -79,15 +78,83 @@ class Transformation(XMLObject, Predicate, Variated):
, PropertySheet.TransformedResource
, PropertySheet.Path
, PropertySheet.Transformation
, PropertySheet.Order
, PropertySheet.Task
)
# Declarative interfaces
zope.interface.implements(interfaces.IVariated,
interfaces.IVariationRange,
interfaces.IAmountGenerator
)
# Predicate Value implementation
# asPredicate takes into account the resource
# XXX-JPS not Impl.
def getCellAggregateKey(self, amount_generator_cell):
"""Define a key in order to aggregate amounts at cell level
Transformed Resource (Transformation)
key must be None because:
- quantity and variation are defined in different cells so that the
user does not need to enter values depending on all axes
- amount_generator_cell.test should filter only 1 variant
current key = (acquired resource, acquired variation)
Assorted Resource (Transformation)
key = (assorted resource, assorted resource variation)
usually resource and quantity provided together
Payroll
key = (payroll resource, payroll resource variation)
Tax
key = (tax resource, tax resource variation)
"""
if len(amount_generator_cell.contentValues()):
key = (amount_generator_cell.getRelativeUrl(),)
else:
key = (amount_generator_cell.getParentValue().getRelativeUrl(),)
return key
# Mapped Value implementation
# Transformation itself provides no properties or categories
def getMappedValuePropertyList(self):
return ()
def getMappedValueBaseCategoryList(self):
return ()
# Amount Generator Mixin
def _getGlobalPropertyDict(self, context, amount_list=None, rounding=False):
"""
No global properties needed
"""
return {
}
def _getAmountPropertyDict(self, amount, amount_list=None, rounding=False):
"""
Produced amount quantity is needed to initialize transformation
"""
# XXX 1 is for compatibility
return {
'produced_quantity' : amount.getQuantity(1),
}
def getBaseApplication(self):
"""
"""
# It is OK to try to acquire
if getattr(self, '_baseGetBaseApplication', None) is not None:
result = self._baseGetBaseApplication()
if result:
return result
return 'produced_quantity'
# IVariationRange and IVariated Implementation
security.declareProtected(Permissions.AccessContentsInformation,
'updateVariationCategoryList')
def updateVariationCategoryList(self):
......@@ -162,15 +229,6 @@ class Transformation(XMLObject, Predicate, Variated):
base_category_list, base=1, display_none_category=0)
return result
security.declareProtected(Permissions.AccessContentsInformation,
'setVariationBaseCategoryList')
def setVariationBaseCategoryList(self, value):
"""
Define the possible base categories and reindex object
"""
self._setVariationBaseCategoryList(value)
self.reindexObject()
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationCategoryItemList')
def getVariationCategoryItemList(self, base_category_list=(), base=1,
......@@ -216,89 +274,3 @@ class Transformation(XMLObject, Predicate, Variated):
display_id=display_id,**kw).\
render(object_list))
return variation_category_item_list
security.declareProtected(Permissions.AccessContentsInformation,
'getAggregatedAmountList')
def getAggregatedAmountList(self, context=None, REQUEST=None,
trade_phase_list=None,
# obsolete, use trade_phase_list instead
ind_phase_url_list=None,
rejected_resource_uid_list=None,
**kw):
"""
getAggregatedAmountList returns an AggregatedAmountList which
can be used either to do some calculation (ex. price, BOM)
or to display a detailed view of a transformation.
"""
if context is None:
warn("Calling Transformation.getAggregatedAmountList without context " \
"is wrong. Context should be an Amount defining the resource to " \
"produce", DeprecationWarning)
from Products.ERP5Type.Document import newTempAmount
context = newTempAmount(self, "deprecated_usage")
context.setResourceValue(self.getResourceValue())
context.setQuantity(1.0)
# A list of functions taking a transformation_line as sole argument
# and returning True iif the line should be kept in the result
filter_list = []
# Get only lines related to a precise trade_phase
if trade_phase_list is not None:
def trade_phase_filter(line):
return line.getTradePhase() in trade_phase_list
filter_list.append(trade_phase_filter)
# Get only lines related to a precise industrial_phase
if ind_phase_url_list is not None:
LOG("Transformation", WARNING, "ind_phase_list is obsolete")
def industrial_phase_filter(line):
ind_ph = line.getIndustrialPhaseValue()
if ind_ph is not None:
return ind_ph.getRelativeUrl() in ind_phase_url_list
return False
filter_list.append(industrial_phase_filter)
# Filter lines with resource we do not want to see
if rejected_resource_uid_list is not None:
def rejected_uid_filter(line):
return line.getResourceUid() not in rejected_resource_uid_list
filter_list.append(rejected_uid_filter)
def line_is_included(line):
# XXX > 2.5 : all(f(line) for f in filter_list)
for filterr in filter_list:
if not filterr(line):
return False
return True
# First we need to get the list of transformations which this
# transformation depends on
# At this moment, we only consider 1 dependency
template_transformation_list = self.getSpecialiseValueList()
# Browse all involved transformations and create one line per
# line of transformation
# Currently, we do not consider abstractions, we just add
# whatever we find in all transformations
result = AggregatedAmountList()
for transformation in ([self] + template_transformation_list):
for transformation_line in transformation.objectValues():
# Browse each transformed or assorted resource of the current
# transformation
if line_is_included(transformation_line):
try:
line_result = transformation_line.getAggregatedAmountList(context)
except KeyError:
# KeyError is raised by TransformedResource.getAggregatedAmountList
# in case of misconfiguration of a Cell.
# Just ignore the line
pass
else:
result.extend(line_result)
return result
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