Commit 78e1bfe9 authored by Romain Courteaud's avatar Romain Courteaud

Clean variation method and make the code more generic.

Fix testTransformation (variation was not well defined).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5246 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 13b3ccf0
......@@ -132,7 +132,8 @@ class Amount(Base, Variated):
render(object_list))
return variation_category_item_list
security.declareProtected(Permissions.ModifyPortalContent, '_setVariationCategoryList')
security.declareProtected(Permissions.ModifyPortalContent,
'_setVariationCategoryList')
def _setVariationCategoryList(self, value):
result = []
resource = self.getDefaultResourceValue()
......@@ -141,7 +142,8 @@ class Amount(Base, Variated):
if len(variation_list) > 0:
self._setCategoryMembership(variation_list, value, base = 1)
security.declareProtected(Permissions.ModifyPortalContent, 'setVariationCategoryList')
security.declareProtected(Permissions.ModifyPortalContent,
'setVariationCategoryList')
def setVariationCategoryList(self, value):
self._setVariationCategoryList(value)
self.reindexObject()
......@@ -162,7 +164,18 @@ class Amount(Base, Variated):
base_category_list.append(base_category)
return base_category_list
security.declareProtected(Permissions.AccessContentsInformation, 'getVariationValue')
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryItemList')
def getVariationBaseCategoryItemList(self,display_id='title_or_id',**kw):
"""
Returns a list of base_category tuples.
"""
return self.portal_categories.getItemList(
self.getVariationBaseCategoryList(),
display_id=display_id,**kw)
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationValue')
def getVariationValue(self):
"""
New Method for dicrete and countinuous variations
......@@ -215,7 +228,7 @@ class Amount(Base, Variated):
base=base, **kw)]
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeBaseCategoryList')
'getVariationRangeBaseCategoryList')
def getVariationRangeBaseCategoryList(self, omit_option_base_category=0):
"""
Returns possible variations base categories for this amount ie.
......@@ -232,7 +245,7 @@ class Amount(Base, Variated):
result = resource.getVariationBaseCategoryList(
omit_option_base_category=omit_option_base_category)
else:
result = self.portal_categories.getBaseCategoryList()
result = Variated.getVariationRangeBaseCategoryList(self)
return result
security.declareProtected(Permissions.AccessContentsInformation,
......
......@@ -60,20 +60,23 @@ class Consumption(XMLObject, XMLMatrix, Variated):
# , PropertySheet.Consumption
)
security.declareProtected(Permissions.ModifyPortalContent, '_setVariationCategoryList')
security.declareProtected(Permissions.ModifyPortalContent,
'_setVariationCategoryList')
def _setVariationCategoryList(self,value):
"""
Set consumption variation category list.
Set matrix cell range.
"""
self._setCategoryMembership(self.getVariationRangeBaseCategoryList(),value,base=1)
self._setCategoryMembership(self.getVariationRangeBaseCategoryList(),
value, base=1)
# XXX Must use in futur this method, but it failed today
#Variated._setVariationCategoryList(self, value)
# XXX FIXME: Use a interaction workflow instead
# Kept for compatibility.
self.updateCellRange(base_id='quantity')
security.declareProtected(Permissions.ModifyPortalContent, 'setVariationCategoryList')
security.declareProtected(Permissions.ModifyPortalContent,
'setVariationCategoryList')
def setVariationCategoryList(self,value):
"""
Set consumption variation category list.
......@@ -82,14 +85,8 @@ class Consumption(XMLObject, XMLMatrix, Variated):
self._setVariationCategoryList(value)
self.reindexObject()
security.declareProtected(Permissions.ModifyPortalContent, 'getVariationRangeBaseCategoryList')
def getVariationRangeBaseCategoryList(self):
"""
Return range of base variation
"""
return self.getPortalVariationBaseCategoryList()
security.declareProtected(Permissions.ModifyPortalContent, 'getVariationRangeBaseCategoryItemList')
security.declareProtected(Permissions.ModifyPortalContent,
'getVariationRangeBaseCategoryItemList')
def getVariationRangeBaseCategoryItemList(self):
"""
Return range of base variation item
......@@ -98,33 +95,18 @@ class Consumption(XMLObject, XMLMatrix, Variated):
# XXX get TitleOrId
return map( lambda x: (x,x) , self.getVariationRangeBaseCategoryList() )
security.declareProtected(Permissions.ModifyPortalContent, 'getVariationRangeCategoryList')
def getVariationRangeCategoryList(self):
"""
Return range of variation
"""
result = self.portal_categories.getCategoryChildList(self.getVariationBaseCategoryList(), base=0)
return result
security.declareProtected(Permissions.ModifyPortalContent, 'getVariationRangeCategoryItemList')
def getVariationRangeCategoryItemList(self):
"""
Return range of variation item
"""
# We need a left display for ListField, and self.portal_categories.getCategoryChildTitleItemList return a right display
# So, invert all tuples
result = map( lambda x: (x[1],x[0]), self.portal_categories.getCategoryChildTitleItemList(self.getVariationBaseCategoryList(), base=1) )
return result
security.declareProtected(Permissions.ModifyPortalContent, 'getQuantityRatio')
def getQuantityRatio(self, variation_category_line, variation_category_column):
security.declareProtected(Permissions.ModifyPortalContent,
'getQuantityRatio')
def getQuantityRatio(self, variation_category_line,
variation_category_column):
"""
Return quantity ratio for a virtual cell.
Return None if not result can be return.
"""
cell_quantity_ratio_list = []
for variation_category in (variation_category_line, variation_category_column):
for variation_category in (variation_category_line,
variation_category_column):
cell = self.getCell(variation_category, base_id='quantity')
if cell is None:
return None
......
......@@ -77,7 +77,8 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated):
updateRelatedContent = XMLMatrix.updateRelatedContent
# Explicit acquisition of aq_dynamic generated method
security.declareProtected(Permissions.AccessContentsInformation, 'getSimulationState')
security.declareProtected(Permissions.AccessContentsInformation,
'getSimulationState')
def getSimulationState(self):
"""
Explicitly acquire simulation_state from parent
......
......@@ -187,12 +187,12 @@ class Resource(XMLMatrix, CoreResource, Variated):
# XXX now, call Renderer a lot of time.
# Better implementation needed
result.extend(Renderer(
base_category=base_category,
display_base_category=display_base_category,
display_none_category=0, base=base,
current_category=current_category,
display_id=display_id, **kw).\
render([object]))
base_category=base_category,
display_base_category=display_base_category,
display_none_category=0, base=base,
current_category=current_category,
display_id=display_id, **kw).\
render([object]))
return result
security.declareProtected(Permissions.AccessContentsInformation,
......@@ -228,8 +228,8 @@ class Resource(XMLMatrix, CoreResource, Variated):
| morphology/2 | (morphology/2, )
"""
vcil = self.getVariationCategoryItemList(
base_category_list=base_category_list,
omit_individual_variation=omit_individual_variation,**kw)
base_category_list=base_category_list,
omit_individual_variation=omit_individual_variation,**kw)
return map(lambda x: x[1], vcil)
# Unit conversion
......
......@@ -95,24 +95,6 @@ class Transformation(XMLObject, Predicate, Variated):
for transformation_line in transformation_line_list:
transformation_line.updateVariationCategoryList()
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeBaseCategoryList')
def getVariationRangeBaseCategoryList(self):
"""
Returns possible variation base_category ids of the
default resource which can be used a variation axis
in the transformation.
"""
resource = self.getResourceValue()
if resource is not None:
result = resource.getVariationBaseCategoryList()
else:
# XXX result = self.getBaseCategoryIds()
# Why calling this method ?
# Get a global variable which define a list of variation base category
result = self.getPortalVariationBaseCategoryList()
return result
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeBaseCategoryItemList')
def getVariationRangeBaseCategoryItemList(self,display_id='title_or_id',**kw):
......@@ -122,39 +104,14 @@ class Transformation(XMLObject, Predicate, Variated):
useful in ERP5Form instances to generate selection
menus.
"""
return self.portal_categories.getItemList( self.getVariationRangeBaseCategoryList(),
display_id=display_id,**kw )
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeCategoryList')
def getVariationRangeCategoryList(self, base_category_list=()):
"""
Returns possible variation category values for the
transformation according to the default resource.
Possible category values is provided as a list of
id.
User may want to define generic transformation without
any resource define.
Result is left display.
"""
if base_category_list is ():
base_category_list = self.getVariationBaseCategoryList()
resource = self.getResourceValue()
if resource != None:
result = resource.getVariationCategoryList(
base_category_list=base_category_list,
omit_individual_variation=0)
else:
# No resource is define on transformation. We want to display content of base categories
result = self.portal_categories.getCategoryChildList(base_category_list, base=1)
return result
return self.portal_categories.getItemList(
self.getVariationRangeBaseCategoryList(),
display_id=display_id, **kw)
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeCategoryItemList')
def getVariationRangeCategoryItemList(self, base_category_list=(),
display_base_category=1,**kw):
display_base_category=1, **kw):
"""
Returns possible variation category values for the
transformation according to the default resource.
......@@ -171,24 +128,16 @@ class Transformation(XMLObject, Predicate, Variated):
resource = self.getResourceValue()
if resource != None:
result = resource.getVariationCategoryItemList(
base_category_list=base_category_list,
omit_individual_variation=0,
display_base_category=display_base_category,**kw)
base_category_list=base_category_list,
omit_individual_variation=0,
display_base_category=display_base_category,**kw)
else:
# No resource is define on transformation. We want to display content of base categories
result = self.portal_categories.getCategoryChildTitleItemList(base_category_list, base=1, display_none_category=0)
# No resource is define on transformation.
# We want to display content of base categories
result = self.portal_categories.getCategoryChildTitleItemList(
base_category_list, base=1, display_none_category=0)
return result
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryItemList')
def getVariationBaseCategoryItemList(self,display_id='title_or_id',**kw):
"""
Returns a list of base_category tuples for this tranformation
"""
return self.portal_categories.getItemList(self.getVariationBaseCategoryList(),
display_id=display_id,**kw)
security.declareProtected(Permissions.AccessContentsInformation,
'_setVariationBaseCategoryList')
def _setVariationBaseCategoryList(self, value):
......
......@@ -162,51 +162,6 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount):
self._setVVariationBaseCategoryList(value)
self.reindexObject()
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeCategoryItemList')
def getVariationRangeCategoryItemList(self, base_category_list = (),
omit_individual_variation=1, base=1,
current_category=None,
display_base_category=1,
display_id='title', **kw):
"""
Returns possible variation category values for the
transformation according to the default resource.
Possible category values is provided as a list of
tuples (id, title). This is mostly
useful in ERP5Form instances to generate selection
menus.
Display is left...
"""
resource = self.getResourceValue()
result = []
if resource != None:
if base_category_list is ():
base_category_list = resource.getVariationBaseCategoryList()
result = resource.getVariationCategoryItemList(
base_category_list=base_category_list,
omit_individual_variation=0,
base=base,
current_category=current_category,
display_base_category=display_base_category,
display_id=display_id,
**kw)
return result
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeCategoryItemList')
def getVariationRangeCategoryList(self, base_category_list=()):
"""
Returns possible variation category values for the
transformation according to the default resource.
"""
return map(lambda x: x[1],
self.getVariationRangeCategoryItemList(
base_category_list=base_category_list))
return result
security.declareProtected(Permissions.AccessContentsInformation,
'getAggregatedAmountList')
def getAggregatedAmountList(self, context=None, REQUEST=None, **kw):
......
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# Copyright (c) 2002, 2006 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
......@@ -76,7 +76,8 @@ class Variated(Base):
'_getVariationCategoryList')
def _getVariationCategoryList(self, base_category_list = ()):
if base_category_list is ():
base_category_list = self.getVariationRangeBaseCategoryList()
base_category_list = self.getVariationBaseCategoryList()
# base_category_list = self.getVariationRangeBaseCategoryList()
return self.getAcquiredCategoryMembershipList(base_category_list, base=1)
security.declareProtected(Permissions.AccessContentsInformation,
......@@ -104,71 +105,83 @@ class Variated(Base):
variation_category_item_list.append((current_category,current_category))
if base_category_list is ():
base_category_list = self.getVariationRangeBaseCategoryList()
base_category_list = self.getVariationBaseCategoryList()
if omit_option_base_category == 1:
base_category_list = [x for x in base_category_list if x not in
self.getPortalOptionBaseCategoryList()]
for base_category in base_category_list:
variation_category_list = self._getVariationCategoryList(
base_category_list=[base_category])
variation_list = map(lambda x: self.portal_categories.resolveCategory(x),
variation_category_list)
variation_category_item_list.extend(Renderer(
base_category_list=[base_category])
variation_list = [self.portal_categories.resolveCategory(x) for x in \
variation_category_list]
category_list = [x for x in variation_list \
if x.getPortalType() == 'Category']
variation_category_item_list.extend(Renderer(
display_base_category=display_base_category,
display_none_category=0, base=base,
current_category=current_category,
display_id=display_id,**kw).\
render(variation_list))
display_id=display_id, **kw).\
render(category_list))
object_list = [x for x in variation_list \
if x.getPortalType() != 'Category']
variation_category_item_list.extend(Renderer(
base_category=base_category,
display_base_category=display_base_category,
display_none_category=0, base=base,
current_category=current_category,
display_id='title', **kw).\
render(object_list))
return variation_category_item_list
def getVariationCategoryTitleOrIdItemList(self, base_category_list=(), base=1, **kw):
"""
Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Uses getTitleOrId as method
"""
return self.getVariationCategoryItemList(display_id='title_or_id', base_category_list=base_category_list, base=base, **kw)
# XXX Is it used ?
# def getVariationCategoryTitleOrIdItemList(self, base_category_list=(),
# base=1, **kw):
# """
# Returns a list of tuples by parsing recursively all categories in a
# given list of base categories. Uses getTitleOrId as method
# """
# return self.getVariationCategoryItemList(
# display_id='title_or_id',
# base_category_list=base_category_list, base=base, **kw)
security.declareProtected(Permissions.ModifyPortalContent, '_setVariationCategoryList')
def _setVariationCategoryList(self, node_list, base_category_list = ()):
security.declareProtected(Permissions.ModifyPortalContent,
'_setVariationCategoryList')
def _setVariationCategoryList(self, node_list, base_category_list=()):
if base_category_list is ():
base_category_list = self.getVariationRangeBaseCategoryList()
base_category_list = self.getVariationBaseCategoryList()
self._setCategoryMembership(base_category_list,node_list,base=1)
security.declareProtected(Permissions.ModifyPortalContent, 'setVariationCategoryList')
def setVariationCategoryList(self, node_list, base_category_list = () ):
self._setVariationCategoryList(node_list, base_category_list = base_category_list)
security.declareProtected(Permissions.ModifyPortalContent,
'setVariationCategoryList')
def setVariationCategoryList(self, node_list, base_category_list=()):
self._setVariationCategoryList(node_list,
base_category_list=base_category_list)
self.reindexObject()
# Range
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeBaseCategoryList')
'getVariationRangeBaseCategoryList')
def getVariationRangeBaseCategoryList(self):
"""
Returns possible variation base_category ids of the
default resource of this transformation
Returns possible variation base_category ids.
"""
try:
resource = self.getDefaultResourceValue()
except AttributeError:
resource = None
if resource is not None:
result = resource.getVariationBaseCategoryList()
else:
result = self.portal_categories.getBaseCategoryList()
return result
# Get a portal method which defines a list of
# variation base category
return self.getPortalVariationBaseCategoryList()
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeBaseCategoryItemList')
def getVariationRangeBaseCategoryItemList(self, base=1, display_id='getTitle', current_category=None):
'getVariationRangeBaseCategoryItemList')
def getVariationRangeBaseCategoryItemList(self, base=1,
display_id='getTitle',
current_category=None):
"""
Returns possible variations of the resource
as a list of tuples (id, title). This is mostly
useful in ERP5Form instances to generate selection
menus.
"""
return self.portal_categories.getItemList(self.getVariationRangeBaseCategoryList())
return self.portal_categories.getItemList(
self.getVariationBaseCategoryList())
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryItemList')
......@@ -191,8 +204,10 @@ class Variated(Base):
return result
# Methods for matrix UI widgets
# XXX FIXME Those method are depreciated.
# We now use _asCellRange scripts.
security.declareProtected(Permissions.AccessContentsInformation,
'getLineVariationRangeCategoryItemList')
'getLineVariationRangeCategoryItemList')
def getLineVariationRangeCategoryItemList(self):
"""
Returns possible variations in line
......@@ -202,8 +217,9 @@ class Variated(Base):
except AttributeError:
resource = None
if resource is not None:
clist = resource.getVariationRangeCategoryItemList(base_category_list =
self.getVariationBaseCategoryLine(), root=0)
clist = resource.getVariationRangeCategoryItemList(
base_category_list=self.getVariationBaseCategoryLine(),
root=0)
else:
clist = [(None,None)]
return clist
......
......@@ -103,15 +103,24 @@ class TestTransformation(TestOrderMixin,ERP5TypeTestCase):
component_name = component_info['name']
component = component_module.newContent()
component_dict[component_name] = component
variation1 = component.newContent(portal_type=self.component_variation_portal_type,id='1')
variation2 = component.newContent(portal_type=self.component_variation_portal_type,id='2')
variation1 = component.newContent(
portal_type=self.component_variation_portal_type,
id='1')
variation2 = component.newContent(
portal_type=self.component_variation_portal_type,
id='2')
variations = [variation1, variation2]
# Commit and catalog
get_transaction().commit()
self.tic()
component.setPricedQuantity(component_info['quantity'])
component.setVariationBaseCategoryList(['variation'])
component.setPVariationBaseCategoryList(['variation'])
component.setCategoryList( ['variation/' + x.getRelativeUrl() for x in variations] )
# Variation are automatically acquired if they are individual variation.
# component.setCategoryList(
# ['variation/' + x.getRelativeUrl() for x in variations] )
# Set the price
supply_line = component.newContent(portal_type='Supply Line')
supply_line.edit( mapped_value_property_list = ['base_price'] )
......@@ -122,10 +131,13 @@ class TestTransformation(TestOrderMixin,ERP5TypeTestCase):
membership_criterion_category = ['variation/' + x.getRelativeUrl() for x in variations],
base_price = component_prices[0])
else:
supply_line.setVariationBaseCategoryList(['variation'])
# supply_line.setVariationBaseCategoryList(['variation'])
supply_line.updateCellRange(base_id = 'path')
for i in range(2):
supply_cell = supply_line.newCell('apparel_component_module/%s/%d' % (component.getId(),(i+1)), base_id='path')
supply_cell = supply_line.newCell(
'variation/apparel_component_module/%s/%d' % \
(component.getId(),(i+1)),
base_id='path')
supply_cell.edit(
membership_criterion_base_category = ['variation'],
membership_criterion_category = ['variation/' + variations[i].getRelativeUrl()],
......
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