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

added support for group_by_payment and group_by_mirror_section in getInventoryList



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12212 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d01b5311
......@@ -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
......
......@@ -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
......
242
\ No newline at end of file
243
\ No newline at end of file
......@@ -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:
......
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