From a7688c4e4f83ea22488224654c37f7a6230fe9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Wed, 4 Oct 2017 09:18:45 +0200 Subject: [PATCH] accounting: use Base_redirect instead of lower level RESPONSE.redirect This API takes care of building query string and redirecting to the same form_id, this is a cleanup. --- ...ule_createRelatedPaymentTransactionList.py | 38 ++++++++++--------- ...le_createRelatedPaymentTransactionList.xml | 2 +- ...Invoice_createRelatedPaymentTransaction.py | 6 +-- ...nvoice_createRelatedPaymentTransaction.xml | 2 +- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_createRelatedPaymentTransactionList.py b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_createRelatedPaymentTransactionList.py index 031f1371f6..a2a9b70542 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_createRelatedPaymentTransactionList.py +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_createRelatedPaymentTransactionList.py @@ -1,5 +1,4 @@ from Products.ERP5Type.Message import translateString -from zExceptions import Redirect portal = context.getPortalObject() countMessage = portal.portal_activities.countMessage @@ -21,10 +20,10 @@ portal.portal_selections.setSelectionParamsFor('accounting_create_related_paymen # XXX prevent to call this on the whole module: if len(object_list) >= 1000: - return context.REQUEST.RESPONSE.redirect( - "%s/view?portal_status_message=%s" % ( - context.absolute_url(), translateString( - 'Refusing to process more than 1000 objects, check your selection.'))) + return context.Base_redirect( + form_id, + keep_items={'portal_status_message': translateString( + 'Refusing to process more than 1000 objects, check your selection.')}) tag = 'payment_creation_%s' % random.randint(0, 1000) activated = 0 @@ -33,9 +32,11 @@ for obj in object_list: obj = obj.getObject() if countMessage(path=obj.getPath(), method_id='Invoice_createRelatedPaymentTransaction'): - raise Redirect, "%s/view?portal_status_message=%s" % ( - context.absolute_url(), translateString( - 'Payment creation already in progress, abandon.')) + return context.Base_redirect( + form_id, + abort_transaction=True, + keep_items={'portal_status_message': translateString( + 'Payment creation already in progress, abandon.')}) obj.activate(tag=tag).Invoice_createRelatedPaymentTransaction( node=node, payment_mode=payment_mode, @@ -44,17 +45,18 @@ for obj in object_list: activated += 1 if not activated: - return context.REQUEST.RESPONSE.redirect( - "%s/view?portal_status_message=%s" % ( - context.absolute_url(), translateString('No invoice in your selection.'))) + return context.Base_redirect( + form_id, + keep_items={'portal_status_message': translateString( + 'No invoice in your selection.')}) # activate something on the folder context.activate(after_tag=tag).getTitle() -return context.REQUEST.RESPONSE.redirect( - "%s/view?portal_status_message=%s" % ( - context.absolute_url(), translateString( - 'Payments creation for ${activated_invoice_count} on' - ' ${total_selection_count} invoices in progress.', - mapping=dict(activated_invoice_count=activated, - total_selection_count=len(object_list))))) +return context.Base_redirect( + form_id, + keep_items={'portal_status_message': translateString( + 'Payments creation for ${activated_invoice_count} on' + ' ${total_selection_count} invoices in progress.', + mapping={'activated_invoice_count': activated, + 'total_selection_count': len(object_list)})}) diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_createRelatedPaymentTransactionList.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_createRelatedPaymentTransactionList.xml index d0ce2b915c..58f4a14b64 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_createRelatedPaymentTransactionList.xml +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountingTransactionModule_createRelatedPaymentTransactionList.xml @@ -50,7 +50,7 @@ </item> <item> <key> <string>_params</string> </key> - <value> <string>node, payment_mode, payment, selection_index=None, uids=(), listbox_uid=(),selection_name=\'\', **kw</string> </value> + <value> <string>node, payment_mode, payment, selection_index=None, uids=(), listbox_uid=(),selection_name=\'\', form_id=\'\', **kw</string> </value> </item> <item> <key> <string>id</string> </key> diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.py b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.py index ae6ff83beb..abdfb99199 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.py +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.py @@ -30,9 +30,9 @@ total_payable_price_details = \ # if there's nothing more to pay, don't create an empty transaction if sum(total_payable_price_details.values()) == 0: if not batch_mode: - return context.REQUEST.RESPONSE.redirect( - "%s/view?portal_status_message=%s" % ( - context.absolute_url(), Base_translateString('Nothing more to pay.'))) + return context.Base_redirect( + form_id, + keep_items={'portal_status_message': Base_translateString('Nothing more to pay.')}) return None related_payment = portal.accounting_module.newContent( diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.xml b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.xml index 2375575afc..47669574ca 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.xml +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.xml @@ -50,7 +50,7 @@ </item> <item> <key> <string>_params</string> </key> - <value> <string>node, payment_mode, payment, date=None, plan=False, batch_mode=0, **kw</string> </value> + <value> <string>node, payment_mode, payment, date=None, plan=False, batch_mode=0, form_id=\'\', **kw</string> </value> </item> <item> <key> <string>id</string> </key> -- 2.30.9