Commit e566e286 authored by Nicolas Dumazet's avatar Nicolas Dumazet

inventory API: allow to omit metric_type parameter in inventory

queries. Default metric type is used instead


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32160 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3bd1fc4b
...@@ -1033,21 +1033,25 @@ class SimulationTool(BaseTool): ...@@ -1033,21 +1033,25 @@ class SimulationTool(BaseTool):
result_column_id_dict = {} result_column_id_dict = {}
metric_type = kw.pop('metric_type', None)
quantity_unit = kw.pop('quantity_unit', None) quantity_unit = kw.pop('quantity_unit', None)
quantity_unit_uid = None quantity_unit_uid = None
if quantity_unit is not None: if quantity_unit is not None:
if isinstance(quantity_unit, str): if isinstance(quantity_unit, str):
quantity_unit_uid = getCategory(quantity_unit, 'quantity_unit') quantity_unit_uid = getCategory(quantity_unit, 'quantity_unit')
if quantity_unit_uid is not None: if quantity_unit_uid is not None:
result_column_id_dict['converted_quantity'] = None result_column_id_dict['converted_quantity'] = None
if metric_type is None:
# use the default metric type
metric_type = quantity_unit.split("/", 1)[0]
elif isinstance(quantity_unit, int) or isinstance(quantity_unit, float): elif isinstance(quantity_unit, int) or isinstance(quantity_unit, float):
# quantity_unit used to be a numerical parameter.. # quantity_unit used to be a numerical parameter..
raise ValueError('Numeric values for quantity_unit are not supported') raise ValueError('Numeric values for quantity_unit are not supported')
convert_quantity_result = False convert_quantity_result = False
metric_type = kw.pop('metric_type', None)
if metric_type is not None: if metric_type is not None:
metric_type_uid = getCategory(metric_type, 'metric_type') metric_type_uid = getCategory(metric_type, 'metric_type')
......
...@@ -2513,6 +2513,16 @@ class TestUnitConversion(BaseTestUnitConversion): ...@@ -2513,6 +2513,16 @@ class TestUnitConversion(BaseTestUnitConversion):
self.assertEquals(13 * .056 - 2 * .043, self.assertEquals(13 * .056 - 2 * .043,
self.convertedSimulation('mass/nutr/lipid')) self.convertedSimulation('mass/nutr/lipid'))
def testInventoryNoMetricType(self):
"""
providing only the quantity_unit argument should also work,
and the standard metric type is used
"""
self.assertEquals((11 * 123 - 789) / 1e6,
self.getSimulationTool().getInventory(
node_uid=self.node.getUid(),
quantity_unit="mass/t"))
class TestUnitConversionDefinition(BaseTestUnitConversion): class TestUnitConversionDefinition(BaseTestUnitConversion):
QUANTITY_UNIT_DICT = { QUANTITY_UNIT_DICT = {
# base: (reference, dict_of_others) # base: (reference, dict_of_others)
......
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