Commit 08b6276b authored by Julien Muchembled's avatar Julien Muchembled

Fix testApparelTransformation

To simplify amount generator and because requirements are not clear,
support of '*_quantity' variants (as mapped property) is dropped.

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@39505 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6ca6ce61
...@@ -27,15 +27,13 @@ ...@@ -27,15 +27,13 @@
# #
############################################################################## ##############################################################################
from UserList import UserList
import zope.interface import zope.interface
from Products.ERP5Type import interfaces from Products.ERP5Type import interfaces
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
class AggregatedAmountList(UserList): class AggregatedAmountList(list):
""" """
Temporary object needed to aggregate Amount value Temporary object needed to aggregate Amount value
And to calculate some report or total value And to calculate some report or total value
......
...@@ -658,21 +658,19 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin): ...@@ -658,21 +658,19 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
Get all pricing parameters from Predicate. Get all pricing parameters from Predicate.
""" """
# Search all categories context # Search all categories context
new_category_list = [] if context is None:
if context is not None: new_category_list = []
new_category_list += context.getCategoryList() else:
new_category_list = context.getCategoryList()
#XXX This should be 'category_list' instead of 'categories' to respect #XXX This should be 'category_list' instead of 'categories' to respect
# the naming convention. Must take care of side effects when fixing # the naming convention. Must take care of side effects when fixing
if kw.has_key('categories'): new_category_list += kw.pop('categories', ())
new_category_list.extend(kw['categories'])
del kw['categories']
resource_category = 'resource/' + self.getRelativeUrl() resource_category = 'resource/' + self.getRelativeUrl()
if not resource_category in new_category_list: if not resource_category in new_category_list:
new_category_list += (resource_category, ) new_category_list.append(resource_category)
# Generate the predicate mapped value # Generate the predicate mapped value
# to get some price values. # to get some price values.
portal = self.getPortalObject() portal = self.getPortalObject()
domain_tool = getToolByName(portal, 'portal_domains')
if supply_path_type is None: if supply_path_type is None:
portal_type_list = kw.pop('portal_type', portal_type_list = kw.pop('portal_type',
portal.getPortalSupplyPathTypeList()) portal.getPortalSupplyPathTypeList())
...@@ -681,17 +679,20 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin): ...@@ -681,17 +679,20 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
else: else:
portal_type_list = (supply_path_type,) portal_type_list = (supply_path_type,)
sort_method = kw.pop('sort_method', self._pricingSortMethod)
# Generate the fake context # Generate the fake context
tmp_context = self.asContext(context=context, tmp_context = context.asContext(categories=new_category_list,
categories=new_category_list, REQUEST=REQUEST, **kw)
REQUEST=REQUEST, **kw) # XXX When called for a generated amount, base_application may point
tmp_kw = kw.copy() # to nonexistant base_amount (e.g. "produced_quantity" for
if 'sort_method' not in tmp_kw: # transformations), which would make domain tool return nothing.
tmp_kw['sort_method'] = self._pricingSortMethod # Following hack cleans up a category we don't want to test anyway.
mapped_value = domain_tool.generateMultivaluedMappedValue( tmp_context.setBaseApplication(None)
mapped_value = portal.portal_domains.generateMultivaluedMappedValue(
tmp_context, tmp_context,
portal_type=portal_type_list, portal_type=portal_type_list,
has_cell_content=0, **tmp_kw) has_cell_content=0,
sort_method=sort_method, **kw)
# Get price parameters # Get price parameters
price_parameter_dict = { price_parameter_dict = {
'base_price': None, 'base_price': None,
......
...@@ -63,7 +63,7 @@ class TradeModelLine(AmountGeneratorLine): ...@@ -63,7 +63,7 @@ class TradeModelLine(AmountGeneratorLine):
if self._baseGetQuantity(None) is not None: if self._baseGetQuantity(None) is not None:
return ('quantity', 'price', 'step') return ('quantity', 'price', 'step')
# Else tax provides only a ratio on amount # Else tax provides only a ratio on amount
return ('price', 'efficiency') return ('price',)
def getMappedValueBaseCategoryList(self): def getMappedValueBaseCategoryList(self):
return self._baseGetMappedValueBaseCategoryList() or ('trade_phase',) return self._baseGetMappedValueBaseCategoryList() or ('trade_phase',)
......
...@@ -92,6 +92,7 @@ class Transformation(MappedValue, VariatedMixin, Amount, AmountGeneratorMixin): ...@@ -92,6 +92,7 @@ class Transformation(MappedValue, VariatedMixin, Amount, AmountGeneratorMixin):
# XXX add a 'transformation_amount_generator' group type # XXX add a 'transformation_amount_generator' group type
kw['amount_generator_type_list'] = ('Transformation', kw['amount_generator_type_list'] = ('Transformation',
'Transformed Resource', 'Transformed Resource',
'Transformation Operation',
'Assorted Resource') 'Assorted Resource')
if context is not None: if context is not None:
context = (context,) context = (context,)
......
...@@ -63,8 +63,7 @@ class TransformedResource(AmountGeneratorLine): ...@@ -63,8 +63,7 @@ class TransformedResource(AmountGeneratorLine):
# Provide default mapped value properties and categories if # Provide default mapped value properties and categories if
# not defined # not defined
def getMappedValuePropertyList(self): def getMappedValuePropertyList(self):
return self._baseGetMappedValuePropertyList() or ( return self._baseGetMappedValuePropertyList() or ('quantity',)
'converted_quantity', 'efficiency')
def getMappedValueBaseCategoryList(self): def getMappedValueBaseCategoryList(self):
result = self._baseGetMappedValueBaseCategoryList() result = self._baseGetMappedValueBaseCategoryList()
......
...@@ -30,6 +30,7 @@ import random ...@@ -30,6 +30,7 @@ import random
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Acquisition import Implicit from Acquisition import Implicit
from Products.ERP5.AggregatedAmountList import AggregatedAmountList
from Products.ERP5Type import Permissions, interfaces from Products.ERP5Type import Permissions, interfaces
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5.Document.MappedValue import MappedValue from Products.ERP5.Document.MappedValue import MappedValue
...@@ -167,7 +168,7 @@ class AmountGeneratorMixin: ...@@ -167,7 +168,7 @@ class AmountGeneratorMixin:
portal.getPortalAmountGeneratorCellTypeList() portal.getPortalAmountGeneratorCellTypeList()
# Set empty result by default # Set empty result by default
result = [] result = AggregatedAmountList()
args = (getTransactionalVariable().setdefault( args = (getTransactionalVariable().setdefault(
"amount_generator.BaseAmountDict", {}), "amount_generator.BaseAmountDict", {}),
...@@ -230,15 +231,20 @@ class AmountGeneratorMixin: ...@@ -230,15 +231,20 @@ class AmountGeneratorMixin:
'base_contribution_set': set(), 'base_contribution_set': set(),
'category_list': [], 'category_list': [],
'causality_value_list': [], 'causality_value_list': [],
'efficiency': self.getEfficiency(),
'quantity_unit': self.getQuantityUnit(),
# XXX If they are several cells, we have duplicate references. # XXX If they are several cells, we have duplicate references.
'reference': self.getReference(), 'reference': self.getReference(),
} }
# 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():
if key in ('net_converted_quantity',
'net_quantity', 'converted_quantity'):
# XXX only 'quantity' is accepted and it is treated
# as if it was 'converted_quantity'
raise NotImplementedError
# XXX-JPS Make sure handling of list properties can be handled # XXX-JPS Make sure handling of list properties can be handled
dict_key = key in ('net_quantity', 'converted_quantity', property_dict[key] = cell.getProperty(key)
'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
...@@ -276,9 +282,7 @@ class AmountGeneratorMixin: ...@@ -276,9 +282,7 @@ class AmountGeneratorMixin:
# base_contribution_list - needed to produce reports with # base_contribution_list - needed to produce reports with
# getTotalPrice # getTotalPrice
# 'efficiency' is stored separately in the generated amount, # 'efficiency' is stored separately in the generated amount,
# for future simulation of efficiencies (use net_quantity otherwise). # for future simulation of efficiencies.
# 'converted_quantity' is used preferrably to 'quantity' since we
# need values converted to the default management unit.
# If no quantity is provided, we consider that the value is 1.0 # If no quantity is provided, we consider that the value is 1.0
# (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,
...@@ -297,6 +301,8 @@ class AmountGeneratorMixin: ...@@ -297,6 +301,8 @@ class AmountGeneratorMixin:
# we only want the id to be unique so we pick a random causality # we only want the id to be unique so we pick a random causality
causality_value.getRelativeUrl().replace('/', '_')) causality_value.getRelativeUrl().replace('/', '_'))
amount._setCategoryList(property_dict.pop('category_list', ())) amount._setCategoryList(property_dict.pop('category_list', ()))
if amount.getQuantityUnit():
del property_dict['quantity_unit']
amount._edit( amount._edit(
quantity=quantity, quantity=quantity,
# XXX Are title, int_index and description useful ?? # XXX Are title, int_index and description useful ??
...@@ -304,6 +310,9 @@ class AmountGeneratorMixin: ...@@ -304,6 +310,9 @@ class AmountGeneratorMixin:
int_index=self.getIntIndex(), int_index=self.getIntIndex(),
description=self.getDescription(), description=self.getDescription(),
**property_dict) **property_dict)
# convert to default management unit if possible
amount._setQuantity(amount.getConvertedQuantity())
amount._setQuantityUnit(amount.getResourceDefaultQuantityUnit())
if rounding: if rounding:
# We hope here that rounding is sufficient at line level # We hope here that rounding is sufficient at line level
amount = getRoundingProxy(amount, context=self) amount = getRoundingProxy(amount, context=self)
...@@ -341,7 +350,7 @@ class AmountGeneratorMixin: ...@@ -341,7 +350,7 @@ class AmountGeneratorMixin:
amount_list=amount_list, rounding=rounding, amount_list=amount_list, rounding=rounding,
amount_generator_type_list=amount_generator_type_list) amount_generator_type_list=amount_generator_type_list)
aggregated_amount_dict = {} aggregated_amount_dict = {}
result_list = [] result_list = AggregatedAmountList()
for amount in generated_amount_list: for amount in generated_amount_list:
key = (amount.getPrice(), amount.getEfficiency(), key = (amount.getPrice(), amount.getEfficiency(),
amount.getReference(), amount.categories) amount.getReference(), amount.categories)
......
...@@ -155,7 +155,8 @@ class TestApparelTransformation(TestOrderMixin, ERP5TypeTestCase): ...@@ -155,7 +155,8 @@ class TestApparelTransformation(TestOrderMixin, ERP5TypeTestCase):
portal = self.getPortal() portal = self.getPortal()
operation_dict = {} operation_dict = {}
for operation_name in ('piquage', 'taillage'): for operation_name in ('piquage', 'taillage'):
operation = portal.portal_categories.operation.newContent(id=operation_name) operation = portal.portal_categories.operation.newContent(operation_name,
quantity_unit='time/min')
operation_dict[operation_name] = operation operation_dict[operation_name] = operation
sequence.edit(operation_dict=operation_dict) sequence.edit(operation_dict=operation_dict)
...@@ -331,8 +332,7 @@ class TestApparelTransformation(TestOrderMixin, ERP5TypeTestCase): ...@@ -331,8 +332,7 @@ class TestApparelTransformation(TestOrderMixin, ERP5TypeTestCase):
operation.edit( operation.edit(
title = op_name, title = op_name,
quantity = 10., quantity = 10.,
categories = operation.getCategoryList() + [ 'resource/' + operation_dict[op_name].getRelativeUrl(), resource_value=operation_dict[op_name],
'quantity_unit/time/min'],
int_index=4, int_index=4,
) )
...@@ -346,8 +346,7 @@ class TestApparelTransformation(TestOrderMixin, ERP5TypeTestCase): ...@@ -346,8 +346,7 @@ class TestApparelTransformation(TestOrderMixin, ERP5TypeTestCase):
operation = transformation.newContent(portal_type=self.operation_portal_type) operation = transformation.newContent(portal_type=self.operation_portal_type)
operation.edit( operation.edit(
title = op_name, title = op_name,
categories = operation.getCategoryList() + [ 'resource/' + operation_dict[op_name].getRelativeUrl(), resource_value=operation_dict[op_name],
'quantity_unit/time/min'],
int_index=5, int_index=5,
) )
base_category_list = ['size'] base_category_list = ['size']
...@@ -629,21 +628,17 @@ class TestApparelTransformation(TestOrderMixin, ERP5TypeTestCase): ...@@ -629,21 +628,17 @@ class TestApparelTransformation(TestOrderMixin, ERP5TypeTestCase):
produced_resource = transformation.getResource() produced_resource = transformation.getResource()
production_order_module = self.portal.getDefaultModule("Production Order") production_order_module = self.portal.getDefaultModule("Production Order")
production_order = production_order_module.newContent( production_order = production_order_module.newContent(
portal_type="Production Order") portal_type="Production Order",
temp_object=1,
specialise_value=transformation)
for i, expected in enumerate(expected_list): for i, expected in enumerate(expected_list):
context = production_order.newContent( context = production_order.newContent(
portal_type="Production Order Line") portal_type="Production Order Line",
context.edit( quantity=1,
quantity = 1.0, variation_category_list=expected['id'],
variation_category_list = expected['id'], resource=produced_resource,
resource = produced_resource,
specialise=transformation.getRelativeUrl(),
) )
aggregated_amount_list = context.getAggregatedAmountList( aggregated_amount_list = context.getAggregatedAmountList()
amount_generator_type_list=("Transformation",
"Transformation Transformed Resource",
"Transformation Operation",
))
expected_amount_list = expected['amount'] expected_amount_list = expected['amount']
expected_amount_list_len = len(expected_amount_list) expected_amount_list_len = len(expected_amount_list)
......
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