Commit ffd048e3 authored by Alexandre Boeglin's avatar Alexandre Boeglin

Rename omit_option_base_category property to omit_optional_variation, such as

to make it similar to omit_individual_variation.
Keep compatibility with the old name.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20080 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f2438ef8
...@@ -38,7 +38,7 @@ from Products.CMFCategory.Renderer import Renderer ...@@ -38,7 +38,7 @@ from Products.CMFCategory.Renderer import Renderer
from zLOG import LOG, ERROR from zLOG import LOG, ERROR
from warnings import warn
class Amount(Base, Variated): class Amount(Base, Variated):
...@@ -74,16 +74,22 @@ class Amount(Base, Variated): ...@@ -74,16 +74,22 @@ class Amount(Base, Variated):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationCategoryList') 'getVariationCategoryList')
def getVariationCategoryList(self, default=[], base_category_list=(), def getVariationCategoryList(self, default=[], base_category_list=(),
omit_option_base_category=0): omit_optional_variation=0, omit_option_base_category=None):
""" """
Returns the possible discrete variations Returns the possible discrete variations
(as a list of relative urls to categories) (as a list of relative urls to categories)
""" """
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
result = [] result = []
resource = self.getDefaultResourceValue() resource = self.getDefaultResourceValue()
if resource is not None: if resource is not None:
resource_variation_list = resource.getVariationBaseCategoryList( resource_variation_list = resource.getVariationBaseCategoryList(
omit_option_base_category=omit_option_base_category) omit_optional_variation=omit_optional_variation)
if len(base_category_list) > 0 : if len(base_category_list) > 0 :
variation_list = filter(lambda x: x in base_category_list, variation_list = filter(lambda x: x in base_category_list,
resource_variation_list) resource_variation_list)
...@@ -151,15 +157,21 @@ class Amount(Base, Variated): ...@@ -151,15 +157,21 @@ class Amount(Base, Variated):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryList') 'getVariationBaseCategoryList')
def getVariationBaseCategoryList(self, default=[], def getVariationBaseCategoryList(self, default=[],
omit_option_base_category=0): omit_optional_variation=0, omit_option_base_category=None):
""" """
Return the list of base_category from all variation related to Return the list of base_category from all variation related to
amount. amount.
It is maybe a nonsense, but useful for correcting user errors. It is maybe a nonsense, but useful for correcting user errors.
""" """
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
base_category_list = [] base_category_list = []
for category in self.getVariationCategoryList( for category in self.getVariationCategoryList(
omit_option_base_category=omit_option_base_category): omit_optional_variation=omit_optional_variation):
base_category = category.split('/')[0] base_category = category.split('/')[0]
if base_category not in base_category_list: if base_category not in base_category_list:
base_category_list.append(base_category) base_category_list.append(base_category)
...@@ -231,7 +243,8 @@ class Amount(Base, Variated): ...@@ -231,7 +243,8 @@ class Amount(Base, Variated):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeBaseCategoryList') 'getVariationRangeBaseCategoryList')
def getVariationRangeBaseCategoryList(self, default=[], omit_option_base_category=0): def getVariationRangeBaseCategoryList(self, default=[],
omit_optional_variation=0, omit_option_base_category=None):
""" """
Returns possible variations base categories for this amount ie. Returns possible variations base categories for this amount ie.
the variation base category of the resource (not the the variation base category of the resource (not the
...@@ -242,29 +255,41 @@ class Amount(Base, Variated): ...@@ -242,29 +255,41 @@ class Amount(Base, Variated):
getVariationRangeBaseCategoryList -> notion of getVariationRangeBaseCategoryList -> notion of
getVariationBaseCategoryList is different getVariationBaseCategoryList is different
""" """
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
resource = self.getDefaultResourceValue() resource = self.getDefaultResourceValue()
if resource is not None: if resource is not None:
result = resource.getVariationBaseCategoryList( result = resource.getVariationBaseCategoryList(
omit_option_base_category=omit_option_base_category) omit_optional_variation=omit_optional_variation)
else: else:
result = Variated.getVariationRangeBaseCategoryList(self) result = Variated.getVariationRangeBaseCategoryList(self)
return result return result
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeBaseCategoryItemList') 'getVariationRangeBaseCategoryItemList')
def getVariationRangeBaseCategoryItemList(self, omit_option_base_category=0, def getVariationRangeBaseCategoryItemList(self, omit_optional_variation=0,
display_id="title", omit_option_base_category=None, display_id="title",
display_none_category=0): display_none_category=0):
""" """
Returns possible variations base categories for this amount ie. Returns possible variations base categories for this amount ie.
the variation base category of the resource (not the the variation base category of the resource (not the
variation range). variation range).
""" """
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
return self.portal_categories.getItemList( return self.portal_categories.getItemList(
self.getVariationRangeBaseCategoryList( self.getVariationRangeBaseCategoryList(
omit_option_base_category=omit_option_base_category), omit_optional_variation=omit_optional_variation),
display_id=display_id, display_id=display_id,
display_none_category=display_none_category) display_none_category=display_none_category)
##################################################################### #####################################################################
# Variation property API # Variation property API
......
...@@ -479,7 +479,7 @@ class OrderBuilder(XMLObject, Amount, Predicate): ...@@ -479,7 +479,7 @@ class OrderBuilder(XMLObject, Amount, Predicate):
if object_to_update is None: if object_to_update is None:
# create a new cell # create a new cell
cell_key = movement.getVariationCategoryList( cell_key = movement.getVariationCategoryList(
omit_option_base_category=1) omit_optional_variation=1)
if not delivery_line.hasCell(base_id=base_id, *cell_key): if not delivery_line.hasCell(base_id=base_id, *cell_key):
cell = delivery_line.newCell(base_id=base_id, \ cell = delivery_line.newCell(base_id=base_id, \
portal_type=self.getDeliveryCellPortalType(), portal_type=self.getDeliveryCellPortalType(),
......
...@@ -33,6 +33,7 @@ Define in this file all classes intended to group every kind of movement ...@@ -33,6 +33,7 @@ Define in this file all classes intended to group every kind of movement
""" """
from zLOG import LOG, DEBUG from zLOG import LOG, DEBUG
from warnings import warn
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
class MovementRejected(Exception) : pass class MovementRejected(Exception) : pass
...@@ -873,21 +874,35 @@ class FakeMovement: ...@@ -873,21 +874,35 @@ class FakeMovement:
path_list.append(movement.getPath()) path_list.append(movement.getPath())
return path_list return path_list
def getVariationBaseCategoryList(self, omit_option_base_category=0,**kw): def getVariationBaseCategoryList(self, omit_optional_variation=0,
omit_option_base_category=None, **kw):
""" """
Return variation base category list Return variation base category list
Which must be shared by all movement Which must be shared by all movement
""" """
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
return self.__movement_list[0].getVariationBaseCategoryList( return self.__movement_list[0].getVariationBaseCategoryList(
omit_option_base_category=omit_option_base_category,**kw) omit_optional_variation=omit_optional_variation, **kw)
def getVariationCategoryList(self, omit_option_base_category=0,**kw): def getVariationCategoryList(self, omit_optional_variation=0,
omit_option_base_category=None, **kw):
""" """
Return variation base category list Return variation base category list
Which must be shared by all movement Which must be shared by all movement
""" """
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
return self.__movement_list[0].getVariationCategoryList( return self.__movement_list[0].getVariationCategoryList(
omit_option_base_category=omit_option_base_category,**kw) omit_optional_variation=omit_optional_variation, **kw)
def edit(self, **kw): def edit(self, **kw):
""" """
......
...@@ -34,6 +34,8 @@ from Products.ERP5Type import Context, Interface, Permissions ...@@ -34,6 +34,8 @@ from Products.ERP5Type import Context, Interface, Permissions
from Products.ERP5Type.Base import Base from Products.ERP5Type.Base import Base
from Products.CMFCategory.Renderer import Renderer from Products.CMFCategory.Renderer import Renderer
from warnings import warn
class Variated(Base): class Variated(Base):
""" """
Variated is a mix-in class for all classes which implement Variated is a mix-in class for all classes which implement
...@@ -59,14 +61,21 @@ class Variated(Base): ...@@ -59,14 +61,21 @@ class Variated(Base):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryList') 'getVariationBaseCategoryList')
def getVariationBaseCategoryList(self, omit_option_base_category=0): def getVariationBaseCategoryList(self, omit_optional_variation=0,
omit_option_base_category=None):
""" """
Return the list of variation base category. Return the list of variation base category.
If omit_option_base_category==1, do not include base category If omit_optional_variation==1, do not include base category
considered as option (ex: industrial_phase). considered as option (ex: industrial_phase).
""" """
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
vbcl = self._baseGetVariationBaseCategoryList() vbcl = self._baseGetVariationBaseCategoryList()
if omit_option_base_category == 1: if omit_optional_variation == 1:
# XXX First implementation # XXX First implementation
# option base category list is a portal method, until the creation # option base category list is a portal method, until the creation
# of a good API. # of a good API.
...@@ -85,30 +94,41 @@ class Variated(Base): ...@@ -85,30 +94,41 @@ class Variated(Base):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationCategoryList') 'getVariationCategoryList')
def getVariationCategoryList(self, base_category_list=(), def getVariationCategoryList(self, base_category_list=(),
omit_option_base_category=0): omit_optional_variation=0, omit_option_base_category=None):
""" """
Returns the list of possible variations Returns the list of possible variations
""" """
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
return self._getVariationCategoryList( return self._getVariationCategoryList(
base_category_list=base_category_list) base_category_list=base_category_list)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationCategoryItemList') 'getVariationCategoryItemList')
def getVariationCategoryItemList(self, base_category_list=(), base=1, def getVariationCategoryItemList(self, base_category_list=(), base=1,
display_id='logical_path', display_id='logical_path', display_base_category=1,
display_base_category=1, current_category=None, omit_optional_variation=0,
current_category=None, omit_option_base_category=None, **kw):
omit_option_base_category=0,**kw):
""" """
Returns the list of possible variations Returns the list of possible variations
""" """
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
variation_category_item_list = [] variation_category_item_list = []
if current_category is not None: if current_category is not None:
variation_category_item_list.append((current_category,current_category)) variation_category_item_list.append((current_category,current_category))
if base_category_list is (): if base_category_list is ():
base_category_list = self.getVariationBaseCategoryList() base_category_list = self.getVariationBaseCategoryList()
if omit_option_base_category == 1: if omit_optional_variation == 1:
base_category_list = [x for x in base_category_list if x not in base_category_list = [x for x in base_category_list if x not in
self.getPortalOptionBaseCategoryList()] self.getPortalOptionBaseCategoryList()]
# Prepare 2 rendering # Prepare 2 rendering
...@@ -202,15 +222,21 @@ class Variated(Base): ...@@ -202,15 +222,21 @@ class Variated(Base):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryItemList') 'getVariationBaseCategoryItemList')
def getVariationBaseCategoryItemList(self, display_id='title_or_id', def getVariationBaseCategoryItemList(self, display_id='title_or_id',
omit_option_base_category=0): omit_optional_variation=0, omit_option_base_category=None):
""" """
Returns base category of the resource Returns base category of the resource
as a list of tuples (title, id). This is mostly as a list of tuples (title, id). This is mostly
useful in ERP5Form instances to generate selection useful in ERP5Form instances to generate selection
menus. menus.
""" """
#XXX backwards compatibility
if omit_option_base_category is not None:
warn("Please use omit_optional_variation instead of"\
" omit_option_base_category.", DeprecationWarning)
omit_optional_variation = omit_option_base_category
variation_base_category_list = self.getVariationBaseCategoryList( variation_base_category_list = self.getVariationBaseCategoryList(
omit_option_base_category=omit_option_base_category) omit_optional_variation=omit_optional_variation)
result = [] result = []
for base_category in variation_base_category_list: for base_category in variation_base_category_list:
bc = self.portal_categories.resolveCategory(base_category) bc = self.portal_categories.resolveCategory(base_category)
......
...@@ -250,8 +250,7 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -250,8 +250,7 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
portal_type=self.inventory_line_portal_type) portal_type=self.inventory_line_portal_type)
inventory_line.edit(resource_value = resource) inventory_line.edit(resource_value = resource)
resource_vcl = list(resource.getVariationCategoryList( resource_vcl = list(resource.getVariationCategoryList(
omit_individual_variation=1, omit_individual_variation=1, omit_optional_variation=1))
omit_option_base_category=1))
resource_vcl.sort() resource_vcl.sort()
self.assertEquals(len(resource_vcl),2) self.assertEquals(len(resource_vcl),2)
inventory_line.setVariationCategoryList(resource_vcl) inventory_line.setVariationCategoryList(resource_vcl)
......
...@@ -320,7 +320,7 @@ class TestOrderMixin: ...@@ -320,7 +320,7 @@ class TestOrderMixin:
""" """
order_line = sequence.get('order_line') order_line = sequence.get('order_line')
base_id = 'movement' base_id = 'movement'
vcl = order_line.getVariationCategoryList(omit_option_base_category=1) vcl = order_line.getVariationCategoryList(omit_optional_variation=1)
cell_range = order_line.OrderLine_asCellRange(matrixbox=0) cell_range = order_line.OrderLine_asCellRange(matrixbox=0)
l = len(vcl) l = len(vcl)
......
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