Commit 7bdd936e authored by Jérome Perrin's avatar Jérome Perrin

Simplify workflow scripts, as validation is mostly done using constraints.

We still use workflow scripts for "transiant validation" : for example, validating that at the time we validate this transaction an accounting period is open, other parties are not invalidated.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18382 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 626f45ac
...@@ -76,45 +76,41 @@ from Products.ERP5Type.Message import Message\n ...@@ -76,45 +76,41 @@ from Products.ERP5Type.Message import Message\n
transaction = state_change[\'object\']\n transaction = state_change[\'object\']\n
N_ = lambda msg, **kw: Message(\'erp5_ui\', msg, **kw)\n N_ = lambda msg, **kw: Message(\'erp5_ui\', msg, **kw)\n
\n \n
# do we have to check transaction is in openned periods ? \n # XXX manually default start date to stop date\n
if not transaction.getStartDate() and transaction.getStopDate():\n
transaction.setStartDate(transaction.getStopDate())\n
\n
# Check constraints\n
transaction.Base_checkConsistency()\n
\n
# Check that the transaction is in an open accounting period when we validate\n
# it.\n
skip_period_validation = state_change[\'kwargs\'].get(\n skip_period_validation = state_change[\'kwargs\'].get(\n
\'skip_period_validation\', 0)\n \'skip_period_validation\', 0)\n
transition = state_change[\'transition\']\n transition = state_change[\'transition\']\n
if transition.id in (\'plan_action\', \'confirm_action\') :\n if transition.id in (\'plan_action\', \'confirm_action\') :\n
skip_period_validation = 1\n skip_period_validation = 1\n
\n \n
# Get sections and a currency.\n
source_section = transaction.getSourceSectionValue(\n source_section = transaction.getSourceSectionValue(\n
portal_type=[\'Organisation\', \'Person\'])\n portal_type=[\'Organisation\', \'Person\'])\n
if source_section is None:\n
raise ValidationFailed(N_(\'Source Section is not Defined.\'))\n
\n
destination_section = transaction.getDestinationSectionValue(\n destination_section = transaction.getDestinationSectionValue(\n
portal_type=[\'Organisation\', \'Person\'])\n portal_type=[\'Organisation\', \'Person\'])\n
# if it\'s not an invoice, then we can validate without destination\n
if destination_section is None and \\\n
transaction.getPortalType() in transaction.getPortalInvoiceTypeList():\n
raise ValidationFailed(N_(\'Destination Section is not Defined.\'))\n
\n \n
currency = transaction.getResource(portal_type = \'Currency\')\n if source_section is None and destination_section is None:\n
if not currency :\n raise ValidationFailed(N_(\'At Least One Section Must be Defined\'))\n
raise ValidationFailed(N_(\'Currency is not Defined.\'))\n
\n \n
# XXX manually default start date to stop date\n # check that no categories are used for section\n
if not transaction.getStartDate() and transaction.getStopDate():\n if transaction.getSourceSectionValue(portal_type=\'Category\') is not None or\\\n
transaction.setStartDate(transaction.getStopDate())\n transaction.getDestinationSectionValue(portal_type=\'Category\') is not None:\n
raise ValidationFailed(N_(\'Using Category for Section is Invalid\'))\n
\n \n
\n
transaction_line_list = transaction.getMovementList(\n transaction_line_list = transaction.getMovementList(\n
portal_type=transaction.getPortalAccountingMovementTypeList())\n portal_type=transaction.getPortalAccountingMovementTypeList())\n
if not transaction.getStartDate() :\n \n
raise ValidationFailed(N_(\'Date is not Defined\'))\n if not skip_period_validation :\n
else:\n
if not skip_period_validation :\n
# check the date is in an opened period\n # check the date is in an opened period\n
if source_section is not None:\n if source_section is not None:\n
# if we don\'t have any accounts on this side, we don\'t enforce date\n # if we don\'t have any accounts on this side, we don\'t enforce date checks\n
# checks\n
valid_date = False\n valid_date = False\n
no_accounts = True\n no_accounts = True\n
for line in transaction_line_list:\n for line in transaction_line_list:\n
...@@ -142,8 +138,7 @@ else:\n ...@@ -142,8 +138,7 @@ else:\n
"for source section"))\n "for source section"))\n
# do the same for destination section \n # do the same for destination section \n
if destination_section is not None:\n if destination_section is not None:\n
# if we don\'t have any accounts on this side, we don\'t enforce date\n # if we don\'t have any accounts on this side, we don\'t enforce date checks\n
# checks\n
valid_date = False\n valid_date = False\n
no_accounts = True\n no_accounts = True\n
for line in transaction_line_list:\n for line in transaction_line_list:\n
...@@ -239,9 +234,8 @@ else:\n ...@@ -239,9 +234,8 @@ else:\n
<string>skip_period_validation</string> <string>skip_period_validation</string>
<string>transition</string> <string>transition</string>
<string>source_section</string> <string>source_section</string>
<string>None</string>
<string>destination_section</string> <string>destination_section</string>
<string>currency</string> <string>None</string>
<string>transaction_line_list</string> <string>transaction_line_list</string>
<string>False</string> <string>False</string>
<string>valid_date</string> <string>valid_date</string>
......
526 531
\ 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