Commit 985cd3be authored by Jérome Perrin's avatar Jérome Perrin

fix calculateSeparatePrice implementation

get rid of string exceptions


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4407 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 96dda890
...@@ -37,6 +37,9 @@ from Globals import InitializeClass, DTMLFile ...@@ -37,6 +37,9 @@ from Globals import InitializeClass, DTMLFile
from zLOG import LOG from zLOG import LOG
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
class MovementRejected(Exception) : pass
class FakeMovementError(Exception) : pass
class RootMovementGroup: class RootMovementGroup:
def __init__(self, class_list, movement=None, last_line_class_name=None, def __init__(self, class_list, movement=None, last_line_class_name=None,
...@@ -80,11 +83,11 @@ class RootMovementGroup: ...@@ -80,11 +83,11 @@ class RootMovementGroup:
group.append(movement) group.append(movement)
is_movement_in_group = 1 is_movement_in_group = 1
break break
except "MovementRejected": except MovementRejected:
if self.__class__.__name__ == self._last_line_class_name: if self.__class__.__name__ == self._last_line_class_name:
pass pass
else: else:
raise "MovementRejected" raise MovementRejected
if is_movement_in_group == 0 : if is_movement_in_group == 0 :
if self._nested_class is not None: if self._nested_class is not None:
self._appendGroup(movement) self._appendGroup(movement)
...@@ -99,7 +102,7 @@ class RootMovementGroup: ...@@ -99,7 +102,7 @@ class RootMovementGroup:
if split_movement_list != [None]: if split_movement_list != [None]:
# We rejected a movement, we need to put it on another line # We rejected a movement, we need to put it on another line
# Or to create a new one # Or to create a new one
raise "MovementRejected" raise MovementRejected
else: else:
# No movement on this node, we can add it # No movement on this node, we can add it
self._movement_list.append(movement) self._movement_list.append(movement)
...@@ -141,7 +144,7 @@ class RootMovementGroup: ...@@ -141,7 +144,7 @@ class RootMovementGroup:
""" """
movement_list = self.getMovementList() movement_list = self.getMovementList()
if len(movement_list) != 1: if len(movement_list) != 1:
raise "ProgrammingError", "Can separate only 2 movements" raise ValueError, "Can separate only 2 movements"
else: else:
old_movement = self.getMovementList()[0] old_movement = self.getMovementList()[0]
...@@ -184,13 +187,14 @@ class RootMovementGroup: ...@@ -184,13 +187,14 @@ class RootMovementGroup:
return new_movement, None return new_movement, None
def calculateSeparatePrice(self, movement, added_movement=None): def calculateSeparatePrice(self, movement, added_movement=None):
""" Separate movement which have the same price """ Separate movements which have different price
""" """
if added_movement is not None and \ if added_movement is not None and \
movement.getPrice() == added_movement.getPrice() : movement.getPrice() == added_movement.getPrice() :
new_movement = self._genericCalculation(movement, new_movement = self._genericCalculation(movement,
added_movement=added_movement) added_movement=added_movement)
new_movement.setPriceMethod('getAddQuantity') new_movement.setPriceMethod('getAveragePrice')
new_movement.setQuantityMethod("getAddQuantity")
return new_movement, None return new_movement, None
return movement, added_movement return movement, added_movement
...@@ -580,7 +584,7 @@ class FakeMovement: ...@@ -580,7 +584,7 @@ class FakeMovement:
self.append(movement) self.append(movement)
# This object must not be use when there is not 2 or more movements # This object must not be use when there is not 2 or more movements
if len(movement_list) < 2: if len(movement_list) < 2:
raise "ProgrammingError", "FakeMovement used where it does not." raise ValueError, "FakeMovement used where it does not."
# All movements must share the same getVariationCategoryList # All movements must share the same getVariationCategoryList
# So, verify and raise a error if not # So, verify and raise a error if not
# But, if DeliveryBuilder is well configured, this can never append ;) # But, if DeliveryBuilder is well configured, this can never append ;)
...@@ -600,7 +604,7 @@ class FakeMovement: ...@@ -600,7 +604,7 @@ class FakeMovement:
break break
if error_raising_needed == 1: if error_raising_needed == 1:
raise "ProgrammingError", "FakeMovement not well used." raise ValueError, "FakeMovement not well used."
def append(self, movement): def append(self, movement):
""" """
...@@ -767,7 +771,7 @@ class FakeMovement: ...@@ -767,7 +771,7 @@ class FakeMovement:
elif key == 'delivery_value': elif key == 'delivery_value':
self.setDeliveryValue(kw[key]) self.setDeliveryValue(kw[key])
else: else:
raise "FakeMovementError",\ raise FakeMovementError,\
"Could not call edit on Fakeovement with parameters: %r" % key "Could not call edit on Fakeovement with parameters: %r" % key
# XXX This should not be here # XXX This should not be here
......
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