Commit d6d958be authored by Jérome Perrin's avatar Jérome Perrin

core: handle price 0 or None in Inventory API

parent 8ba71199
Pipeline #35799 failed with stage
in 0 seconds
......@@ -422,7 +422,7 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin):
quantity = self.getQuantity()
if quantity :
source_asset_price = self.getSourceAssetPrice()
if source_asset_price :
if source_asset_price is not None:
return source_asset_price * - quantity
return None
......@@ -466,7 +466,7 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin):
quantity = self.getQuantity()
if quantity :
destination_asset_price = self.getDestinationAssetPrice()
if destination_asset_price :
if destination_asset_price is not None:
return destination_asset_price * quantity
return None
......@@ -520,7 +520,7 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin):
def _getAssetPrice(self,section,date):
price = self.getPrice()
if section is None or not price or getattr(
if section is None or price is None or getattr(
section.aq_base, 'getPriceCurrencyValue', None
) is None:
return price
......
......@@ -1715,7 +1715,7 @@ class TestMovementHistoryList(InventoryAPITestCase):
# default is an empty list
self.assertEqual(0, len(mvt_history_list))
def testDefault0(self):
def testDefaultNone(self):
self._makeMovement()
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
mvt_history_list = getMovementHistoryList(
......@@ -1725,6 +1725,32 @@ class TestMovementHistoryList(InventoryAPITestCase):
# If a movement have no price, None is returned
self.assertEqual(None, mvt_history_list[0].total_price)
def testPriceZero(self):
self._makeMovement(quantity=1, price=0)
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
self.assertEqual(
[(b.total_quantity, b.total_price) for b in getMovementHistoryList(section_uid=self.section.getUid())],
[(1, 0), ]
)
self.assertEqual(
[(b.total_quantity, b.total_price) for b in getMovementHistoryList(section_uid=self.mirror_section.getUid())],
[(-1, 0), ]
)
def testPriceNone(self):
self._makeMovement(quantity=1, price=None)
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
mvt_history_list = getMovementHistoryList(
section_uid=self.section.getUid(),)
self.assertEqual(
[(b.total_quantity, b.total_price) for b in getMovementHistoryList(section_uid=self.section.getUid())],
[(1, None), ]
)
self.assertEqual(
[(b.total_quantity, b.total_price) for b in getMovementHistoryList(section_uid=self.mirror_section.getUid())],
[(-1, None), ]
)
def testMovementBothSides(self):
"""Movement History List returns movement from both sides"""
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
......
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