diff --git a/product/ERP5/Tool/SimulationTool.py b/product/ERP5/Tool/SimulationTool.py index 4225dee4f214a231a7ee37691e0cbf0c7363013f..bc50fd5676c44f9d75de8d8ba8f85e2bbab3fd27 100644 --- a/product/ERP5/Tool/SimulationTool.py +++ b/product/ERP5/Tool/SimulationTool.py @@ -172,7 +172,7 @@ class SimulationTool (BaseTool): category_tool = getToolByName(self, 'portal_categories') property_uid_list = [] if type(property) is type('') : - if as_text == 0: + if not as_text: prop_value = category_tool.getCategoryValue(property) if prop_value is None: raise ValueError, 'Category %s does not exists' % property @@ -181,7 +181,7 @@ class SimulationTool (BaseTool): property_uid_list.append(property) elif type(property) is type([]) or type(property) is type(()) : for property_item in property : - if as_text == 0: + if not as_text: prop_value = category_tool.getCategoryValue(property_item) if prop_value is None: raise ValueError, 'Category %s does not exists' % property_item @@ -193,14 +193,14 @@ class SimulationTool (BaseTool): if type(property['query']) is type('') : property['query'] = [property['query']] for property_item in property['query'] : - if as_text == 0: + if not as_text: prop_value = category_tool.getCategoryValue(property_item) if prop_value is None: raise ValueError, 'Category %s does not exists' % property_item tmp_uid_list.append(prop_value.getUid()) else: tmp_uid_list.append(property_item) - if len(tmp_uid_list) : + if tmp_uid_list: property_uid_list = {} property_uid_list['operator'] = property['operator'] property_uid_list['query'] = tmp_uid_list @@ -443,19 +443,26 @@ class SimulationTool (BaseTool): # build the group by expression group_by_expression_list = [] - if kw.get('group_by_node',0): + if kw.get('group_by_node', 0): group_by_expression_list.append('%s.node_uid' % table) - if kw.get('group_by_sub_variation',0): + if kw.get('group_by_mirror_node', 0): + group_by_expression_list.append('%s.mirror_node_uid' % table) + if kw.get('group_by_section', 0): + group_by_expression_list.append('%s.section_uid' % table) + if kw.get('group_by_mirror_section', 0): + group_by_expression_list.append('%s.mirror_section_uid' % table) + if kw.get('group_by_payment', 0): + group_by_expression_list.append('%s.payment_uid' % table) + if kw.get('group_by_sub_variation', 0): group_by_expression_list.append('%s.sub_variation_text' % table) - if kw.get('group_by_variation',0): + if kw.get('group_by_variation', 0): group_by_expression_list.append('%s.variation_text' % table) - if kw.get('group_by_mirror_node',0): - group_by_expression_list.append('%s.mirror_node_uid' % table) - if len(group_by_expression_list): - # Always group by resource - group_by_expression_list.append('%s.resource_uid' % table) + if group_by_expression_list: + # by default, we group by resource + if kw.get('group_by_resource', 1): + group_by_expression_list.append('%s.resource_uid' % table) 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/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml index 74c69e6f23b64fe5a69f8f7322c0f2f699e6577d..0d957f193908466648b1fcaa45489f285ca7d9d6 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml @@ -243,6 +243,9 @@ SELECT\n stock.uid AS stock_uid,\n stock.date as date,\n stock.simulation_state as simulation_state,\n + stock.mirror_section_uid as mirror_section_uid,\n + stock.payment_uid as payment_uid,\n + stock.mirror_node_uid as mirror_node_uid,\n catalog.path as path\n \n FROM\n @@ -381,6 +384,9 @@ SELECT\n stock.uid AS stock_uid,\n stock.date as date,\n stock.simulation_state as simulation_state,\n + stock.mirror_section_uid as mirror_section_uid,\n + stock.payment_uid as payment_uid,\n + stock.mirror_node_uid as mirror_node_uid,\n catalog.path as path\n \n FROM\n diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision index b6e27607fb529c10ffeb626c858f55206242edb7..104fcf5b4e28106211b72ca265f2915043f68e39 100644 --- a/product/ERP5/bootstrap/erp5_core/bt/revision +++ b/product/ERP5/bootstrap/erp5_core/bt/revision @@ -1 +1 @@ -242 \ No newline at end of file +243 \ No newline at end of file diff --git a/product/ERP5/tests/testInventoryAPI.py b/product/ERP5/tests/testInventoryAPI.py index c52cf101031cfab18655af91630fac8fdea3eaf8..7f1e8418c86b9d3045cecce27d1220a0abc49cba 100644 --- a/product/ERP5/tests/testInventoryAPI.py +++ b/product/ERP5/tests/testInventoryAPI.py @@ -27,6 +27,9 @@ ############################################################################## """Unit Tests for Inventory API. + +TODO: test variation + """ import sys @@ -86,6 +89,9 @@ class InventoryAPITestCase(ERP5TypeTestCase): self.resource = self.getCurrencyModule().newContent( title='Resource', portal_type='Currency') + self.other_resource = self.getCurrencyModule().newContent( + title='Other Resource', + portal_type='Currency') # create a dummy Rule, to be able to create simulation movements rule_tool = self.portal.portal_rules if not hasattr(rule_tool, 'default_order_rule'): @@ -524,8 +530,69 @@ class TestInventoryList(InventoryAPITestCase): 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 ? + def test_GroupByMirrorNode(self): + getInventoryList = self.getSimulationTool().getInventoryList + self._makeMovement(quantity=100) + self._makeMovement(source_value=self.other_node, quantity=100) + self._makeMovement(source_value=None, quantity=100) + inventory_list = getInventoryList(section_uid=self.section.getUid(), + group_by_mirror_node=1) + self.assertEquals(3, len(inventory_list)) + self.assertEquals([r for r in inventory_list if r.mirror_node_uid == + self.mirror_node.getUid()][0].inventory, 100) + self.assertEquals([r for r in inventory_list if r.mirror_node_uid == + self.other_node.getUid()][0].inventory, 100) + self.assertEquals([r for r in inventory_list + if r.mirror_node_uid is None][0].inventory, 100) + + def test_GroupBySection(self): + getInventoryList = self.getSimulationTool().getInventoryList + self._makeMovement(quantity=100) + self._makeMovement(destination_section_value=self.other_node, quantity=100) + self._makeMovement(destination_section_value=None, quantity=100) + inventory_list = getInventoryList(node_uid=self.node.getUid(), + group_by_section=1) + self.assertEquals(3, len(inventory_list)) + self.assertEquals([r for r in inventory_list if r.section_relative_url == + self.section.getRelativeUrl()][0].inventory, 100) + self.assertEquals([r for r in inventory_list if r.section_relative_url == + self.other_node.getRelativeUrl()][0].inventory, 100) + self.assertEquals([r for r in inventory_list if r.section_relative_url is + None][0].inventory, 100) + + def test_GroupByResource(self): + getInventoryList = self.getSimulationTool().getInventoryList + self._makeMovement(quantity=100) + self._makeMovement(resource_value=self.other_resource, quantity=100) + # group_by_resource is implicit ... + inventory_list = getInventoryList(node_uid=self.node.getUid(), + group_by_node=1) + self.assertEquals(2, len(inventory_list)) + self.assertEquals([r for r in inventory_list if r.resource_relative_url == + self.resource.getRelativeUrl()][0].inventory, 100) + self.assertEquals([r for r in inventory_list if r.resource_relative_url == + self.other_resource.getRelativeUrl()][0].inventory, 100) + # ... but can be disabled + inventory_list = getInventoryList(node_uid=self.node.getUid(), + group_by_node=1, + group_by_resource=0) + self.assertEquals(1, len(inventory_list)) + self.assertEquals(inventory_list[0].inventory, 200) + + def test_GroupByPayment(self): + getInventoryList = self.getSimulationTool().getInventoryList + self._makeMovement(quantity=100) + self._makeMovement(destination_payment_value=self.payment_node, + quantity=200) + inventory_list = getInventoryList(node_uid=self.node.getUid(), + group_by_node=1, group_by_payment=1) + self.assertEquals(2, len(inventory_list)) + self.assertEquals([r for r in inventory_list if r.payment_uid is + None][0].inventory, 100) + self.assertEquals([r for r in inventory_list if r.payment_uid == + self.payment_node.getUid()][0].inventory, 200) + + class TestMovementHistoryList(InventoryAPITestCase): """Tests Movement history list methods. @@ -1030,11 +1097,13 @@ class TestMovementHistoryList(InventoryAPITestCase): self.assertEquals(11, len(mvt_history_list)) self.assertEquals(0, mvt_history_list[-1].running_total_quantity) self.assertEquals(0, mvt_history_list[-1].running_total_price) - + + class TestInventoryStat(InventoryAPITestCase): """Tests Inventory Stat methods. """ + if __name__ == '__main__': framework() else: