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
from zLOG import LOG, ERROR
from warnings import warn
class Amount(Base, Variated):
......@@ -74,16 +74,22 @@ class Amount(Base, Variated):
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationCategoryList')
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
(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 = []
resource = self.getDefaultResourceValue()
if resource is not None:
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 :
variation_list = filter(lambda x: x in base_category_list,
resource_variation_list)
......@@ -151,15 +157,21 @@ class Amount(Base, Variated):
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryList')
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
amount.
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 = []
for category in self.getVariationCategoryList(
omit_option_base_category=omit_option_base_category):
omit_optional_variation=omit_optional_variation):
base_category = category.split('/')[0]
if base_category not in base_category_list:
base_category_list.append(base_category)
......@@ -231,7 +243,8 @@ class Amount(Base, Variated):
security.declareProtected(Permissions.AccessContentsInformation,
'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.
the variation base category of the resource (not the
......@@ -242,27 +255,39 @@ class Amount(Base, Variated):
getVariationRangeBaseCategoryList -> notion of
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()
if resource is not None:
result = resource.getVariationBaseCategoryList(
omit_option_base_category=omit_option_base_category)
omit_optional_variation=omit_optional_variation)
else:
result = Variated.getVariationRangeBaseCategoryList(self)
return result
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeBaseCategoryItemList')
def getVariationRangeBaseCategoryItemList(self, omit_option_base_category=0,
display_id="title",
def getVariationRangeBaseCategoryItemList(self, omit_optional_variation=0,
omit_option_base_category=None, display_id="title",
display_none_category=0):
"""
Returns possible variations base categories for this amount ie.
the variation base category of the resource (not the
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(
self.getVariationRangeBaseCategoryList(
omit_option_base_category=omit_option_base_category),
omit_optional_variation=omit_optional_variation),
display_id=display_id,
display_none_category=display_none_category)
......
......@@ -479,7 +479,7 @@ class OrderBuilder(XMLObject, Amount, Predicate):
if object_to_update is None:
# create a new cell
cell_key = movement.getVariationCategoryList(
omit_option_base_category=1)
omit_optional_variation=1)
if not delivery_line.hasCell(base_id=base_id, *cell_key):
cell = delivery_line.newCell(base_id=base_id, \
portal_type=self.getDeliveryCellPortalType(),
......
......@@ -33,6 +33,7 @@ Define in this file all classes intended to group every kind of movement
"""
from zLOG import LOG, DEBUG
from warnings import warn
from Products.PythonScripts.Utility import allow_class
class MovementRejected(Exception) : pass
......@@ -873,21 +874,35 @@ class FakeMovement:
path_list.append(movement.getPath())
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
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(
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
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(
omit_option_base_category=omit_option_base_category,**kw)
omit_optional_variation=omit_optional_variation, **kw)
def edit(self, **kw):
"""
......
......@@ -34,6 +34,8 @@ from Products.ERP5Type import Context, Interface, Permissions
from Products.ERP5Type.Base import Base
from Products.CMFCategory.Renderer import Renderer
from warnings import warn
class Variated(Base):
"""
Variated is a mix-in class for all classes which implement
......@@ -59,14 +61,21 @@ class Variated(Base):
security.declareProtected(Permissions.AccessContentsInformation,
'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.
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).
"""
#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()
if omit_option_base_category == 1:
if omit_optional_variation == 1:
# XXX First implementation
# option base category list is a portal method, until the creation
# of a good API.
......@@ -85,30 +94,41 @@ class Variated(Base):
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationCategoryList')
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
"""
#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(
base_category_list=base_category_list)
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationCategoryItemList')
def getVariationCategoryItemList(self, base_category_list=(), base=1,
display_id='logical_path',
display_base_category=1,
current_category=None,
omit_option_base_category=0,**kw):
display_id='logical_path', display_base_category=1,
current_category=None, omit_optional_variation=0,
omit_option_base_category=None, **kw):
"""
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 = []
if current_category is not None:
variation_category_item_list.append((current_category,current_category))
if base_category_list is ():
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
self.getPortalOptionBaseCategoryList()]
# Prepare 2 rendering
......@@ -202,15 +222,21 @@ class Variated(Base):
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryItemList')
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
as a list of tuples (title, id). This is mostly
useful in ERP5Form instances to generate selection
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(
omit_option_base_category=omit_option_base_category)
omit_optional_variation=omit_optional_variation)
result = []
for base_category in variation_base_category_list:
bc = self.portal_categories.resolveCategory(base_category)
......
......@@ -250,8 +250,7 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
portal_type=self.inventory_line_portal_type)
inventory_line.edit(resource_value = resource)
resource_vcl = list(resource.getVariationCategoryList(
omit_individual_variation=1,
omit_option_base_category=1))
omit_individual_variation=1, omit_optional_variation=1))
resource_vcl.sort()
self.assertEquals(len(resource_vcl),2)
inventory_line.setVariationCategoryList(resource_vcl)
......
......@@ -320,7 +320,7 @@ class TestOrderMixin:
"""
order_line = sequence.get('order_line')
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)
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