Commit 4f748c63 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Xiaowu Zhang

erp5_travel_expense: Fix Creation of transaction to respect accounting constraints

parent 76aa17d4
......@@ -23,6 +23,7 @@ transaction = portal.accounting_module.newContent(
resource=context.getPriceCurrency(),
created_by_builder=1, # XXX this prevent init script from creating lines.
start_date=context.getStartDate(),
stop_date=context.getStartDate(),
causality=context.getRelativeUrl(),
)
......@@ -38,6 +39,27 @@ transaction.newContent(
quantity=(-float(context.getTotalPrice())),
)
from Products.DCWorkflow.DCWorkflow import ValidationFailed
from zExceptions import Redirect
try:
transaction.Base_checkConsistency()
except ValidationFailed, error_message:
if getattr(error_message, 'msg', None):
# use of Message class to store message+mapping+domain
message = error_message.msg
if same_type(message, []):
message = '. '.join('%s' % x for x in message)
else:
message = str(message)
else:
message = str(error_message)
if len(message) > 2000: # too long message will generate a too long URI
# that would become an error.
message = "%s ..." % message[:(2000 - 4)]
raise Redirect, "%s?portal_status_message=%s" % (
context.getAbsoluteUrl(),
message
)
transaction.stop()
return transaction.getRelativeUrl()
......@@ -27,15 +27,15 @@
<item>
<key> <string>after_script_name</string> </key>
<value>
<list>
<string>ExpenseValidationRequest_accept</string>
</list>
<tuple/>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<tuple/>
<list>
<string>ExpenseValidationRequest_accept</string>
</list>
</value>
</item>
<item>
......@@ -67,9 +67,7 @@
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<list>
<string>Expense Validation Request</string>
</list>
<none/>
</value>
</item>
<item>
......
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