Commit 4aad72e4 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 a7db5bb3
...@@ -23,6 +23,7 @@ transaction = portal.accounting_module.newContent( ...@@ -23,6 +23,7 @@ transaction = portal.accounting_module.newContent(
resource=context.getPriceCurrency(), resource=context.getPriceCurrency(),
created_by_builder=1, # XXX this prevent init script from creating lines. created_by_builder=1, # XXX this prevent init script from creating lines.
start_date=context.getStartDate(), start_date=context.getStartDate(),
stop_date=context.getStartDate(),
causality=context.getRelativeUrl(), causality=context.getRelativeUrl(),
) )
...@@ -38,6 +39,27 @@ transaction.newContent( ...@@ -38,6 +39,27 @@ transaction.newContent(
quantity=(-float(context.getTotalPrice())), 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() transaction.stop()
return transaction.getRelativeUrl() return transaction.getRelativeUrl()
...@@ -27,15 +27,15 @@ ...@@ -27,15 +27,15 @@
<item> <item>
<key> <string>after_script_name</string> </key> <key> <string>after_script_name</string> </key>
<value> <value>
<list> <tuple/>
<string>ExpenseValidationRequest_accept</string>
</list>
</value> </value>
</item> </item>
<item> <item>
<key> <string>before_commit_script_name</string> </key> <key> <string>before_commit_script_name</string> </key>
<value> <value>
<tuple/> <list>
<string>ExpenseValidationRequest_accept</string>
</list>
</value> </value>
</item> </item>
<item> <item>
...@@ -67,9 +67,7 @@ ...@@ -67,9 +67,7 @@
<item> <item>
<key> <string>portal_type_filter</string> </key> <key> <string>portal_type_filter</string> </key>
<value> <value>
<list> <none/>
<string>Expense Validation Request</string>
</list>
</value> </value>
</item> </item>
<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