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