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

validate lines with converted quantities


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5443 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cc5ce0e9
...@@ -68,63 +68,74 @@ ...@@ -68,63 +68,74 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
"""Validate Transaction Lines for the source.\n
"""\n
\n
from Products.DCWorkflow.DCWorkflow import ValidationFailed\n from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
\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
\n \n
# first of all, validate the transaction it self\n # first of all, validate the transaction it self\n
container.validateTransaction(state_change)\n container.validateTransaction(state_change)\n
\n \n
# Get sections.\n # Get sections.\n
source_section = transaction.getSourceSection(portal_type = [\'Person\', \'Organisation\',\'Category\'])\n source_section = transaction.getSourceSection(\n
destination_section = transaction.getDestinationSection(portal_type = [\'Person\', \'Organisation\',\'Category\'])\n portal_type = [\'Person\', \'Organisation\',\'Category\'])\n
destination_section = transaction.getDestinationSection(\n
portal_type = [\'Person\', \'Organisation\',\'Category\'])\n
\n \n
# Check transaction lines.\n # Check transaction lines.\n
if transaction.getPortalType() not in (\'Balance Transaction\',) :\n if transaction.getPortalType() not in (\'Balance Transaction\',) :\n
accountingTransactionLineList = transaction.contentValues(\n accounting_transaction_line_list = transaction.contentValues(\n
filter={\'portal_type\': (\'Accounting Transaction Line\',\n filter={ \'portal_type\':\n
\'Sale Invoice Transaction Line\',\n transaction.getPortalAccountingMovementTypeList()})\n
\'Pay Sheet Transaction Line\',\n
\'Purchase Invoice Transaction Line\' )})\n
sum = 0\n sum = 0\n
for transaction_line in accountingTransactionLineList:\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.getQuantity() or 0.0\n quantity = transaction_line.getSourceInventoriatedTotalAssetPrice() or 0\n
else :\n else :\n
quantity = transaction_line.getSourceDebit() - transaction_line.getSourceCredit() + \\\n quantity = transaction_line.getSourceInventoriatedTotalAssetPrice() or 0 +\\\n
transaction_line.getDestinationDebit() - transaction_line.getDestinationCredit()\n transaction_line.getDestinationInventoriatedTotalAssetPrice() or 0\n
\n
sum += int(round(quantity * 100))\n sum += int(round(quantity * 100))\n
\n if transaction_line.getSourceValue() is None :\n
if transaction_line.getSourceValue() is None : continue\n continue\n
\n \n
if transaction_line.getSourceValue().getValidationState() != \'validated\' :\n if transaction_line.getSourceValue().getValidationState() != \'validated\' :\n
raise ValidationFailed, N_(\'Action impossible : Account ${account_title} is ${state}\',\n raise ValidationFailed, N_(\n
mapping = {\'account_title\': unicode(transaction_line.getSourceValue().getTranslatedTitle(), \'utf8\'),\n \'Action impossible : Account ${account_title} is ${state}\',\n
\'state\': unicode(transaction_line.getSourceValue().\n mapping = {\'account_title\': unicode(transaction_line\\\n
getTranslatedValidationStateTitle(), \'utf8\')})\n .getSourceValue().getTranslatedTitle(), \'utf8\'),\n
\'state\': unicode(transaction_line.getSourceValue()\\\n
.getTranslatedValidationStateTitle(), \'utf8\')})\n
\n \n
if transaction_line.getSourceValue().getAccountTypeId() in ("receivable", "payable") \\\n if transaction_line.getSourceValue().getAccountTypeId() in (\n
and transaction_line.getDestinationSection() in (None, "") :\n "receivable", "payable") and \\\n
transaction_line.getDestinationSection() in (None, "") :\n
raise ValidationFailed, N_(\n raise ValidationFailed, N_(\n
\'Action impossible : no Third Party defined for line ${line} where Account Type is ${account_type}.\',\n \'Action impossible : no Third Party defined for line ${line} \'+\n
\'where Account Type is ${account_type}.\',\n
mapping = { \'line\': transaction_line.getId(),\n mapping = { \'line\': transaction_line.getId(),\n
\'account_type\' : unicode(transaction_line.getSourceValue()\n \'account_type\' : unicode(transaction_line.getSourceValue()\\\n
.getAccountTypeValue().getTranslatedLogicalPath(), \'utf8\')})\n .getAccountTypeValue().getTranslatedLogicalPath(), \'utf8\')})\n
\n \n
if transaction_line.getSourceValue().isMemberOf("account_type/asset/cash") \\\n if transaction_line.getSourceValue().isMemberOf("account_type/asset/cash") \\\n
and transaction_line.getSourcePayment() in (None, "") :\n and transaction_line.getSourcePayment() in (None, "") :\n
raise ValidationFailed, N_(\n raise ValidationFailed, N_(\n
\'Action impossible : no Bank Account defined for line ${line} where Account Type is ${account_type}.\',\n \'Action impossible : no Bank Account defined for line ${line} \'+\n
\'where Account Type is ${account_type}.\',\n
mapping = { \'line\': transaction_line.getId(),\n mapping = { \'line\': transaction_line.getId(),\n
\'account_type\' : unicode(transaction_line.getSourceValue()\n \'account_type\' : unicode(transaction_line.getSourceValue()\\\n
.getAccountTypeValue().getTranslatedLogicalPath(), \'utf8\')})\n .getAccountTypeValue().getTranslatedLogicalPath(), \'utf8\')})\n
\n \n
if sum > 0:\n if sum > 0:\n
raise ValidationFailed, N_(\'Action impossible : credit is greater than debit\')\n raise ValidationFailed, N_(\n
\'Action impossible : credit is greater than debit\')\n
elif sum < 0:\n elif sum < 0:\n
raise ValidationFailed, N_(\'Action impossible : credit is smaller than debit\')\n raise ValidationFailed, N_(\n
\'Action impossible : credit is smaller than debit\')\n
\n \n
transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n
...@@ -145,7 +156,7 @@ transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n ...@@ -145,7 +156,7 @@ transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n
</item> </item>
<item> <item>
<key> <string>_filepath</string> </key> <key> <string>_filepath</string> </key>
<value> <string>Script (Python):/nexedi/portal_workflow/accounting_workflow/scripts/validateTransactionLines</string> </value> <value> <string>Script (Python):/erp5/portal_workflow/accounting_workflow/scripts/validateTransactionLines</string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
...@@ -204,7 +215,7 @@ transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n ...@@ -204,7 +215,7 @@ 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>accountingTransactionLineList</string> <string>accounting_transaction_line_list</string>
<string>sum</string> <string>sum</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>transaction_line</string> <string>transaction_line</string>
......
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