Commit b76a696a authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

accounting: introduce AccountingTransaction_checkConsistency

parent 2b03f3be
"""Check consistency of an accounting transaction.
This verifies the constraints defined in constraints and also "temporary" constraints,
such as "client is validated" or "accounting period is open" that are currently defined
in workflow script.
This is intentded to be used in custom scripts creating accounting transactions and
validating them.
"""
context.Base_checkConsistency()
accounting_workflow = context.getPortalObject().portal_workflow.accounting_workflow
accounting_workflow.script_validateTransactionLines(
{
'object': context,
'kwargs': {},
'transition': accounting_workflow.transition_deliver_action
})
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AccountingTransaction_checkConsistency</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -1147,6 +1147,33 @@ class TestTransactionValidation(AccountingTestCase): ...@@ -1147,6 +1147,33 @@ class TestTransactionValidation(AccountingTestCase):
self.portal.portal_workflow.doActionFor(accounting_transaction, self.portal.portal_workflow.doActionFor(accounting_transaction,
'stop_action') 'stop_action')
def test_AccountingTransaction_checkConsistency(self):
accounting_transaction = self._makeOne(
portal_type='Accounting Transaction',
start_date=DateTime('2008/12/31'),
destination_section_value=self.organisation_module.supplier,
lines=(dict(id='line_with_wrong_quantity',
source_value=self.account_module.goods_purchase,
source_debit=400),
dict(source_value=self.account_module.receivable,
source_credit=500)))
self.assertRaisesRegexp(
ValidationFailed,
'Transaction is not balanced',
accounting_transaction.AccountingTransaction_checkConsistency,
)
accounting_transaction.line_with_wrong_quantity.setSourceDebit(500)
self.assertRaisesRegexp(
ValidationFailed,
'Date is not in a started Accounting Period',
accounting_transaction.AccountingTransaction_checkConsistency,
)
accounting_transaction.setStartDate(DateTime('2007/11/11'))
accounting_transaction.AccountingTransaction_checkConsistency()
class TestClosingPeriod(AccountingTestCase): class TestClosingPeriod(AccountingTestCase):
"""Various tests for closing the period. """Various tests for closing the period.
......
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