From ed6b2a5d1d4f0abc5b764e89f78b6b0e75d12f14 Mon Sep 17 00:00:00 2001 From: Gabriel Monnerat <gabriel@tiolive.com> Date: Mon, 9 Sep 2013 14:30:30 +0000 Subject: [PATCH] Refactor code to not search for Moviments, all projects validated are enough --- ...tingTransactionLine_getProjectItemList.xml | 28 ++++++------------- bt5/erp5_accounting/bt/change_log | 2 +- bt5/erp5_accounting/bt/revision | 2 +- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionLine_getProjectItemList.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionLine_getProjectItemList.xml index d7cfaa657f..e0650fc411 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionLine_getProjectItemList.xml +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionLine_getProjectItemList.xml @@ -50,34 +50,24 @@ </item> <item> <key> <string>_body</string> </key> - <value> <string>"""Returns the item list of possible projects to use on accounting lines.\n + <value> <string>"""Returns all validated projects.\n \n This script is indented to be used on custom listfields for accounting lines, and on reports.\n If this script returns an empty list, it means that reports by project are disabled.\n """\n from Products.ERP5Type.Message import translateString\n portal = context.getPortalObject()\n -request = portal.REQUEST\n \n -# case 1: script is used for reports, we display all project that have been used in accounting.\n +# case 1: script is used for reports, we display all validated projects.\n if context.getPortalType() == \'Accounting Transaction Module\':\n - getObject = portal.portal_catalog.getObject\n - search_kw=dict(portal_type=portal.getPortalAccountingMovementTypeList(),\n - group_by=(\'stock.project_uid\',))\n - section_category = request.get(\'your_section_category\',\n - portal.portal_preferences.getPreferredAccountingTransactionSectionCategory())\n - if section_category:\n - section_uid = portal.Base_getSectionUidListForSectionCategory(\n - section_category=section_category,\n - strict_membership=request.get(\'your_section_category_strict\', False))\n - search_kw[\'section_uid\'] = section_uid\n -\n project_list = []\n - for brain in portal.portal_simulation.getInventoryList(**search_kw):\n - if brain.project_uid:\n - project = getObject(brain.project_uid)\n - project_list.append((project.getTitle(), project.getRelativeUrl(),))\n - project_list.sort(key=lambda x:x[0])\n + for project in portal.project_module.searchFolder(\n + portal_type=\'Project\',\n + select_list=[\'relative_url\', \'title\'],\n + validation_state=(\'validated\',),\n + sort_on=((\'title\', \'ASC\'),)):\n + project_list.append((project.title, project.relative_url,))\n +\n if not project_list:\n return [] # returning an empty list, not to add project column on reports\n return [(\'\', \'\'), (translateString(\'No Project\'), \'None\')] + project_list\n diff --git a/bt5/erp5_accounting/bt/change_log b/bt5/erp5_accounting/bt/change_log index da66402e0c..8ddb28a0aa 100644 --- a/bt5/erp5_accounting/bt/change_log +++ b/bt5/erp5_accounting/bt/change_log @@ -1,5 +1,5 @@ 2013-09-09 Gabriel Monnerat -* Refactor ERP5Site_getAccountItemList to search only for validated accounts. +* Refactor ERP5Site_getAccountItemList and AccountingTransactionLine_getProjectItemList to not search for Movements becauses it generate slow queries 2013-04-17 arnaud.fontaine * erp5_simulation should not be required as some system do not use simulation. diff --git a/bt5/erp5_accounting/bt/revision b/bt5/erp5_accounting/bt/revision index 51c3d6754f..19c3151938 100644 --- a/bt5/erp5_accounting/bt/revision +++ b/bt5/erp5_accounting/bt/revision @@ -1 +1 @@ -1542 \ No newline at end of file +1543 \ No newline at end of file -- 2.30.9