Commit 25085d7b authored by Jérome Perrin's avatar Jérome Perrin

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

See merge request nexedi/erp5!1355
parents 5c3419ce 4723100a
......@@ -305,6 +305,7 @@
<string>my_report_mode_node_category</string>
<string>my_view_mode_ledger</string>
<string>my_report_mode_currency</string>
<string>my_dialog_mode_use_list</string>
</list>
</value>
</item>
......
......@@ -11,7 +11,6 @@
<value>
<list>
<string>items</string>
<string>size</string>
<string>title</string>
</list>
</value>
......@@ -72,6 +71,10 @@
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
......@@ -93,10 +96,6 @@
<list/>
</value>
</item>
<item>
<key> <string>size</string> </key>
<value> <int>5</int> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
......
<?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):
account_title_cache[relative_url] = 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):
delivery = delivery.getObject()
for movement in delivery.getMovementList(portal_type=portal_type):
if not isDisplayed(movement):
continue
line_list.append(Object(
int_index=movement.getIntIndex(),
title=movement.getTitle(),
......
......@@ -50,7 +50,7 @@
</item>
<item>
<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>
<key> <string>id</string> </key>
......
......@@ -27,6 +27,7 @@ try:
ReportSection(form_id='DeliveryModule_viewDeliveryLineList',
path=context.getPhysicalPath(),
selection_params=dict(portal_type=request['portal_type'],
use_list=request['use'],
uid_list=uid_list,
module_selection_name=module_selection_name)))
return report_section_list
......
......@@ -105,6 +105,7 @@
<value>
<list>
<string>your_portal_type</string>
<string>your_use</string>
</list>
</value>
</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):
title=group_id,
reference=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
if not self.portal.currency_module.has_key('EUR'):
self.portal.currency_module.newContent(
......@@ -1945,6 +1955,98 @@ class TestTradeReports(ERP5ReportTestCase):
# delivery_resource_text shows quantities and variations
delivery_resource_text="ref 1: 1.0\nref 3 colour1: 3.0\nref 3 colour2: 2.0")
def test_LinesReport(self):
# Create sales orders
self._makeOneSaleOrder(
title='SO 1',
destination_value=self.organisation_module.Organisation_1,
destination_section_value=self.organisation_module.Organisation_1,
destination_decision_value=self.organisation_module.Organisation_1,
source_value=self.organisation_module.Organisation_2,
source_section_value=self.organisation_module.Organisation_2,
source_decision_value=self.organisation_module.Organisation_2,
start_date=DateTime(2006, 2, 2),
resource_dict = {'product_module/product_A':{"quantity":11, "price":3},
'product_module/product_B':{"quantity":7, "price":6},},
)
self._makeOneSaleOrder(
title='SO 2 (cancelled)',
destination_value=self.organisation_module.Organisation_1,
destination_section_value=self.organisation_module.Organisation_1,
destination_decision_value=self.organisation_module.Organisation_1,
source_value=self.organisation_module.Organisation_2,
source_section_value=self.organisation_module.Organisation_2,
source_decision_value=self.organisation_module.Organisation_2,
start_date=DateTime(2006, 2, 2),
resource_dict = {'product_module/product_A':{"quantity":11, "price":3},
'product_module/product_B':{"quantity":7, "price":6},},
cancel=True,
)
# view the module first, it will set selection
self.portal.REQUEST.form['simulation_state'] = 'draft'
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'] = []
report_section, = self.getReportSectionList(
self.sale_order_module,
'DeliveryModule_viewDeliveryLineReport')
line_list = sorted(
(l for l in self.getListBoxLineList(report_section) if l.isDataLine()),
key=lambda x:x.getColumnProperty('quantity'))
self.assertEqual(len(line_list), 2)
self.checkLineProperties(
line_list[0],
start_date=DateTime(2006, 2, 2),
quantity=7,
price=6,
)
self.checkLineProperties(
line_list[1],
start_date=DateTime(2006, 2, 2),
quantity=11,
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():
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