Commit 1e26a7e7 authored by Jérome Perrin's avatar Jérome Perrin

validate from both sides and using values in converted currency


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5615 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7e514fec
...@@ -66,13 +66,13 @@ ...@@ -66,13 +66,13 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>"""Validate Transaction Lines for source and destination section.\n
"""Validate Transaction Lines for the source.\n
"""\n """\n
\n \n
from Products.DCWorkflow.DCWorkflow import ValidationFailed\n from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
\n \n
SOURCE, DESTINATION = (\'source\', \'destination\')\n
\n
error_message = \'\'\n error_message = \'\'\n
transaction = state_change[\'object\']\n transaction = state_change[\'object\']\n
N_ = transaction.Base_translateString\n N_ = transaction.Base_translateString\n
...@@ -86,61 +86,77 @@ source_section = transaction.getSourceSection(\n ...@@ -86,61 +86,77 @@ source_section = transaction.getSourceSection(\n
destination_section = transaction.getDestinationSection(\n destination_section = transaction.getDestinationSection(\n
portal_type = [\'Person\', \'Organisation\',\'Category\'])\n portal_type = [\'Person\', \'Organisation\',\'Category\'])\n
\n \n
# Check transaction lines.\n source_sum = 0\n
destination_sum = 0\n
\n
# Check transaction lines\n
if transaction.getPortalType() not in (\'Balance Transaction\',) :\n if transaction.getPortalType() not in (\'Balance Transaction\',) :\n
accounting_transaction_line_list = transaction.contentValues(\n accounting_transaction_line_list = transaction.contentValues(\n
filter={ \'portal_type\':\n filter={ \'portal_type\':\n
transaction.getPortalAccountingMovementTypeList()})\n transaction.getPortalAccountingMovementTypeList()})\n
sum = 0\n
for transaction_line in accounting_transaction_line_list:\n for transaction_line in accounting_transaction_line_list:\n
if source_section != destination_section :\n if source_section != destination_section :\n
quantity = transaction_line.getSourceInventoriatedTotalAssetPrice() or 0\n source_quantity = transaction_line\\\n
.getSourceInventoriatedTotalAssetPrice() or 0\n
destination_quantity = transaction_line\\\n
.getDestinationInventoriatedTotalAssetPrice() or 0\n
else :\n else :\n
quantity = transaction_line.getSourceInventoriatedTotalAssetPrice() or 0 +\\\n destination_quantity = source_quantity = transaction_line\\\n
transaction_line.getDestinationInventoriatedTotalAssetPrice() or 0\n .getSourceInventoriatedTotalAssetPrice() or 0 +\\\n
transaction_line.getDestinationInventoriatedTotalAssetPrice() or 0\n
\n \n
sum += int(round(quantity * 100))\n source_sum += int(round(source_quantity * 100))\n
destination_sum += int(round(destination_quantity * 100))\n
\n \n
# TODO: validate from both source and destination\n for side in (SOURCE, DESTINATION) :\n
account = transaction_line.getSourceValue(portal_type = \'Account\')\n if side == SOURCE :\n
if account is None :\n account = transaction_line.getSourceValue(portal_type = \'Account\')\n
continue\n mirror_section = transaction_line.getDestinationSection()\n
paiment = transaction_line.getSourcePayment()\n
else:\n
account = transaction_line.getDestinationValue(portal_type = \'Account\')\n
mirror_section = transaction_line.getSourceSection()\n
paiment = transaction_line.getDestinationPayment()\n
\n
if account is None :\n
continue\n
\n \n
if account .getValidationState() != \'validated\' :\n if account.getValidationState() != \'validated\' :\n
raise ValidationFailed, N_(\n raise ValidationFailed, N_(\n
\'Action impossible : Account ${account_title} is ${state}\',\n \'Action impossible : Account ${account_title} is ${state}\',\n
mapping = {\'account_title\': unicode(account.getTranslatedTitle(), \'utf8\'),\n mapping = {\'account_title\':\n
\'state\': unicode(account.getTranslatedValidationStateTitle(), \'utf8\')})\n unicode(account.getTranslatedTitle(), \'utf8\'),\n
\n \'state\': unicode(account\\\n
if account.getAccountTypeId() in ("receivable", "payable") and \\\n .getTranslatedValidationStateTitle(), \'utf8\')})\n
transaction_line.getDestinationSection() in (None, "") :\n \n
raise ValidationFailed, N_(\n if account.getAccountTypeId() in ("receivable", "payable") and \\\n
\'Action impossible : no Third Party defined for line ${line} \'+\n mirror_section in (None, "") :\n
\'where Account Type is ${account_type}.\',\n raise ValidationFailed, N_(\n
mapping = { \'line\': transaction_line.getId(),\n \'Action impossible : no Third Party defined for line ${line} \'+\n
\'account_type\' : unicode(account\\\n \'where Account Type is ${account_type}.\',\n
.getAccountTypeValue().getTranslatedLogicalPath(), \'utf8\')})\n mapping = { \'line\': transaction_line.getId(),\n
\n \'account_type\' : unicode(account\\\n
if account.isMemberOf("account_type/asset/cash") \\\n .getAccountTypeValue().getTranslatedLogicalPath(), \'utf8\')})\n
and transaction_line.getSourcePayment() in (None, "") :\n \n
raise ValidationFailed, N_(\n if account.isMemberOf("account_type/asset/cash") \\\n
\'Action impossible : no Bank Account defined for line ${line} \'+\n and paiment in (None, "") :\n
\'where Account Type is ${account_type}.\',\n raise ValidationFailed, N_(\n
mapping = { \'line\': transaction_line.getId(),\n \'Action impossible : no Bank Account defined for line ${line} \'+\n
\'account_type\' : unicode(account\\\n \'where Account Type is ${account_type}.\',\n
.getAccountTypeValue().getTranslatedLogicalPath(), \'utf8\')})\n mapping = { \'line\': transaction_line.getId(),\n
\'account_type\' : unicode(account\\\n
.getAccountTypeValue().getTranslatedLogicalPath(), \'utf8\')})\n
\n \n
if sum > 0:\n if source_sum != 0:\n
raise ValidationFailed, N_(\n raise ValidationFailed, N_(\n
\'Action impossible : credit is greater than debit\')\n \'Action impossible : transaction is not balanced for source section\')\n
elif sum < 0:\n \n
if destination_sum != 0:\n
raise ValidationFailed, N_(\n raise ValidationFailed, N_(\n
\'Action impossible : credit is smaller than debit\')\n \'Action impossible : transaction is not balanced for destination section\')\n
\n \n
transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_code</string> </key> <key> <string>_code</string> </key>
...@@ -207,6 +223,9 @@ transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n ...@@ -207,6 +223,9 @@ transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n
<string>state_change</string> <string>state_change</string>
<string>Products.DCWorkflow.DCWorkflow</string> <string>Products.DCWorkflow.DCWorkflow</string>
<string>ValidationFailed</string> <string>ValidationFailed</string>
<string>_getiter_</string>
<string>SOURCE</string>
<string>DESTINATION</string>
<string>error_message</string> <string>error_message</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>transaction</string> <string>transaction</string>
...@@ -215,14 +234,18 @@ transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n ...@@ -215,14 +234,18 @@ transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n
<string>container</string> <string>container</string>
<string>source_section</string> <string>source_section</string>
<string>destination_section</string> <string>destination_section</string>
<string>source_sum</string>
<string>destination_sum</string>
<string>accounting_transaction_line_list</string> <string>accounting_transaction_line_list</string>
<string>sum</string>
<string>_getiter_</string>
<string>transaction_line</string> <string>transaction_line</string>
<string>quantity</string> <string>source_quantity</string>
<string>destination_quantity</string>
<string>int</string> <string>int</string>
<string>round</string> <string>round</string>
<string>side</string>
<string>account</string> <string>account</string>
<string>mirror_section</string>
<string>paiment</string>
<string>None</string> <string>None</string>
<string>unicode</string> <string>unicode</string>
</tuple> </tuple>
......
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