diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionLine_getGroupingExtraParameterList.py b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionLine_getGroupingExtraParameterList.py index a09a50c3658931f4135df7b79196528b0700a0a2..af72570aa06e849183fb535faa0470056ba148a5 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionLine_getGroupingExtraParameterList.py +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionLine_getGroupingExtraParameterList.py @@ -6,11 +6,14 @@ For instance, we can refuse to group together lines for different order by retur The returned value must be hashable. """ -# By default we take into account mirror section. -# The rationale is that when using internal accounting transaction between +# By default we take into account ledger and mirror accounting. + +# We consider ledger so that, by default we don't group lines from different ledger. +# This may be customized too, depending on how ledgers are used in customized implementations. + +# We consider mirror accounting because that when using internal accounting transaction between # two entities of the group, the grouping has to be valid for both sides # (source_section & destination_section). - # This behavior was introduced in nexedi/erp5@f3bebea3 for compatibility, # some old sites where accounting lines have been grouped together regardless of # the mirror node can decide to ignore the mirror account. @@ -19,5 +22,5 @@ The returned value must be hashable. # This can be achieved easily by customizing this script. if source: - return context.getSource(portal_type='Account') -return context.getDestination(portal_type='Account') + return context.getLedger(), context.getSource(portal_type='Account') +return context.getLedger(), context.getDestination(portal_type='Account') diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getLedgerItemList.py b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getLedgerItemList.py index 85fc4485e2e51feb476c485408b7e3201ed4b976..309f59a9ce05ca6b19bd45d61123de3f17c668c1 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getLedgerItemList.py +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getLedgerItemList.py @@ -3,18 +3,12 @@ portal = context.getPortalObject() portal_types = portal.portal_types -accounting_type_list = portal.getPortalAccountingTransactionTypeList() ledger_set = set() -for accounting_type in accounting_type_list: - try: - new_ledger_list = portal_types[accounting_type].getLedgerValueList([]) - ledger_set = ledger_set.union(set(new_ledger_list)) - except AttributeError: - # This portal type doesn't inherit from Delivery Type, thus we can pass - continue +ledger_item_list = context.Base_getPreferredCategoryChildItemList( + portal.portal_categories.ledger, base=True) -if len(ledger_set): - return [[ledger.getTranslatedTitle(), ledger.getRelativeUrl()] for ledger in list(ledger_set)] +for accounting_type in portal.getPortalAccountingTransactionTypeList(): + ledger_set.update(portal_types[accounting_type].getLedgerList(base=True)) -return () +return [item for item in ledger_item_list if item[1] in ledger_set] diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getLedgerItemList.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getLedgerItemList.xml index 8edee4b94da862ad19e7bd3c2d83b364c2e3a9a0..17232b6c06b147a8b89316bd47d7091da0eecb25 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getLedgerItemList.xml +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getLedgerItemList.xml @@ -50,7 +50,7 @@ </item> <item> <key> <string>_params</string> </key> - <value> <string>source=True</string> </value> + <value> <string></string> </value> </item> <item> <key> <string>id</string> </key> diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getTransactionLineListForGroupingReference.py b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getTransactionLineListForGroupingReference.py index ab5a666f7a4bc4ee8637bedc3f0a77bcf6c82d96..e6752e6e54b717b3d755675c554d437775057c27 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getTransactionLineListForGroupingReference.py +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getTransactionLineListForGroupingReference.py @@ -44,6 +44,10 @@ mirror_section = mirror_section or request.get('mirror_section') if mirror_section: search_kw['mirror_section_uid'] = portal.restrictedTraverse( mirror_section).getUid() +ledger = ledger or request.get('ledger') +if ledger: + search_kw['ledger_uid'] = [ + portal.portal_categories.restrictedTraverse(x).getUid() for x in ledger] if grouping == 'grouping': search_kw['grouping_reference'] = None diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getTransactionLineListForGroupingReference.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getTransactionLineListForGroupingReference.xml index 6412a5069cdf159cb31d0244b51ae3c4e0be1702..5fc1f96c92a3b9dc0f9021ae3b370d4f7a709c02 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getTransactionLineListForGroupingReference.xml +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_getTransactionLineListForGroupingReference.xml @@ -50,7 +50,7 @@ </item> <item> <key> <string>_params</string> </key> - <value> <string>selection=None, grouping=\'grouping\', node=\'\', mirror_section=\'\', title=None, delivery_reference=None, debit_price=None, credit_price=None, date=None, **kw</string> </value> + <value> <string>selection=None, grouping=\'grouping\', node=\'\', mirror_section=\'\', ledger=\'\', title=None, delivery_reference=None, debit_price=None, credit_price=None, date=None, **kw</string> </value> </item> <item> <key> <string>id</string> </key> diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_viewGroupingFastInputDialog.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_viewGroupingFastInputDialog.xml index 1e69559db4c1947870ad4b4bef735c36468cd99e..3e9bd2b50a70939542064ef4633295151e776efd 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_viewGroupingFastInputDialog.xml +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_viewGroupingFastInputDialog.xml @@ -75,6 +75,7 @@ <list> <string>your_node</string> <string>your_mirror_section</string> + <string>your_ledger</string> </list> </value> </item> diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_viewGroupingFastInputDialog/your_ledger.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_viewGroupingFastInputDialog/your_ledger.xml new file mode 100644 index 0000000000000000000000000000000000000000..798bcb9c77e878cfd57391e168f78ce17c632e1d --- /dev/null +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_viewGroupingFastInputDialog/your_ledger.xml @@ -0,0 +1,84 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ProxyField" module="Products.ERP5Form.ProxyField"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>id</string> </key> + <value> <string>your_ledger</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> + </dictionary> + </value> + </item> + <item> + <key> <string>values</string> </key> + <value> + <dictionary> + <item> + <key> <string>field_id</string> </key> + <value> <string>your_ledger</string> </value> + </item> + <item> + <key> <string>form_id</string> </key> + <value> <string>AccountModule_viewDialogFieldLibrary</string> </value> + </item> + <item> + <key> <string>target</string> </key> + <value> <string>Click to edit the target</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_viewFieldLibrary/my_ledger.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_viewFieldLibrary/my_ledger.xml index 70cfa515dba1fbcdd2838de836308779ea025115..eadba4fbddbdf0a7e459506b07e12dc1a672057a 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_viewFieldLibrary/my_ledger.xml +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_viewFieldLibrary/my_ledger.xml @@ -142,7 +142,7 @@ <dictionary> <item> <key> <string>_text</string> </key> - <value> <string>python: [(\'\',\'\')] + [(ledger.getTranslatedTitle(), ledger.getCategoryRelativeUrl(base=0)) for ledger in here.portal_types[here.getPortalType()].getLedgerValueList()]</string> </value> + <value> <string>context/Delivery_getLedgerItemList</string> </value> </item> </dictionary> </pickle> diff --git a/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_categories/ledger/test_accounting.xml b/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_categories/ledger/test_accounting.xml new file mode 100644 index 0000000000000000000000000000000000000000..ea488a76359690b8ecc876c0ae939240c8c51b9f --- /dev/null +++ b/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_categories/ledger/test_accounting.xml @@ -0,0 +1,78 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="Category" module="erp5.portal_type"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>_count</string> </key> + <value> + <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> + </value> + </item> + <item> + <key> <string>_mt_index</string> </key> + <value> + <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> + </value> + </item> + <item> + <key> <string>_tree</string> </key> + <value> + <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> + </value> + </item> + <item> + <key> <string>categories</string> </key> + <value> + <tuple> + <string>ledger/test_accounting</string> + </tuple> + </value> + </item> + <item> + <key> <string>description</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>test_accounting</string> </value> + </item> + <item> + <key> <string>portal_type</string> </key> + <value> <string>Category</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string>Test Accounting</string> </value> + </item> + </dictionary> + </pickle> + </record> + <record id="2" aka="AAAAAAAAAAI="> + <pickle> + <global name="Length" module="BTrees.Length"/> + </pickle> + <pickle> <int>0</int> </pickle> + </record> + <record id="3" aka="AAAAAAAAAAM="> + <pickle> + <global name="OOBTree" module="BTrees.OOBTree"/> + </pickle> + <pickle> + <none/> + </pickle> + </record> + <record id="4" aka="AAAAAAAAAAQ="> + <pickle> + <global name="OOBTree" module="BTrees.OOBTree"/> + </pickle> + <pickle> + <none/> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_categories/ledger/test_accounting/test_ledger_1.xml b/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_categories/ledger/test_accounting/test_ledger_1.xml new file mode 100644 index 0000000000000000000000000000000000000000..77bbf52690f1226dfe524519ecc9cd4e6b5dd517 --- /dev/null +++ b/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_categories/ledger/test_accounting/test_ledger_1.xml @@ -0,0 +1,44 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="Category" module="erp5.portal_type"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>categories</string> </key> + <value> + <tuple> + <string>ledger/test_accounting/test_ledger_1</string> + </tuple> + </value> + </item> + <item> + <key> <string>description</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>test_ledger_1</string> </value> + </item> + <item> + <key> <string>int_index</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>portal_type</string> </key> + <value> <string>Category</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string>Test Ledger 1</string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_categories/ledger/test_accounting/test_ledger_2.xml b/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_categories/ledger/test_accounting/test_ledger_2.xml new file mode 100644 index 0000000000000000000000000000000000000000..d66093f0376f375bf6f73336061a38d999da1b55 --- /dev/null +++ b/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_categories/ledger/test_accounting/test_ledger_2.xml @@ -0,0 +1,44 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="Category" module="erp5.portal_type"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>categories</string> </key> + <value> + <tuple> + <string>ledger/test_accounting/test_ledger_2</string> + </tuple> + </value> + </item> + <item> + <key> <string>description</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>test_ledger_2</string> </value> + </item> + <item> + <key> <string>int_index</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>portal_type</string> </key> + <value> <string>Category</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string>Test Ledger 2</string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_tests/accounting_zuite/test_grouping_reference/test_group_dialog_ledger.html.xml b/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_tests/accounting_zuite/test_grouping_reference/test_group_dialog_ledger.html.xml new file mode 100644 index 0000000000000000000000000000000000000000..f49a34ad513f8caf433f8acca807d590a37ddbf5 --- /dev/null +++ b/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_tests/accounting_zuite/test_grouping_reference/test_group_dialog_ledger.html.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>_bind_names</string> </key> + <value> + <object> + <klass> + <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_asgns</string> </key> + <value> + <dictionary> + <item> + <key> <string>name_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>content_type</string> </key> + <value> <string>text/html</string> </value> + </item> + <item> + <key> <string>expand</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>test_group_dialog_ledger.html</string> </value> + </item> + <item> + <key> <string>output_encoding</string> </key> + <value> <string>utf-8</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <unicode></unicode> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_tests/accounting_zuite/test_grouping_reference/test_group_dialog_ledger.html.zpt b/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_tests/accounting_zuite/test_grouping_reference/test_group_dialog_ledger.html.zpt new file mode 100644 index 0000000000000000000000000000000000000000..25c5ecc1944719818a29968494bb512bc36dc72c --- /dev/null +++ b/bt5/erp5_accounting_ui_test/PathTemplateItem/portal_tests/accounting_zuite/test_grouping_reference/test_group_dialog_ledger.html.zpt @@ -0,0 +1,156 @@ +<html> +<head><title>Using Ledger in Grouping Dialog</title></head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="4"> +Using Ledger in Grouping Dialog +</td></tr> +</thead><tbody tal:define="init_method string:AccountingZuite_createAccountingTransactionList?add_draft_transactions:int=0&add_related_payments:int=1&set_ledger:int=1"> + +<!-- Setup {{{ --> +<tal:block metal:use-macro="here/AccountingZuite_CommonTemplate/macros/init"/> +<tr> + <td>selectAndWait</td> + <td>select_module</td> + <td>Organisations</td> +</tr> +<tr> + <td>clickAndWait</td> + <td>Folder_show:method</td> + <td></td> +</tr> +<tr> + <td>type</td> + <!-- title --> + <td>//tr[@class='listbox-search-line']/th[2]/input</td> + <td>Client 1</td> +</tr> +<tr> + <td>clickAndWait</td> + <td>//input[@class="listbox-select-action"]</td> + <td></td> +</tr> +<!-- }}} --> + +<!-- {{{ Select Client 1 Organisation and use grouping fast input --> +<tr> + <td>clickAndWait</td> + <td>link=Client 1</td> + <td></td> +</tr> +<tr> + <td>clickAndWait</td> + <td>//img[@alt='Grouping Reference Fast Input']</td> + <td></td> +</tr> + +<!-- The mode should be 'grouping' by default --> +<tr> + <td>verifyValue</td> + <td>//input[@name='field_your_grouping' and @value='grouping']</td> + <td>on</td> +</tr> +<tr> + <td>verifyText</td> + <td>//label[contains(text(),"Total Selected Amount")]/../div[1]/</td> + <td>0.00</td> +</tr> +<tr> + <td>select</td> + <td>field_your_node</td> + <td>label=41 - Receivable</td> +</tr> +<tr> + <td>clickAndWait</td> + <td>//button[@id="dialog_update_button"]</td> + <td></td> +</tr> +<tr> + <td>assertPortalStatusMessage</td> + <td>Updated</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>//span[@class="listbox-current-page-total-number"]</td> + <td>2 records</td> +</tr> + +<!-- in test ledger 2, we have no transactions. --> +<tr> + <td>select</td> + <td>field_your_ledger</td> + <td>label=Test Accounting/Test Ledger 2</td> +</tr> +<tr> + <td>clickAndWait</td> + <td>//button[@id="dialog_update_button"]</td> + <td></td> +</tr> +<tr> + <td>assertPortalStatusMessage</td> + <td>Updated</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>//span[@class="listbox-current-page-total-number"]</td> + <td>0 records</td> +</tr> + +<!-- in test ledger 1, we have 2 transactions. --> +<tr> + <td>select</td> + <td>field_your_ledger</td> + <td>label=Test Accounting/Test Ledger 1</td> +</tr> +<tr> + <td>clickAndWait</td> + <td>//button[@id="dialog_update_button"]</td> + <td></td> +</tr> +<tr> + <td>assertPortalStatusMessage</td> + <td>Updated</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>//span[@class="listbox-current-page-total-number"]</td> + <td>2 records</td> +</tr> + +<!-- in test ledger 1 and 2, we have 2 transactions. --> +<tr> + <td>addSelection</td> + <td>field_your_ledger</td> + <td>label=Test Accounting/Test Ledger 1</td> +</tr> +<tr> + <td>addSelection</td> + <td>field_your_ledger</td> + <td>label=Test Accounting/Test Ledger 2</td> +</tr> +<tr> + <td>clickAndWait</td> + <td>//button[@id="dialog_update_button"]</td> + <td></td> +</tr> +<tr> + <td>assertPortalStatusMessage</td> + <td>Updated</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>//span[@class="listbox-current-page-total-number"]</td> + <td>2 records</td> +</tr> + +<!-- }}} --> + +</tbody></table> +</body> +</html> <!-- vim: syntax=html foldmethod=marker +--> \ No newline at end of file diff --git a/bt5/erp5_accounting_ui_test/SkinTemplateItem/portal_skins/erp5_accounting_ui_test/AccountingZuite_createAccountingTransactionList.py b/bt5/erp5_accounting_ui_test/SkinTemplateItem/portal_skins/erp5_accounting_ui_test/AccountingZuite_createAccountingTransactionList.py index f950a2df4c4e487fab7648c88f0291af8defca4c..e50e718c67bb96bb7b5c65b0e6527c5be43b2d65 100644 --- a/bt5/erp5_accounting_ui_test/SkinTemplateItem/portal_skins/erp5_accounting_ui_test/AccountingZuite_createAccountingTransactionList.py +++ b/bt5/erp5_accounting_ui_test/SkinTemplateItem/portal_skins/erp5_accounting_ui_test/AccountingZuite_createAccountingTransactionList.py @@ -14,9 +14,9 @@ business_process = portal.portal_catalog.getResultValue( portal_type='Business Process').getRelativeUrl() # if the previous test didn't change input data, no need to recreate content -current_script_data_id = '%s_month_count_%s_draft_%s_state_%s_payment_%s' % ( +current_script_data_id = '%s_month_count_%s_draft_%s_state_%s_payment_%s_leger_%s' % ( month_count, add_draft_transactions, transaction_state, - add_related_payments, script.getId()) + add_related_payments, set_ledger, script.getId()) if accounting_module.getProperty('current_content_script', '') == current_script_data_id: @@ -34,6 +34,18 @@ if 1: raise ValueError("Do not run this on production !!!") module.manage_delObjects(list(module.objectIds())) +# if `set_ledger`is true, allow all test ledgers in accounting types. +for accounting_type_id in portal.getPortalAccountingTransactionTypeList(): + accounting_type = portal.portal_types[accounting_type_id] + accounting_type.edit( + ledger_value_list=list(portal.portal_categories.ledger.test_accounting.contentValues()) + if set_ledger else ()) + +test_ledger_1 = test_ledger_2 = None +if set_ledger: + test_ledger_1 = portal.portal_categories.ledger.test_accounting.test_ledger_1 + test_ledger_2 = portal.portal_categories.ledger.test_accounting.test_ledger_2 + def getAccountByTitle(title): account_list = [x.getObject().getRelativeUrl() for x in portal.portal_catalog(portal_type='Account', @@ -97,6 +109,7 @@ for month in range(1, month_count + 1): portal_type='Accounting Transaction', source_section=section, created_by_builder=1, + ledger_value=test_ledger_1, start_date=default_date, stop_date=default_date, resource=euro_resource, @@ -122,7 +135,7 @@ for month in range(1, month_count + 1): else: # other cases not supported for now assert transaction_state == 'draft' - + vat_rate = .1 for client_title, amount in (('Client 1', 2000), ('Client 2', 3000)): @@ -135,6 +148,7 @@ for month in range(1, month_count + 1): source=section, destination=getOrganisationByTitle(client_title), created_by_builder=1, + ledger_value=test_ledger_1, start_date=default_date, stop_date=default_date, specialise=business_process, @@ -174,6 +188,7 @@ for month in range(1, month_count + 1): source_section=section, destination_section=getOrganisationByTitle(client_title), created_by_builder=1, + ledger_value=test_ledger_1, start_date=default_date + .1, # make sure this will be after the invoice stop_date=default_date + .1, resource=euro_resource, @@ -213,6 +228,7 @@ for month in range(1, month_count + 1): destination_section=section, source_section=getOrganisationByTitle('Supplier'), created_by_builder=1, + ledger_value=test_ledger_1, start_date=default_date-5, # In purchase invoice transaction, stop_date is accounting operation date. stop_date=default_date, specialise=business_process, @@ -248,6 +264,7 @@ if add_draft_transactions: source_section=section, destination_section=getOrganisationByTitle(client_title), created_by_builder=1, + ledger_value=test_ledger_1, start_date=default_date, stop_date=default_date, resource=euro_resource, diff --git a/bt5/erp5_accounting_ui_test/SkinTemplateItem/portal_skins/erp5_accounting_ui_test/AccountingZuite_createAccountingTransactionList.xml b/bt5/erp5_accounting_ui_test/SkinTemplateItem/portal_skins/erp5_accounting_ui_test/AccountingZuite_createAccountingTransactionList.xml index f7ffd40b53a36fe9cb941894387010faea24013d..d801dedd79b3855f7c3d482841d56e31a86988fe 100644 --- a/bt5/erp5_accounting_ui_test/SkinTemplateItem/portal_skins/erp5_accounting_ui_test/AccountingZuite_createAccountingTransactionList.xml +++ b/bt5/erp5_accounting_ui_test/SkinTemplateItem/portal_skins/erp5_accounting_ui_test/AccountingZuite_createAccountingTransactionList.xml @@ -50,7 +50,7 @@ </item> <item> <key> <string>_params</string> </key> - <value> <string>month_count=1, add_draft_transactions=1, transaction_state=\'validated\', add_related_payments=0, keep_grouping_reference=0</string> </value> + <value> <string>month_count=1, add_draft_transactions=1, transaction_state=\'validated\', add_related_payments=0, keep_grouping_reference=0, set_ledger=0</string> </value> </item> <item> <key> <string>id</string> </key> diff --git a/bt5/erp5_accounting_ui_test/bt/template_path_list b/bt5/erp5_accounting_ui_test/bt/template_path_list index 3bc60b6295dc49b79882f9136d245b4c81c20a50..e22449a732411899913be9d5a6867f9063e0a9a6 100644 --- a/bt5/erp5_accounting_ui_test/bt/template_path_list +++ b/bt5/erp5_accounting_ui_test/bt/template_path_list @@ -33,6 +33,8 @@ portal_categories/group/demo_group portal_categories/group/demo_group/** portal_categories/group/vendor portal_categories/group/vendor/** +portal_categories/ledger/test_accounting +portal_categories/ledger/test_accounting/** portal_categories/payment_mode/cash portal_categories/payment_mode/check portal_categories/role/client diff --git a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Delivery_getLedgerItemList.py b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Delivery_getLedgerItemList.py new file mode 100644 index 0000000000000000000000000000000000000000..1c8608885d8155477870eeee87f0f83da7605265 --- /dev/null +++ b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Delivery_getLedgerItemList.py @@ -0,0 +1,11 @@ +"""Returns the possible ledger for this delivery. + +This will return only ledgers allowed in the delivery type definition. +""" + +portal = context.getPortalObject() + +ledger_item_list = context.Base_getPreferredCategoryChildItemList(portal.portal_categories.ledger) +allowed_ledger_list = portal.portal_types[context.getPortalType()].getLedgerList() + +return [('', '')] + [item for item in ledger_item_list if item[1] in allowed_ledger_list] diff --git a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Delivery_getLedgerItemList.xml b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Delivery_getLedgerItemList.xml new file mode 100644 index 0000000000000000000000000000000000000000..b4056e6f087c593b29af012f97eb65ebdf4fa367 --- /dev/null +++ b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Delivery_getLedgerItemList.xml @@ -0,0 +1,62 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="PythonScript" module="Products.PythonScripts.PythonScript"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>Script_magic</string> </key> + <value> <int>3</int> </value> + </item> + <item> + <key> <string>_bind_names</string> </key> + <value> + <object> + <klass> + <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_asgns</string> </key> + <value> + <dictionary> + <item> + <key> <string>name_container</string> </key> + <value> <string>container</string> </value> + </item> + <item> + <key> <string>name_context</string> </key> + <value> <string>context</string> </value> + </item> + <item> + <key> <string>name_m_self</string> </key> + <value> <string>script</string> </value> + </item> + <item> + <key> <string>name_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>_params</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>Delivery_getLedgerItemList</string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_base/bt/template_action_path_list b/bt5/erp5_base/bt/template_action_path_list index 59dcfeea6ae69a3823e1da1221a2c3ce9305fa0b..86f32110dbee56dd19487935eabebcd14224ef55 100644 --- a/bt5/erp5_base/bt/template_action_path_list +++ b/bt5/erp5_base/bt/template_action_path_list @@ -26,6 +26,7 @@ Delivery Causality Assignment Movement Group | view Delivery Tool | view Delivery Type | action_view Delivery Type | copy_roles +Delivery Type | delivery_view Delivery Type | jump_property_sheets Delivery Type | role_view Delivery Type | translation_view diff --git a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/Base_viewPayrollFieldLibrary/my_ledger.xml b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/Base_viewPayrollFieldLibrary/my_ledger.xml index 2a3ebcf2ec0986458519ea578c8cc0f2e58fad37..8cd2a75ed3e07098271a9fb978d8ccc65b34c083 100644 --- a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/Base_viewPayrollFieldLibrary/my_ledger.xml +++ b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/Base_viewPayrollFieldLibrary/my_ledger.xml @@ -118,7 +118,7 @@ <dictionary> <item> <key> <string>_text</string> </key> - <value> <string>python: [(\'\',\'\')] + [(ledger.getTranslatedTitle(), ledger.getCategoryRelativeUrl(base=0)) for ledger in here.portal_types[here.getPortalType()].getLedgerValueList()]</string> </value> + <value> <string>context/Delivery_getLedgerItemList</string> </value> </item> </dictionary> </pickle> diff --git a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewFieldLibrary/my_ledger.xml b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewFieldLibrary/my_ledger.xml index 2a3ebcf2ec0986458519ea578c8cc0f2e58fad37..8cd2a75ed3e07098271a9fb978d8ccc65b34c083 100644 --- a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewFieldLibrary/my_ledger.xml +++ b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewFieldLibrary/my_ledger.xml @@ -118,7 +118,7 @@ <dictionary> <item> <key> <string>_text</string> </key> - <value> <string>python: [(\'\',\'\')] + [(ledger.getTranslatedTitle(), ledger.getCategoryRelativeUrl(base=0)) for ledger in here.portal_types[here.getPortalType()].getLedgerValueList()]</string> </value> + <value> <string>context/Delivery_getLedgerItemList</string> </value> </item> </dictionary> </pickle> diff --git a/product/ERP5/tests/testAccounting.py b/product/ERP5/tests/testAccounting.py index d005811f98fd57ed050270073e2709d5b560f6b3..cefed435b52f7681de22322329843900e6ff8a63 100644 --- a/product/ERP5/tests/testAccounting.py +++ b/product/ERP5/tests/testAccounting.py @@ -241,6 +241,25 @@ class AccountingTestCase(ERP5TypeTestCase): 'erp5_configurator_standard_invoicing_template', 'erp5_simulation_test') + @UnrestrictedMethod + def setUpLedger(self): + # Create Ledger Categories + ledger_category = self.portal.portal_categories.ledger + ledger_accounting_category = ledger_category.get('accounting', None) + if ledger_accounting_category is None: + ledger_accounting_category = ledger_category.newContent(portal_type='Category', id='accounting') + if ledger_accounting_category.get('general', None) is None: + ledger_accounting_category.newContent(portal_type='Category', id='general') + if ledger_accounting_category.get('detailed', None) is None: + ledger_accounting_category.newContent(portal_type='Category', id='detailed') + if ledger_accounting_category.get('other', None) is None: + ledger_accounting_category.newContent(portal_type='Category', id='other') + + # Allow some ledgers on the 'Sale Invoice Transaction' portal type + self.portal.portal_types['Sale Invoice Transaction'].edit( + ledger=['accounting/general', 'accounting/detailed']) + + class TestAccounts(AccountingTestCase): """Tests Accounts. @@ -1169,24 +1188,6 @@ class TestClosingPeriod(AccountingTestCase): self.assertEqual(None, pl_movement.getSourceTotalAssetPrice()) self.assertEqual(200., pl_movement.getDestinationCredit()) - @UnrestrictedMethod - def setUpLedger(self): - # Create Ledger Categories - ledger_category = self.portal.portal_categories.ledger - ledger_accounting_category = ledger_category.get('accounting', None) - if ledger_accounting_category is None: - ledger_accounting_category = ledger_category.newContent(portal_type='Category', id='accounting') - if ledger_accounting_category.get('general', None) is None: - ledger_accounting_category.newContent(portal_type='Category', id='general') - if ledger_accounting_category.get('detailed', None) is None: - ledger_accounting_category.newContent(portal_type='Category', id='detailed') - if ledger_accounting_category.get('other', None) is None: - ledger_accounting_category.newContent(portal_type='Category', id='other') - - # Allow some ledgers on the 'Sale Invoice Transaction' portal type - self.portal.portal_types['Sale Invoice Transaction'].edit( - ledger=['accounting/general', 'accounting/detailed']) - def test_createBalanceOnLedgerWithTransactionsWithNoLedger(self): self.setUpLedger() organisation_module = self.organisation_module @@ -3462,6 +3463,8 @@ class TestTransactions(AccountingTestCase): invoice.stop() self.assertTrue(invoice_line.getGroupingReference()) self.assertTrue(payment_line.getGroupingReference()) + self.assertEqual(invoice_line.getGroupingReference(), + payment_line.getGroupingReference()) # the grouping date is set to the latest date of all grouped lines self.assertEqual(DateTime(2012, 1, 3), invoice_line.getGroupingDate()) self.assertEqual(DateTime(2012, 1, 3), payment_line.getGroupingDate()) @@ -3478,6 +3481,8 @@ class TestTransactions(AccountingTestCase): invoice.stop() self.assertTrue(invoice_line.getGroupingReference()) self.assertTrue(payment_line.getGroupingReference()) + self.assertEqual(invoice_line.getGroupingReference(), + payment_line.getGroupingReference()) self.assertEqual(DateTime(2012, 1, 3), invoice_line.getGroupingDate()) self.assertEqual(DateTime(2012, 1, 3), payment_line.getGroupingDate()) @@ -3525,6 +3530,8 @@ class TestTransactions(AccountingTestCase): invoice.stop() self.assertTrue(invoice_line.getGroupingReference()) self.assertTrue(payment_line.getGroupingReference()) + self.assertEqual(invoice_line.getGroupingReference(), + payment_line.getGroupingReference()) # when restarting, grouping is removed invoice.restart() @@ -3534,6 +3541,8 @@ class TestTransactions(AccountingTestCase): invoice.stop() self.assertTrue(invoice_line.getGroupingReference()) self.assertTrue(payment_line.getGroupingReference()) + self.assertEqual(invoice_line.getGroupingReference(), + payment_line.getGroupingReference()) def test_automatically_setting_grouping_reference_only_related(self): invoice = self._makeOne( @@ -3662,6 +3671,74 @@ class TestTransactions(AccountingTestCase): for line in invoice.contentValues(): self.assertTrue(line.getGroupingReference()) + def test_automatically_setting_grouping_reference_when_same_ledger(self): + self.setUpLedger() + invoice = self._makeOne( + title='First Invoice', + ledger_value=self.portal.portal_categories.ledger.accounting.general, + destination_section_value=self.organisation_module.client_1, + lines=(dict(source_value=self.account_module.goods_purchase, + source_debit=100), + dict(source_value=self.account_module.receivable, + source_credit=100, + id='line_for_grouping_reference',))) + invoice_line = invoice.line_for_grouping_reference + + payment = self._makeOne( + title='First Invoice Payment', + portal_type='Payment Transaction', + simulation_state='delivered', + causality_value=invoice, + ledger_value=self.portal.portal_categories.ledger.accounting.general, + source_payment_value=self.section.newContent( + portal_type='Bank Account'), + destination_section_value=self.organisation_module.client_1, + lines=(dict(source_value=self.account_module.receivable, + id='line_for_grouping_reference', + source_debit=100), + dict(source_value=self.account_module.bank, + source_credit=100,))) + payment_line = payment.line_for_grouping_reference + + invoice.stop() + self.assertTrue(invoice_line.getGroupingReference()) + self.assertTrue(payment_line.getGroupingReference()) + self.assertEqual(invoice_line.getGroupingReference(), + payment_line.getGroupingReference()) + + def test_not_automatically_setting_grouping_reference_when_different_ledger(self): + self.setUpLedger() + invoice = self._makeOne( + title='First Invoice', + ledger_value=self.portal.portal_categories.ledger.accounting.general, + destination_section_value=self.organisation_module.client_1, + lines=(dict(source_value=self.account_module.goods_purchase, + source_debit=100), + dict(source_value=self.account_module.receivable, + source_credit=100, + id='line_for_grouping_reference',))) + invoice_line = invoice.line_for_grouping_reference + + payment = self._makeOne( + title='First Invoice Payment', + portal_type='Payment Transaction', + simulation_state='delivered', + causality_value=invoice, + ledger_value=self.portal.portal_categories.ledger.accounting.detailed, + source_payment_value=self.section.newContent( + portal_type='Bank Account'), + destination_section_value=self.organisation_module.client_1, + lines=(dict(source_value=self.account_module.receivable, + id='line_for_grouping_reference', + source_debit=100), + dict(source_value=self.account_module.bank, + source_credit=100,))) + payment_line = payment.line_for_grouping_reference + + invoice.stop() + self.assertFalse(invoice_line.getGroupingReference()) + self.assertFalse(payment_line.getGroupingReference()) + def test_roundDebitCredit_raises_if_big_difference(self): invoice = self._makeOne( portal_type='Sale Invoice Transaction',