Commit 4723100a authored by Jérome Perrin's avatar Jérome Perrin

trade: extend "Lines Report" to allow filtering by use

Nowadays instead of creating many portal types, we use `use` category to
separate different types of movements, so it makes sense to filter by use,
the same way that we already were able to filter by portal type.
parent d8343f59
...@@ -305,6 +305,7 @@ ...@@ -305,6 +305,7 @@
<string>my_report_mode_node_category</string> <string>my_report_mode_node_category</string>
<string>my_view_mode_ledger</string> <string>my_view_mode_ledger</string>
<string>my_report_mode_currency</string> <string>my_report_mode_currency</string>
<string>my_dialog_mode_use_list</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>items</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_dialog_mode_use_list</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_multi_list_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Use</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: getattr(here.portal_categories.use, preferences.getPreference(\'preferred_category_child_item_list_method_id\', \'getCategoryChildCompactLogicalPathItemList\'))(local_sort_id=(\'int_index\', \'translated_title\'), checked_permission=\'View\', base=True)</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -15,10 +15,16 @@ def getAccountTitle(relative_url): ...@@ -15,10 +15,16 @@ def getAccountTitle(relative_url):
account_title_cache[relative_url] = title account_title_cache[relative_url] = title
return title return title
isDisplayed = lambda movement: True
if use_list:
def isDisplayed(movement): # pylint:disable=function-redefined
return any(movement.isMemberOf(use) for use in use_list)
for delivery in portal.portal_catalog(uid=uid_list or -1): for delivery in portal.portal_catalog(uid=uid_list or -1):
delivery = delivery.getObject() delivery = delivery.getObject()
for movement in delivery.getMovementList(portal_type=portal_type): for movement in delivery.getMovementList(portal_type=portal_type):
if not isDisplayed(movement):
continue
line_list.append(Object( line_list.append(Object(
int_index=movement.getIntIndex(), int_index=movement.getIntIndex(),
title=movement.getTitle(), title=movement.getTitle(),
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>uid_list, portal_type, **kw</string> </value> <value> <string>uid_list, portal_type, use_list, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -27,6 +27,7 @@ try: ...@@ -27,6 +27,7 @@ try:
ReportSection(form_id='DeliveryModule_viewDeliveryLineList', ReportSection(form_id='DeliveryModule_viewDeliveryLineList',
path=context.getPhysicalPath(), path=context.getPhysicalPath(),
selection_params=dict(portal_type=request['portal_type'], selection_params=dict(portal_type=request['portal_type'],
use_list=request['use'],
uid_list=uid_list, uid_list=uid_list,
module_selection_name=module_selection_name))) module_selection_name=module_selection_name)))
return report_section_list return report_section_list
......
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
<value> <value>
<list> <list>
<string>your_portal_type</string> <string>your_portal_type</string>
<string>your_use</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_use</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_dialog_mode_use_list</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewTradeFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Movement Use</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -102,6 +102,16 @@ class TestTradeReports(ERP5ReportTestCase): ...@@ -102,6 +102,16 @@ class TestTradeReports(ERP5ReportTestCase):
title=group_id, title=group_id,
reference=group_id, reference=group_id,
id=group_id) id=group_id)
# create use categories
for use_id in ('u1', 'u2'):
if not self.portal_categories['use'].has_key(use_id):
self.portal_categories.use.newContent(
portal_type='Category',
title=use_id,
reference=use_id,
id=use_id)
# currencies # currencies
if not self.portal.currency_module.has_key('EUR'): if not self.portal.currency_module.has_key('EUR'):
self.portal.currency_module.newContent( self.portal.currency_module.newContent(
...@@ -1979,6 +1989,7 @@ class TestTradeReports(ERP5ReportTestCase): ...@@ -1979,6 +1989,7 @@ class TestTradeReports(ERP5ReportTestCase):
self.assertFalse('Site Error' in view) self.assertFalse('Site Error' in view)
self.portal.REQUEST.form['portal_type'] = ['Sale Order Line'] self.portal.REQUEST.form['portal_type'] = ['Sale Order Line']
self.portal.REQUEST.form['use'] = []
report_section, = self.getReportSectionList( report_section, = self.getReportSectionList(
self.sale_order_module, self.sale_order_module,
'DeliveryModule_viewDeliveryLineReport') 'DeliveryModule_viewDeliveryLineReport')
...@@ -2000,6 +2011,42 @@ class TestTradeReports(ERP5ReportTestCase): ...@@ -2000,6 +2011,42 @@ class TestTradeReports(ERP5ReportTestCase):
price=3, price=3,
) )
def test_LinesReport_use(self):
sale_order = self.sale_order_module.newContent(portal_type="Sale Order")
sale_order.newContent(
portal_type="Sale Order Line",
resource_value=self.portal.product_module.product_A,
use_value=self.portal.portal_categories.use.u1,
quantity=2,
price=3,
)
sale_order.newContent(
portal_type="Sale Order Line",
resource_value=self.portal.product_module.product_A,
use_value=self.portal.portal_categories.use.u2,
quantity=3,
price=4,
)
self.tic()
# view the module first, it will set selection
view = self.portal.sale_order_module.view()
self.assertFalse('Site Error' in view)
self.portal.REQUEST.form['portal_type'] = ['Sale Order Line']
self.portal.REQUEST.form['use'] = ['use/u1']
report_section, = self.getReportSectionList(
self.sale_order_module,
'DeliveryModule_viewDeliveryLineReport')
line_list = [l for l in self.getListBoxLineList(report_section) if l.isDataLine()]
self.assertEqual(len(line_list), 1)
self.checkLineProperties(
line_list[0],
quantity=2,
price=3,
)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
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