Commit a7688c4e authored by Jérome Perrin's avatar Jérome Perrin

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.
parent 8072877f
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(
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=dict(activated_invoice_count=activated,
total_selection_count=len(object_list)))))
mapping={'activated_invoice_count': activated,
'total_selection_count': len(object_list)})})
......@@ -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>
......
......@@ -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(
......
......@@ -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>
......
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