From b353eaff116985b4dadeba100a3eb51c48713d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Wed, 1 Feb 2006 15:11:55 +0000 Subject: [PATCH] use activities to deliver transactions when closing accounting period git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5504 20353a03-c40f-0410-a6d1-a30d3c3de9de --- ...ingTransaction_closeByAccountingPeriod.xml | 166 ++++++++++++++++++ .../AccountingPeriod_DeliverTransactions.xml | 40 ++--- .../states/closing.xml | 51 ++++++ .../states/confirmed.xml | 4 +- .../transitions/close.xml | 70 ++++++++ .../{deliver_action.xml => close_action.xml} | 10 +- .../transitions/fail_closing.xml | 70 ++++++++ 7 files changed, 376 insertions(+), 35 deletions(-) create mode 100755 bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_closeByAccountingPeriod.xml create mode 100755 bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/states/closing.xml create mode 100755 bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/close.xml rename bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/{deliver_action.xml => close_action.xml} (85%) create mode 100755 bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/fail_closing.xml diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_closeByAccountingPeriod.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_closeByAccountingPeriod.xml new file mode 100755 index 0000000000..c37de967f5 --- /dev/null +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransaction_closeByAccountingPeriod.xml @@ -0,0 +1,166 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <tuple> + <tuple> + <string>Products.PythonScripts.PythonScript</string> + <string>PythonScript</string> + </tuple> + <none/> + </tuple> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>Python_magic</string> </key> + <value> <string encoding="base64">O/INCg==</string> </value> + </item> + <item> + <key> <string>Script_magic</string> </key> + <value> <int>3</int> </value> + </item> + <item> + <key> <string>__ac_local_roles__</string> </key> + <value> + <none/> + </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>_body</string> </key> + <value> <string>"""Deliver the transaction and \'notify\' the closing_period on failure."""\n +\n +from Products.DCWorkflow.DCWorkflow import ValidationFailed\n +N_ = context.Base_translateString\n +\n +try : \n + context.portal_workflow.doActionFor( context,\n + \'deliver_action\', \n + skip_period_validation = 1,\n + comment=comment )\n +except ValidationFailed, message :\n + closing_period = context.getPortalObject().restrictedTraverse(closing_period_path)\n + closing_period.failClosing()\n + closing_period.portal_workflow.doActionFor( closing_period,\n + \'edit_action\', \n + comment=N_(\'unable to deliver ${transaction_path} : ${error_message}\',\n + mapping={\'transaction_path\':context.getPath(),\n + \'error_message\': unicode(str(message), \'utf8\') } ))\n +</string> </value> + </item> + <item> + <key> <string>_code</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_filepath</string> </key> + <value> <string>Script (Python):/nexedi/erp5_accounting/AccountingTransaction_closeByAccountingPeriod</string> </value> + </item> + <item> + <key> <string>_params</string> </key> + <value> <string>comment, closing_period_path, **kw</string> </value> + </item> + <item> + <key> <string>errors</string> </key> + <value> + <tuple/> + </value> + </item> + <item> + <key> <string>func_code</string> </key> + <value> + <object> + <klass> + <global name="FuncCode" module="Shared.DC.Scripts.Signature"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>co_argcount</string> </key> + <value> <int>2</int> </value> + </item> + <item> + <key> <string>co_varnames</string> </key> + <value> + <tuple> + <string>comment</string> + <string>closing_period_path</string> + <string>kw</string> + <string>Products.DCWorkflow.DCWorkflow</string> + <string>ValidationFailed</string> + <string>_getattr_</string> + <string>context</string> + <string>N_</string> + <string>message</string> + <string>closing_period</string> + <string>unicode</string> + <string>str</string> + </tuple> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>func_defaults</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>AccountingTransaction_closeByAccountingPeriod</string> </value> + </item> + <item> + <key> <string>warnings</string> </key> + <value> + <tuple/> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/AccountingPeriod_DeliverTransactions.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/AccountingPeriod_DeliverTransactions.xml index a70426b5a9..5444a56de2 100755 --- a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/AccountingPeriod_DeliverTransactions.xml +++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/scripts/AccountingPeriod_DeliverTransactions.xml @@ -76,18 +76,16 @@ N_ = portal.Base_translateString\n accounting_module = portal.accounting_module\n valid_states = [\'cancelled\', \'stopped\', \'delivered\']\n \n -# validate all transactions states.\n -container.AccountingPeriod_CheckTransactionsState(state_change)\n -\n start_date = closing_period.getStartDate()\n stop_date = closing_period.getStopDate()\n \n search_params = { \'delivery.start_date\' : \'>= %s\' % start_date,\n - \'delivery.stop_date\' : \'<= %s\' % stop_date,\n - \'simulation_state\' : \'stopped\' }\n + \'delivery.stop_date\' : \'<= %s\' % stop_date,\n + \'simulation_state\' : \'stopped\' }\n transaction_list = accounting_module.searchFolder( **search_params )\n \n -#raise \'\\n\'.join([transaction.path for transaction in transaction_list])\n +comment=N_("Closing period ${period_title}",\n + mapping={\'period_title\': closing_period.getTitle()})\n \n section_uid = closing_period.getParentValue().getUid()\n for transaction in transaction_list :\n @@ -95,27 +93,13 @@ for transaction in transaction_list :\n # FIXME: this approach is not compatible with categories as sections.\n if transaction.getSourceSectionUid() == section_uid or \\\n transaction.getDestinationSectionUid() == section_uid :\n - if transaction.getSimulationState() == \'stopped\' :\n - # this action is made in the \'before_script\', even if this is \n - # related to the workflow logic, because we want the user to be\n - # notified of failures\n - \n - # FIXME: this way is not compatible with 100.000 transactions and should\n - # probably be activated.\n - portal.portal_workflow.doActionFor( transaction, \'deliver_action\',\n - wf_id="accounting_workflow",\n - comment=N_("Closing period ${period_title}",\n - mapping={\'period_title\': closing_period.getTitle()}),\n - skip_period_validation = 1 )\n - if transaction.getSimulationState() != \'delivered\' :\n - # FIXME: this is not transactional\n - raise ValidationFailed, N_(\n - "Unable to change state for ${transaction_path}, "+\n - "check this transaction history",\n - mapping = {\'transaction_path\' : transaction.getPath()})\n - else :\n - transaction.log(\'AccountingPeriod_DeliverTransaction\',\n - \'deliver %s\' % transaction.getPath())\n + transaction.activate().AccountingTransaction_closeByAccountingPeriod(\n + comment = comment, closing_period_path = closing_period.getPath() )\n +\n +# if a transaction validation fails, it puts the Closing Period object back to confirmed state\n +closing_period.activate( \n + after_method_id = [\'AccountingTransaction_closeByAccountingPeriod\']\n + ).deliver()\n ]]></string> </value> @@ -173,12 +157,12 @@ for transaction in transaction_list :\n <string>N_</string> <string>accounting_module</string> <string>valid_states</string> - <string>container</string> <string>start_date</string> <string>stop_date</string> <string>search_params</string> <string>_apply_</string> <string>transaction_list</string> + <string>comment</string> <string>section_uid</string> <string>_getiter_</string> <string>transaction</string> diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/states/closing.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/states/closing.xml new file mode 100755 index 0000000000..68f98f0307 --- /dev/null +++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/states/closing.xml @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <tuple> + <tuple> + <string>Products.DCWorkflow.States</string> + <string>StateDefinition</string> + </tuple> + <none/> + </tuple> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>__ac_local_roles__</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>description</string> </key> + <value> <string>Closing is the state used when the activity of delivering transaction happens.</string> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>closing</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>transitions</string> </key> + <value> + <tuple> + <string>deliver</string> + <string>fail_closing</string> + </tuple> + </value> + </item> + <item> + <key> <string>type_list</string> </key> + <value> + <tuple/> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/states/confirmed.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/states/confirmed.xml index a612c3b1c9..39d8f0b656 100755 --- a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/states/confirmed.xml +++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/states/confirmed.xml @@ -40,8 +40,8 @@ <key> <string>transitions</string> </key> <value> <tuple> - <string>deliver</string> - <string>deliver_action</string> + <string>close</string> + <string>close_action</string> <string>plan</string> <string>reopen_action</string> </tuple> diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/close.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/close.xml new file mode 100755 index 0000000000..bf8d257ad8 --- /dev/null +++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/close.xml @@ -0,0 +1,70 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <tuple> + <tuple> + <string>Products.DCWorkflow.Transitions</string> + <string>TransitionDefinition</string> + </tuple> + <none/> + </tuple> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>__ac_local_roles__</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>actbox_category</string> </key> + <value> <string>workflow</string> </value> + </item> + <item> + <key> <string>actbox_name</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>actbox_url</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>after_script_name</string> </key> + <value> <string>AccountingPeriod_DeliverTransactions</string> </value> + </item> + <item> + <key> <string>description</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>guard</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>close</string> </value> + </item> + <item> + <key> <string>new_state_id</string> </key> + <value> <string>closing</string> </value> + </item> + <item> + <key> <string>script_name</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>trigger_type</string> </key> + <value> <int>2</int> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/deliver_action.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/close_action.xml similarity index 85% rename from bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/deliver_action.xml rename to bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/close_action.xml index cda30d220b..66f1d121ed 100755 --- a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/deliver_action.xml +++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/close_action.xml @@ -28,15 +28,15 @@ </item> <item> <key> <string>actbox_url</string> </key> - <value> <string>%(content_url)s/BaseWorkflow_viewWorkflowActionDialog?workflow_action=deliver_action</string> </value> + <value> <string>%(content_url)s/BaseWorkflow_viewWorkflowActionDialog?workflow_action=close_action</string> </value> </item> <item> <key> <string>after_script_name</string> </key> - <value> <string>deliver</string> </value> + <value> <string>close</string> </value> </item> <item> <key> <string>description</string> </key> - <value> <string></string> </value> + <value> <string>Closing accounting period is made in an activity. if it fails, the Accounting Period object remains in confirmed state, otherwise it goes to delivered state, depending on the result of passing workflow transitions.</string> </value> </item> <item> <key> <string>guard</string> </key> @@ -46,7 +46,7 @@ </item> <item> <key> <string>id</string> </key> - <value> <string>deliver_action</string> </value> + <value> <string>close_action</string> </value> </item> <item> <key> <string>new_state_id</string> </key> @@ -54,7 +54,7 @@ </item> <item> <key> <string>script_name</string> </key> - <value> <string>AccountingPeriod_DeliverTransactions</string> </value> + <value> <string></string> </value> </item> <item> <key> <string>title</string> </key> diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/fail_closing.xml b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/fail_closing.xml new file mode 100755 index 0000000000..96eda90e69 --- /dev/null +++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_period_workflow/transitions/fail_closing.xml @@ -0,0 +1,70 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <tuple> + <tuple> + <string>Products.DCWorkflow.Transitions</string> + <string>TransitionDefinition</string> + </tuple> + <none/> + </tuple> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>__ac_local_roles__</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>actbox_category</string> </key> + <value> <string>workflow</string> </value> + </item> + <item> + <key> <string>actbox_name</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>actbox_url</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>after_script_name</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>description</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>guard</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>fail_closing</string> </value> + </item> + <item> + <key> <string>new_state_id</string> </key> + <value> <string>confirmed</string> </value> + </item> + <item> + <key> <string>script_name</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>trigger_type</string> </key> + <value> <int>2</int> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> -- 2.30.9