Commit 8ceef6bd authored by Julien Muchembled's avatar Julien Muchembled

Make testLegacyProductionOrder work with new amount generator

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@39253 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c5822540
...@@ -11,6 +11,4 @@ ProductionOrderModelRootSimulationRule ...@@ -11,6 +11,4 @@ ProductionOrderModelRootSimulationRule
ProductionOrderRootSimulationRule ProductionOrderRootSimulationRule
RootAppliedRuleCausalityMovementGroup RootAppliedRuleCausalityMovementGroup
SimulationLegacyPatches SimulationLegacyPatches
TradeModelSimulationRule TradeModelSimulationRule
Transformation \ No newline at end of file
TransformedResource
\ No newline at end of file
...@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo ...@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint from Products.ERP5Type import Permissions, PropertySheet, Constraint
from Products.ERP5Type.XMLMatrix import XMLMatrix from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5Type.Utils import cartesianProduct from Products.ERP5Type.Utils import cartesianProduct
from Products.ERP5.Document.AmountGeneratorLine import AmountGeneratorLine
from Products.ERP5.Document.TransformedResource import TransformedResource from Products.ERP5.Document.TransformedResource import TransformedResource
from Products.ERP5Type.Base import TempBase from Products.ERP5Type.Base import TempBase
...@@ -114,14 +115,6 @@ class AssortedResource(TransformedResource): ...@@ -114,14 +115,6 @@ class AssortedResource(TransformedResource):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.SimpleItem
, PropertySheet.CategoryCore
, PropertySheet.Amount
, PropertySheet.TransformedResource
)
# Local property sheet # Local property sheet
_properties = ( _properties = (
{ 'id' : 'variation_base_category', { 'id' : 'variation_base_category',
...@@ -138,6 +131,8 @@ class AssortedResource(TransformedResource): ...@@ -138,6 +131,8 @@ class AssortedResource(TransformedResource):
'mode' : 'w' }, 'mode' : 'w' },
) )
getCellAggregateKey = AmountGeneratorLine.getCellAggregateKey
security.declareProtected(Permissions.AccessContentsInformation, 'getAssortedVariationCategoryList') security.declareProtected(Permissions.AccessContentsInformation, 'getAssortedVariationCategoryList')
def getAssortedVariationCategoryList(self, cell_index): def getAssortedVariationCategoryList(self, cell_index):
""" """
...@@ -500,8 +495,8 @@ class AssortedResource(TransformedResource): ...@@ -500,8 +495,8 @@ class AssortedResource(TransformedResource):
return error_list return error_list
security.declareProtected(Permissions.AccessContentsInformation, 'getAggregatedAmountList') if 0: # obsolete
def getAggregatedAmountList(self, REQUEST): def getAggregatedAmountList(self, REQUEST):
# First, we set initial values for quantity and variation # First, we set initial values for quantity and variation
# Currently, we only consider discrete variations # Currently, we only consider discrete variations
# Continuous variations will be implemented in a future version of ERP5 # Continuous variations will be implemented in a future version of ERP5
......
...@@ -139,7 +139,7 @@ class SupplyLink(Path, XMLObject): ...@@ -139,7 +139,7 @@ class SupplyLink(Path, XMLObject):
supply_chain.getNextProductionIndustrialPhaseList(self) supply_chain.getNextProductionIndustrialPhaseList(self)
# XXX GetRelativeUrl copy/paste from transformation # XXX GetRelativeUrl copy/paste from transformation
# Code duplication # Code duplication
ind_phase_url_list = [x.getRelativeUrl() \ ind_phase_url_list = [x.getCategoryRelativeUrl()
for x in next_industrial_phase_list] for x in next_industrial_phase_list]
# Get the transformation to use # Get the transformation to use
...@@ -147,10 +147,11 @@ class SupplyLink(Path, XMLObject): ...@@ -147,10 +147,11 @@ class SupplyLink(Path, XMLObject):
rule = applied_rule.getSpecialiseValue() rule = applied_rule.getSpecialiseValue()
transformation = rule.getTransformation(movement) transformation = rule.getTransformation(movement)
# Call getAggregatedAmountList # Call getAggregatedAmountList
amount_list = transformation.getAggregatedAmountList( tmp_context = movement.getParentValue().getParentValue().asContext()
movement.getParentValue().getParentValue(), tmp_context.asComposedDocument = lambda *args: transformation
ind_phase_url_list=ind_phase_url_list) resource_list = [x.getResourceValue()
resource_list = [x.getResourceValue() for x in amount_list] for x in tmp_context.getAggregatedAmountList()
if x.getCausalityValue().getIndustrialPhase() in ind_phase_url_list]
current_resource = movement.getResourceValue() current_resource = movement.getResourceValue()
if current_resource not in resource_list: if current_resource not in resource_list:
# We can delivered this resource # We can delivered this resource
......
...@@ -29,21 +29,13 @@ ...@@ -29,21 +29,13 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
import zope.interface
from warnings import warn
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5.Document.AmountGeneratorLine import AmountGeneratorLine
from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5.Document.Amount import Amount
from Products.ERP5.Document.MappedValue import MappedValue
from Products.ERP5.Document.Predicate import Predicate
class TransformedResource(MappedValue, XMLMatrix, Amount): class TransformedResource(AmountGeneratorLine):
""" """
TransformedResource defines which resource is being transformed TransformedResource defines which resource is being transformed
in order to produce a product define in the parent Transformation in order to produce a product define in the parent Transformation
...@@ -51,8 +43,8 @@ class TransformedResource(MappedValue, XMLMatrix, Amount): ...@@ -51,8 +43,8 @@ class TransformedResource(MappedValue, XMLMatrix, Amount):
TODO: TODO:
- transformations used to work perfectly for more than 3 dimensions - transformations used to work perfectly for more than 3 dimensions
of variations. However, this feature was broken with time and of variations. However, this feature was broken with time and
is no longer usable. It is time to reimplement it. This is is no longer usable. It is time to reimplement it. This is
completely unrelated to MatrixBox reimplementation unlike completely unrelated to MatrixBox reimplementation unlike
what is stated in some comments. what is stated in some comments.
""" """
...@@ -65,18 +57,8 @@ class TransformedResource(MappedValue, XMLMatrix, Amount): ...@@ -65,18 +57,8 @@ class TransformedResource(MappedValue, XMLMatrix, Amount):
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
# Declarative properties # Declarative properties
property_sheets = ( PropertySheet.Base property_sheets = (PropertySheet.TransformedResource, )
, PropertySheet.SimpleItem
, PropertySheet.CategoryCore
, PropertySheet.Amount
, PropertySheet.Reference
, PropertySheet.TransformedResource
)
# Declarative interfaces
zope.interface.implements(interfaces.IAmountGenerator,
interfaces.IVariated,
interfaces.IVariationRange,)
### Mapped Value Definition ### Mapped Value Definition
# Provide default mapped value properties and categories if # Provide default mapped value properties and categories if
# not defined # not defined
...@@ -91,30 +73,41 @@ class TransformedResource(MappedValue, XMLMatrix, Amount): ...@@ -91,30 +73,41 @@ class TransformedResource(MappedValue, XMLMatrix, Amount):
result = self.getVariationRangeBaseCategoryList() # The current resource variation result = self.getVariationRangeBaseCategoryList() # The current resource variation
return result return result
def getCellAggregateKey(self):
"""Define a key in order to aggregate amounts at cell level"""
return None
@classmethod
def getBaseAmountQuantity(cls, delivery_amount, base_application, rounding):
value = delivery_amount.getGeneratedAmountQuantity(base_application)
if base_application == 'produced_quantity':
value += delivery_amount.getQuantity()
return value
def getBaseApplication(self): def getBaseApplication(self):
""" """
"""
return self.getBaseApplicationList()[0]
def getBaseApplicationList(self):
"""
""" """
# It is OK to try to acquire # It is OK to try to acquire
if getattr(self, '_baseGetBaseApplication', None) is not None: return self._categoryGetBaseApplicationList() or ['produced_quantity']
result = self._baseGetBaseApplication()
if result:
return result
return 'produced_quantity'
### Variation matrix definition ### Variation matrix definition
# XXX-JPS Some explanation needed # XXX-JPS Some explanation needed
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'updateVariationCategoryList') 'updateVariationCategoryList')
def updateVariationCategoryList(self): def updateVariationCategoryList(self):
""" """
Check if variation category list of the resource changed and Check if variation category list of the resource changed and
update transformed resource by doing a set cell range update transformed resource by doing a set cell range
""" """
self.setQVariationBaseCategoryList(self.getQVariationBaseCategoryList()) self.setQVariationBaseCategoryList(self.getQVariationBaseCategoryList())
self.setVVariationBaseCategoryList(self.getVVariationBaseCategoryList()) self.setVVariationBaseCategoryList(self.getVVariationBaseCategoryList())
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'_setQVariationBaseCategoryList') '_setQVariationBaseCategoryList')
def _setQVariationBaseCategoryList(self, value): def _setQVariationBaseCategoryList(self, value):
""" """
...@@ -124,7 +117,7 @@ class TransformedResource(MappedValue, XMLMatrix, Amount): ...@@ -124,7 +117,7 @@ class TransformedResource(MappedValue, XMLMatrix, Amount):
self._baseSetQVariationBaseCategoryList(value) self._baseSetQVariationBaseCategoryList(value)
self._updateCellRange('quantity') self._updateCellRange('quantity')
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'_setVVariationBaseCategoryList') '_setVVariationBaseCategoryList')
def _setVVariationBaseCategoryList(self, value): def _setVVariationBaseCategoryList(self, value):
""" """
...@@ -137,7 +130,7 @@ class TransformedResource(MappedValue, XMLMatrix, Amount): ...@@ -137,7 +130,7 @@ class TransformedResource(MappedValue, XMLMatrix, Amount):
# XXX-JPS This should be handled by interaction workflow or interactor # XXX-JPS This should be handled by interaction workflow or interactor
# XXX-JPS SO many cases are not handled well... # XXX-JPS SO many cases are not handled well...
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'setVVariationBaseCategoryList') 'setVVariationBaseCategoryList')
def setVVariationBaseCategoryList(self, value): def setVVariationBaseCategoryList(self, value):
""" """
......
...@@ -75,13 +75,14 @@ for transformation_relative_url, variation_list_list in transformation_item_list ...@@ -75,13 +75,14 @@ for transformation_relative_url, variation_list_list in transformation_item_list
continue\n continue\n
for variation_list in variation_list_list:\n for variation_list in variation_list_list:\n
movement = newTempMovement(resource, \'temp\',\n movement = newTempMovement(resource, \'temp\',\n
specialise_value=transformation,\n
variation_category_list=variation_list,\n variation_category_list=variation_list,\n
resource=resource.getRelativeUrl(),\n resource_value=resource,\n
quantity=1.0)\n quantity=1.0)\n
base_row = dict(uid=resource.getUid(), variation_text=movement.getVariationText())\n base_row = dict(uid=resource.getUid(), variation_text=movement.getVariationText())\n
\n \n
row_dict_list = []\n row_dict_list = []\n
for amount in transformation.getAggregatedAmountList([movement]):\n for amount in movement.getAggregatedAmountList():\n
transformed_resource_uid = amount.getResourceUid()\n transformed_resource_uid = amount.getResourceUid()\n
quantity = amount.getQuantity()\n quantity = amount.getQuantity()\n
if transformed_resource_uid is not None and quantity is not None:\n if transformed_resource_uid is not None and quantity is not None:\n
......
...@@ -234,7 +234,9 @@ class AmountGeneratorMixin: ...@@ -234,7 +234,9 @@ class AmountGeneratorMixin:
# Then collect the mapped values (quantity, price, trade_phase...) # Then collect the mapped values (quantity, price, trade_phase...)
for key in cell.getMappedValuePropertyList(): for key in cell.getMappedValuePropertyList():
# XXX-JPS Make sure handling of list properties can be handled # XXX-JPS Make sure handling of list properties can be handled
property_dict[key] = cell.getProperty(key) dict_key = key in ('net_quantity', 'converted_quantity',
'net_converted_quantity') and 'quantity' or key
property_dict[dict_key] = cell.getProperty(key)
category_list = cell.getAcquiredCategoryMembershipList( category_list = cell.getAcquiredCategoryMembershipList(
cell.getMappedValueBaseCategoryList(), base=1) cell.getMappedValueBaseCategoryList(), base=1)
property_dict['category_list'] += category_list property_dict['category_list'] += category_list
...@@ -279,14 +281,10 @@ class AmountGeneratorMixin: ...@@ -279,14 +281,10 @@ class AmountGeneratorMixin:
# (XXX is it OK ?) XXX-JPS Need careful review with taxes # (XXX is it OK ?) XXX-JPS Need careful review with taxes
quantity = float(sum(map(base_amount.getGeneratedAmountQuantity, quantity = float(sum(map(base_amount.getGeneratedAmountQuantity,
base_application_set))) base_application_set)))
for quantity_key in ('net_quantity', 'converted_quantity', try:
'net_converted_quantity', 'quantity'): quantity *= property_dict.pop('quantity', 1)
if quantity_key in property_dict: except TypeError: # None or ''
try: pass
quantity *= property_dict.pop(quantity_key)
except TypeError: # None or ''
pass
break
if not quantity: if not quantity:
continue continue
# Backward compatibility # Backward compatibility
......
...@@ -217,24 +217,27 @@ class TransformationRule(TransformationSourcingRuleMixin, Rule): ...@@ -217,24 +217,27 @@ class TransformationRule(TransformationSourcingRuleMixin, Rule):
base_category_list=base_category_list) base_category_list=base_category_list)
# Get the transformation to use # Get the transformation to use
transformation = self.getTransformation(applied_rule) transformation = self.getTransformation(applied_rule)
# Generate the fake context # Generate the fake context
tmp_context = parent_movement.asContext( tmp_context = parent_movement.asContext(categories=category_list)
context=parent_movement, tmp_context.asComposedDocument = lambda *args: transformation
REQUEST={'categories':category_list})
# Calculate the industrial phase list # Calculate the industrial phase list
previous_ind_phase_list = supply_chain.\ previous_ind_phase_list = supply_chain.\
getPreviousPackingListIndustrialPhaseList(current_supply_link) getPreviousPackingListIndustrialPhaseList(current_supply_link)
ind_phase_id_list = [x.getRelativeUrl() for x in previous_ind_phase_list] ind_phase_url_list = [x.getCategoryRelativeUrl()
for x in previous_ind_phase_list]
# Call getAggregatedAmountList # Call getAggregatedAmountList
# XXX expand failed if transformation is not defined. # XXX expand failed if transformation is not defined.
# Do we need to catch the exception ? # Do we need to catch the exception ?
amount_list = transformation.getAggregatedAmountList( amount_list = tmp_context.getAggregatedAmountList()
tmp_context,
ind_phase_url_list=ind_phase_id_list)
# Add entries in the consumed_movement_dict # Add entries in the consumed_movement_dict
consumed_movement_dict = {} consumed_movement_dict = {}
for amount in amount_list: for amount in amount_list:
consumed_mvt_id = "%s_%s" % ("cr", amount.getId()) model_line = amount.getCausalityValue()
if model_line.getIndustrialPhase() not in ind_phase_url_list:
continue
consumed_mvt_id = "cr_%s_%s_%s" % (model_line.getParentId(),
model_line.getId(),
tmp_context.getId())
stop_date = parent_movement.getStartDate() stop_date = parent_movement.getStartDate()
resource_price = amount.getResourcePrice() resource_price = amount.getResourcePrice()
price = None price = None
...@@ -248,7 +251,7 @@ class TransformationRule(TransformationSourcingRuleMixin, Rule): ...@@ -248,7 +251,7 @@ class TransformationRule(TransformationSourcingRuleMixin, Rule):
amount.getVariationCategoryList(), amount.getVariationCategoryList(),
"variation_property_dict": \ "variation_property_dict": \
amount.getVariationPropertyDict(), amount.getVariationPropertyDict(),
"quantity": amount.getNetQuantity(), # getNetQuantity to support efficency from transformation "quantity": amount.getNetQuantity(), # getNetQuantity to support efficency from <
"price": price, "price": price,
"quantity_unit": amount.getQuantityUnit(), "quantity_unit": amount.getQuantityUnit(),
"destination_list": (), "destination_list": (),
......
...@@ -65,7 +65,8 @@ class TestProductionOrderMixin(TestOrderMixin): ...@@ -65,7 +65,8 @@ class TestProductionOrderMixin(TestOrderMixin):
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
""" """
""" """
return TestOrderMixin.getBusinessTemplateList(self) + ('erp5_mrp',) return TestOrderMixin.getBusinessTemplateList(self) + (
'erp5_mrp', 'erp5_mrp_simulation_legacy')
def setUpPreferences(self): def setUpPreferences(self):
portal = self.getPortal() portal = self.getPortal()
......
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