Commit 2c7a8077 authored by Jérome Perrin's avatar Jérome Perrin

AccountingTransactionModule_createRelatedPaymentTransactionList:

  Refuse to create payment if payment creation is already in progress.
Invoice_createRelatedPaymentTransaction:
  Make sure we don't create an empty transaction.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12876 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8fa2de69
...@@ -74,6 +74,7 @@ from Products.ERP5Type.Message import Message\n ...@@ -74,6 +74,7 @@ from Products.ERP5Type.Message import Message\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
stool = portal.portal_selections\n stool = portal.portal_selections\n
getObject = portal.portal_catalog.getObject\n getObject = portal.portal_catalog.getObject\n
countMessage = portal.portal_activities.countMessage\n
invoice_type_list = portal.getPortalInvoiceTypeList()\n invoice_type_list = portal.getPortalInvoiceTypeList()\n
N_ = lambda msg, **kw: Message(\'erp5_ui\', msg, **kw)\n N_ = lambda msg, **kw: Message(\'erp5_ui\', msg, **kw)\n
\n \n
...@@ -92,17 +93,23 @@ stool.setSelectionParamsFor(\'accounting_create_related_payment_selection\',\n ...@@ -92,17 +93,23 @@ stool.setSelectionParamsFor(\'accounting_create_related_payment_selection\',\n
payment_for_related_payment=payment))\n payment_for_related_payment=payment))\n
\n \n
# XXX prevent to call this on the whole module:\n # XXX prevent to call this on the whole module:\n
if len(object_list) > 100:\n if len(object_list) >= 1000:\n
return context.REQUEST.RESPONSE.redirect(\n return context.REQUEST.RESPONSE.redirect(\n
"%s/view?portal_status_message=%s" % (\n "%s/view?portal_status_message=%s" % (\n
context.absolute_url(), N_(\n context.absolute_url(), N_(\n
\'Refusing to process more than 100 objects, check your selection\')))\n \'Refusing to process more than 1000 objects, check your selection\')))\n
\n \n
tag = \'payment_creation_%s\' % portal.portal_ids.generateNewLongId()\n tag = \'payment_creation_%s\' % portal.portal_ids.generateNewLongId()\n
activated = 0\n activated = 0\n
for obj in object_list:\n for obj in object_list:\n
if obj.portal_type in invoice_type_list:\n if obj.portal_type in invoice_type_list:\n
obj.getObject().activate(tag=tag).Invoice_createRelatedPaymentTransaction(\n obj = obj.getObject()\n
if countMessage(path=obj.getPath(),\n
method_id=\'Invoice_createRelatedPaymentTransaction\'):\n
raise \'Redirect\', "%s/view?portal_status_message=%s" % (\n
context.absolute_url(), N_(\'Payment Creation already in\'\n
\' progress, abandon\'))\n
obj.activate(tag=tag).Invoice_createRelatedPaymentTransaction(\n
node=node,\n node=node,\n
payment_mode=payment_mode,\n payment_mode=payment_mode,\n
payment=payment,\n payment=payment,\n
...@@ -182,6 +189,7 @@ return context.REQUEST.RESPONSE.redirect(\n ...@@ -182,6 +189,7 @@ return context.REQUEST.RESPONSE.redirect(\n
<string>portal</string> <string>portal</string>
<string>stool</string> <string>stool</string>
<string>getObject</string> <string>getObject</string>
<string>countMessage</string>
<string>invoice_type_list</string> <string>invoice_type_list</string>
<string>N_</string> <string>N_</string>
<string>selection_uid_list</string> <string>selection_uid_list</string>
......
...@@ -90,6 +90,20 @@ portal.portal_selections.setSelectionParamsFor(\n ...@@ -90,6 +90,20 @@ portal.portal_selections.setSelectionParamsFor(\n
payment_mode_for_related_payment=payment_mode,\n payment_mode_for_related_payment=payment_mode,\n
payment_for_related_payment=payment))\n payment_for_related_payment=payment))\n
\n \n
\n
# Calculate the payable/receivable quantity, using\n
# Invoice_getRemainingTotalPayablePrice script.\n
total_payable_price_details = \\\n
context.Invoice_getRemainingTotalPayablePrice(detailed=True)\n
\n
# if there\'s nothing more to pay, don\'t create an empty transaction\n
if sum(total_payable_price_per_node_section.values()) == 0:\n
if not batch_mode:\n
return context.REQUEST.RESPONSE.redirect(\n
"%s/view?portal_status_message=%s" % (\n
context.absolute_url(), N_(\'Nothing more to pay\')))\n
return None\n
\n
related_payment = portal.accounting_module.newContent(\n related_payment = portal.accounting_module.newContent(\n
portal_type="Payment Transaction",\n portal_type="Payment Transaction",\n
title=str(N_("Payment of ${invoice_title}",\n title=str(N_("Payment of ${invoice_title}",\n
...@@ -122,10 +136,6 @@ bank = related_payment.newContent(\n ...@@ -122,10 +136,6 @@ bank = related_payment.newContent(\n
)\n )\n
bank_quantity = 0\n bank_quantity = 0\n
\n \n
# Calculate the payable/receivable quantity, using\n
# Invoice_getRemainingTotalPayablePrice script.\n
total_payable_price_details = \\\n
context.Invoice_getRemainingTotalPayablePrice(detailed=True)\n
for (line_node, line_mirror_section), quantity in\\\n for (line_node, line_mirror_section), quantity in\\\n
total_payable_price_details.items():\n total_payable_price_details.items():\n
if line_mirror_section == mirror_section:\n if line_mirror_section == mirror_section:\n
...@@ -216,6 +226,11 @@ else:\n ...@@ -216,6 +226,11 @@ else:\n
<string>is_source</string> <string>is_source</string>
<string>line_portal_type</string> <string>line_portal_type</string>
<string>dict</string> <string>dict</string>
<string>True</string>
<string>total_payable_price_details</string>
<string>sum</string>
<string>total_payable_price_per_node_section</string>
<string>None</string>
<string>str</string> <string>str</string>
<string>unicode</string> <string>unicode</string>
<string>related_payment</string> <string>related_payment</string>
...@@ -223,8 +238,6 @@ else:\n ...@@ -223,8 +238,6 @@ else:\n
<string>mirror_section</string> <string>mirror_section</string>
<string>bank</string> <string>bank</string>
<string>bank_quantity</string> <string>bank_quantity</string>
<string>True</string>
<string>total_payable_price_details</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>line_node</string> <string>line_node</string>
<string>line_mirror_section</string> <string>line_mirror_section</string>
......
186 187
\ No newline at end of file \ No newline at end of file
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