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