Commit 0fde0d73 authored by Yusuke Muraoka's avatar Yusuke Muraoka

- changed ProductionOrderRule to inherit mixin instead of using

  monkeyPatch
- added the interface ITransformation to Transformation and
  TransformedResource
- changed TransformedResource to return a tempDocument of 
  TransformedResouce instead of Amount
- changed TransformationRule to use
  Transformation.getAggeratedAmountList again, because Transformation
  came to be able to return document which has trade_phase


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27361 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eb8ca062
...@@ -34,7 +34,7 @@ from Products.ERP5.Document.TransformationRule import TransformationRuleMixin ...@@ -34,7 +34,7 @@ from Products.ERP5.Document.TransformationRule import TransformationRuleMixin
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
class ProductionOrderRule(OrderRule): class ProductionOrderRule(TransformationRuleMixin, OrderRule):
""" """
Prouction Order Rule object use a Supply Chain to expand a Prouction Order Rule object use a Supply Chain to expand a
Production Order. Production Order.
...@@ -106,6 +106,3 @@ class ProductionOrderRule(OrderRule): ...@@ -106,6 +106,3 @@ class ProductionOrderRule(OrderRule):
property_dict[prop] = movement.getProperty(prop) property_dict[prop] = movement.getProperty(prop)
return property_dict return property_dict
from Products.ERP5Type.Utils import monkeyPatch
monkeyPatch(TransformationRuleMixin, ProductionOrderRule)
...@@ -80,7 +80,9 @@ class Transformation(XMLObject, Predicate, Variated): ...@@ -80,7 +80,9 @@ class Transformation(XMLObject, Predicate, Variated):
) )
# Declarative interfaces # Declarative interfaces
__implements__ = ( interfaces.IVariated, ) __implements__ = ( interfaces.IVariated
, interfaces.ITransformation
)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -222,6 +224,9 @@ class Transformation(XMLObject, Predicate, Variated): ...@@ -222,6 +224,9 @@ class Transformation(XMLObject, Predicate, Variated):
render(object_list)) render(object_list))
return variation_category_item_list return variation_category_item_list
def updateAggregatedAmountList(self, context, **kw):
raise NotImplementedError, 'need?'
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getAggregatedAmountList') 'getAggregatedAmountList')
def getAggregatedAmountList(self, context=None, REQUEST=None, def getAggregatedAmountList(self, context=None, REQUEST=None,
......
...@@ -40,7 +40,7 @@ from Products.ERP5Type.Errors import TransformationRuleError ...@@ -40,7 +40,7 @@ from Products.ERP5Type.Errors import TransformationRuleError
class TransformationMovementFactory: class TransformationMovementFactory:
def __init__(self): def __init__(self):
self.product = None # base information to use for making movements self.default = None # base information to use for making movements
self.produced_list = list() self.produced_list = list()
self.consumed_list = list() self.consumed_list = list()
...@@ -63,6 +63,17 @@ class TransformationMovementFactory: ...@@ -63,6 +63,17 @@ class TransformationMovementFactory:
return [causality_value.getRelativeUrl() return [causality_value.getRelativeUrl()
for causality_value in causality_value_list] for causality_value in causality_value_list]
def getRequestList(self):
_list = []
for (request_list, sign) in ((self.produced_list, -1),
(self.consumed_list, 1)):
for request in request_list:
d = self.default.copy()
d.update(request)
d['quantity'] *= sign
_list.append(d)
return _list
def makeMovements(self, applied_rule): def makeMovements(self, applied_rule):
""" """
make movements under the applied_rule by requests make movements under the applied_rule by requests
...@@ -77,24 +88,18 @@ class TransformationMovementFactory: ...@@ -77,24 +88,18 @@ class TransformationMovementFactory:
produced quantity should be represented by minus quantity on movement. produced quantity should be represented by minus quantity on movement.
because plus quantity is consumed. because plus quantity is consumed.
""" """
for (request_list, sign) in ((self.produced_list, -1), for request in self.getRequestList():
(self.consumed_list, 1)): # get movement by causality
for request in request_list: key = tuple(sorted(self._getCausalityList(**request)))
d = self.product.copy() movement = movement_dict.get(key, None)
d.update(request) # when no exist
d['quantity'] *= sign if movement is None:
movement = applied_rule.newContent(portal_type="Simulation Movement")
# get movement by causality # update
key = tuple(sorted(self._getCausalityList(**request))) if movement.isFrozen():
movement = movement_dict.get(key, None) self.makeDifferentMovement(movement, **request)
# when no exist else:
if movement is None: movement.edit(**request)
movement = applied_rule.newContent(portal_type="Simulation Movement")
# update
if movement.isFrozen():
self.makeDifferentMovement(movement, **d)
else:
movement.edit(**d)
def _requestNetQuantity(self, request): def _requestNetQuantity(self, request):
quantity = request.get('quantity', None) quantity = request.get('quantity', None)
...@@ -214,7 +219,7 @@ class TransformationRule(TransformationRuleMixin, Rule): ...@@ -214,7 +219,7 @@ class TransformationRule(TransformationRuleMixin, Rule):
""" """
production_trade_phase_set = set([amount.getTradePhase() production_trade_phase_set = set([amount.getTradePhase()
for amount in transformation\ for amount in transformation\
.objectValues(portal_type='Transformation Transformed Resource')]) .getAggregatedAmountList()])
head_path_list = [] head_path_list = []
for state in business_process.objectValues( for state in business_process.objectValues(
portal_type=self.getPortalBusinessStateTypeList()): portal_type=self.getPortalBusinessStateTypeList()):
...@@ -261,7 +266,7 @@ class TransformationRule(TransformationRuleMixin, Rule): ...@@ -261,7 +266,7 @@ class TransformationRule(TransformationRuleMixin, Rule):
head_production_path_list = self.getHeadProductionPathList(transformation, head_production_path_list = self.getHeadProductionPathList(transformation,
business_process) business_process)
factory = self.getFactory() factory = self.getFactory()
factory.product = dict( factory.default = dict(
resource=transformation.getResource(), resource=transformation.getResource(),
quantity=parent_movement.getNetQuantity(), quantity=parent_movement.getNetQuantity(),
quantity_unit=parent_movement.getQuantityUnit(), quantity_unit=parent_movement.getQuantityUnit(),
...@@ -270,8 +275,7 @@ class TransformationRule(TransformationRuleMixin, Rule): ...@@ -270,8 +275,7 @@ class TransformationRule(TransformationRuleMixin, Rule):
# consumed amounts are sorted by phase, but not ordered. # consumed amounts are sorted by phase, but not ordered.
amount_dict = {} amount_dict = {}
# XXX Transformation.getAggregatedAmountList is useless for this, it can not have trade_phase, because Amout. for amount in transformation.getAggregatedAmountList():
for amount in transformation.objectValues(portal_type='Transformation Transformed Resource'):
phase = amount.getTradePhase() phase = amount.getTradePhase()
if phase not in trade_phase_list: if phase not in trade_phase_list:
...@@ -313,7 +317,7 @@ class TransformationRule(TransformationRuleMixin, Rule): ...@@ -313,7 +317,7 @@ class TransformationRule(TransformationRuleMixin, Rule):
start_date=start_date, start_date=start_date,
stop_date=stop_date, stop_date=stop_date,
# when last path of transformation, path.getQuantity() will be return 1. # when last path of transformation, path.getQuantity() will be return 1.
quantity=factory.product['quantity'] * path.getQuantity(), quantity=factory.default['quantity'] * path.getQuantity(),
destination=destination, destination=destination,
#destination_section=???, #destination_section=???,
trade_phase_value_list=successor_remaining_phase_list) trade_phase_value_list=successor_remaining_phase_list)
...@@ -346,7 +350,7 @@ class TransformationRule(TransformationRuleMixin, Rule): ...@@ -346,7 +350,7 @@ class TransformationRule(TransformationRuleMixin, Rule):
causality_value=path, causality_value=path,
start_date=start_date, start_date=start_date,
stop_date=stop_date, stop_date=stop_date,
quantity=factory.product['quantity'] * path.getQuantity(), quantity=factory.default['quantity'] * path.getQuantity(),
source=path.getSource(), source=path.getSource(),
#source_section=???, #source_section=???,
trade_phase_value_list=predecessor_remaining_phase_list) trade_phase_value_list=predecessor_remaining_phase_list)
...@@ -358,7 +362,7 @@ class TransformationRule(TransformationRuleMixin, Rule): ...@@ -358,7 +362,7 @@ class TransformationRule(TransformationRuleMixin, Rule):
start_date=start_date, start_date=start_date,
stop_date=stop_date, stop_date=stop_date,
resource=amount.getResource(), resource=amount.getResource(),
quantity=factory.product['quantity'] * amount.getQuantity()\ quantity=factory.default['quantity'] * amount.getQuantity()\
/ amount.getEfficiency() * path.getQuantity(), / amount.getEfficiency() * path.getQuantity(),
quantity_unit=amount.getQuantityUnit(), quantity_unit=amount.getQuantityUnit(),
source=path.getSource(), source=path.getSource(),
...@@ -394,7 +398,7 @@ which last_phase_path_list is empty.""" % (transformation, business_process) ...@@ -394,7 +398,7 @@ which last_phase_path_list is empty.""" % (transformation, business_process)
factory.requestProduced( factory.requestProduced(
causality_value_list=last_phase_path_list, causality_value_list=last_phase_path_list,
# when last path of transformation, path.getQuantity() will be return 1. # when last path of transformation, path.getQuantity() will be return 1.
quantity=factory.product['quantity'] * path.getQuantity(), quantity=factory.default['quantity'] * path.getQuantity(),
#destination_section=???, #destination_section=???,
**last_prop_dict) **last_prop_dict)
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
from Globals import InitializeClass from Globals import InitializeClass
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.XMLMatrix import XMLMatrix from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5Type.Utils import cartesianProduct from Products.ERP5Type.Utils import cartesianProduct
...@@ -77,8 +77,9 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount): ...@@ -77,8 +77,9 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount):
) )
# Declarative interfaces # Declarative interfaces
__implements__ = ( interfaces.IVariated, ) __implements__ = ( interfaces.IVariated
, interfaces.ITransformation
)
### Variation matrix definition ### Variation matrix definition
...@@ -163,6 +164,9 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount): ...@@ -163,6 +164,9 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount):
self._setVVariationBaseCategoryList(value) self._setVVariationBaseCategoryList(value)
self.reindexObject() self.reindexObject()
def updateAggregatedAmountList(self, context, **kw):
raise NotImplementedError('TODO')
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getAggregatedAmountList') 'getAggregatedAmountList')
def getAggregatedAmountList(self, context=None, REQUEST=None, **kw): def getAggregatedAmountList(self, context=None, REQUEST=None, **kw):
...@@ -178,11 +182,11 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount): ...@@ -178,11 +182,11 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount):
# If no predicate is defined on line, the result of the test # If no predicate is defined on line, the result of the test
# must be true # must be true
# Create temporary object to store amount # Create temporary object to store amount
from Products.ERP5Type.Document import newTempAmount from Products.ERP5Type.Document import newTempTransformedResource
# XXX changed by TB getParentID()+getId() instead of getId() # XXX changed by TB getParentID()+getId() instead of getId()
# This might not be enough if we have different transformation # This might not be enough if we have different transformation
# with the same id (for example in several modules) # with the same id (for example in several modules)
tmp_amount = newTempAmount(self.getPortalObject(), self.getParentId()+'_'+self.getId()) tmp_amount = newTempTransformedResource(self.getPortalObject(), self.getParentId()+'_'+self.getId())
# Create error string # Create error string
error_string = '' error_string = ''
# Add resource relation # Add resource relation
...@@ -320,17 +324,19 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount): ...@@ -320,17 +324,19 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount):
else: else:
variation_category_list = self._getVariationCategoryList() variation_category_list = self._getVariationCategoryList()
variation_category_list_defined_by = self.getRelativeUrl() variation_category_list_defined_by = self.getRelativeUrl()
trade_phase = self.getTradePhase()
# Store values in Amount # Store values in Amount
tmp_amount._edit( tmp_amount._edit(
# Properties define on transformation line # Properties define on transformation line
title = self.getTitle(), title=self.getTitle(),
description = self.getDescription(), description=self.getDescription(),
efficiency = efficiency, efficiency=efficiency,
quantity = quantity, quantity=quantity,
# This fields only store some informations for debugging if necessary # This fields only store some informations for debugging if necessary
quantity_defined_by = quantity_defined_by, quantity_defined_by=quantity_defined_by,
variation_category_list_defined_by = variation_category_list_defined_by, variation_category_list_defined_by=variation_category_list_defined_by,
error_string = error_string trade_phase=trade_phase,
error_string=error_string
) )
tmp_amount.setVariationCategoryList(variation_category_list) tmp_amount.setVariationCategoryList(variation_category_list)
# Variation property dict # Variation property dict
......
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