From e56cb1c36f85d578427b787f6b990402b4caa38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Wed, 28 Oct 2009 14:21:48 +0000 Subject: [PATCH] calculateSeparatePrice should not simply compare floats for equality, for now we'll compare with an arbitrary precision, untill we have a good way of specifying this. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30065 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/MovementGroup.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/product/ERP5/MovementGroup.py b/product/ERP5/MovementGroup.py index e9053a9b55..695a7f18c5 100644 --- a/product/ERP5/MovementGroup.py +++ b/product/ERP5/MovementGroup.py @@ -228,13 +228,22 @@ class MovementGroupNode: def calculateSeparatePrice(self, movement, added_movement=None): """ Separate movements which have different price """ - if added_movement is not None and \ - movement.getPrice() == added_movement.getPrice() : - new_movement = self._genericCalculation(movement, - added_movement=added_movement) - new_movement.setPriceMethod('getAveragePrice') - new_movement.setQuantityMethod("getAddQuantity") - return new_movement, None + if added_movement is not None: + # XXX To prevent float rounding issue, we round the price with an + # arbirary precision before comparision. + movement_price = movement.getPrice() + if movement_price is not None: + movement_price = round(movement_price, 5) + added_movement_price = added_movement.getPrice() + if added_movement_price is not None: + added_movement_price = round(added_movement_price, 5) + + if movement_price == added_movement_price: + new_movement = self._genericCalculation(movement, + added_movement=added_movement) + new_movement.setPriceMethod('getAveragePrice') + new_movement.setQuantityMethod("getAddQuantity") + return new_movement, None return movement, added_movement def calculateAddQuantity(self, movement, added_movement=None): -- 2.30.9