diff --git a/product/ERP5/Tool/SimulationTool.py b/product/ERP5/Tool/SimulationTool.py index a52711fb7d32a2cb52384892879054d9ecc268e4..4225dee4f214a231a7ee37691e0cbf0c7363013f 100644 --- a/product/ERP5/Tool/SimulationTool.py +++ b/product/ERP5/Tool/SimulationTool.py @@ -454,7 +454,7 @@ class SimulationTool (BaseTool): if len(group_by_expression_list): # Always group by resource group_by_expression_list.append('%s.resource_uid' % table) - sql_kw['group_by_expression'] = ', '.join(group_by_expression_list) + new_kw['group_by_expression'] = ', '.join(group_by_expression_list) sql_kw.update(self.portal_catalog.buildSQLQuery(**new_kw)) return sql_kw diff --git a/product/ERP5/tests/testInventoryAPI.py b/product/ERP5/tests/testInventoryAPI.py index 5329db315e7a23329d8acfb256808f688b32f20d..c52cf101031cfab18655af91630fac8fdea3eaf8 100644 --- a/product/ERP5/tests/testInventoryAPI.py +++ b/product/ERP5/tests/testInventoryAPI.py @@ -77,6 +77,7 @@ class InventoryAPITestCase(ERP5TypeTestCase): self.section = self._makeOrganisation(title='Section') self.node = self._makeOrganisation(title='Node') + self.other_node = self._makeOrganisation(title='Other Node') self.payment_node = self.section.newContent( title='Payment Node', portal_type='Bank Account') @@ -497,6 +498,34 @@ class TestInventory(InventoryAPITestCase): class TestInventoryList(InventoryAPITestCase): """Tests getInventoryList methods. """ + def test_ReturnedTypeIsList(self): + """Inventory List returns a sequence object""" + getInventoryList = self.getSimulationTool().getInventoryList + inventory_list = getInventoryList() + self.assertEquals(str(inventory_list.__class__), + 'Shared.DC.ZRDB.Results.Results') + # the brain is InventoryListBrain + self.assert_('InventoryListBrain' in + [c.__name__ for c in inventory_list._class.__bases__]) + # default is an empty list + self.assertEquals(0, len(inventory_list)) + + def test_GroupByNode(self): + getInventoryList = self.getSimulationTool().getInventoryList + self._makeMovement(quantity=100) + self._makeMovement(destination_value=self.other_node, quantity=100) + self._makeMovement(destination_value=None, quantity=100) + inventory_list = getInventoryList(group_by_node=1) + self.assertEquals(3, len(inventory_list)) + self.assertEquals([r for r in inventory_list if r.node_relative_url == + self.node.getRelativeUrl()][0].inventory, 100) + self.assertEquals([r for r in inventory_list if r.node_relative_url == + self.other_node.getRelativeUrl()][0].inventory, 100) + self.assertEquals([r for r in inventory_list if r.node_relative_url == + self.mirror_node.getRelativeUrl()][0].inventory, -300) + + # TODO group by mirror_node, section, mirror_section, payment, resource + # ? and maybe project, function, portal_type ? class TestMovementHistoryList(InventoryAPITestCase): """Tests Movement history list methods.