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

only validate for mirror section if mirror section and section are in the same

group.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10057 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent da95e49b
...@@ -74,11 +74,10 @@ ...@@ -74,11 +74,10 @@
"""\n """\n
\n \n
from Products.DCWorkflow.DCWorkflow import ValidationFailed\n from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
from Products.ERP5Type.Message import Message\n
\n \n
transaction = state_change[\'object\']\n transaction = state_change[\'object\']\n
N_ = transaction.Base_translateString\n N_ = lambda msg, **kw: Message(\'erp5_ui\', msg, **kw)\n
def raiseError(msg) :\n
raise ValidationFailed(N_(msg))\n
\n \n
# do we have to check transaction is in openned periods ?\n # do we have to check transaction is in openned periods ?\n
skip_period_validation = state_change[\'kwargs\'].get(\n skip_period_validation = state_change[\'kwargs\'].get(\n
...@@ -98,7 +97,7 @@ if source_section is not None and \\\n ...@@ -98,7 +97,7 @@ if source_section is not None and \\\n
source_section = source_section.getMappingRelatedValue(\n source_section = source_section.getMappingRelatedValue(\n
portal_type = \'Organisation\')\n portal_type = \'Organisation\')\n
if source_section is None:\n if source_section is None:\n
raiseError(\'Source Section is not Defined.\')\n raise ValidationFailed(\'Source Section is not Defined.\')\n
\n \n
destination_section = transaction.getDestinationSectionValue(\n destination_section = transaction.getDestinationSectionValue(\n
portal_type = [\'Organisation\', \'Person\', \'Category\'])\n portal_type = [\'Organisation\', \'Person\', \'Category\'])\n
...@@ -108,18 +107,18 @@ if destination_section is not None and \\\n ...@@ -108,18 +107,18 @@ if destination_section is not None and \\\n
portal_type = \'Organisation\')\n portal_type = \'Organisation\')\n
# if it\'s not an invoice, then we can validate without destination\n # if it\'s not an invoice, then we can validate without destination\n
if destination_section is None and check_destination :\n if destination_section is None and check_destination :\n
raiseError(\'Destination Section is not Defined.\')\n raise ValidationFailed(\'Destination Section is not Defined.\')\n
\n \n
currency = transaction.getResource(portal_type = \'Currency\')\n currency = transaction.getResource(portal_type = \'Currency\')\n
if not currency :\n if not currency :\n
raiseError(\'Currency is not Defined.\')\n raise ValidationFailed(\'Currency is not Defined.\')\n
\n \n
# XXX manually default start date to stop date\n # XXX manually default start date to stop date\n
if not transaction.getStartDate() and transaction.getStopDate():\n if not transaction.getStartDate() and transaction.getStopDate():\n
transaction.setStartDate(transaction.getStopDate())\n transaction.setStartDate(transaction.getStopDate())\n
\n \n
if not transaction.getStartDate() :\n if not transaction.getStartDate() :\n
raiseError(\'Date is not Defined\')\n raise ValidationFailed(\'Date is not Defined\')\n
else:\n else:\n
if not skip_period_validation :\n if not skip_period_validation :\n
valid_date = False\n valid_date = False\n
...@@ -142,7 +141,7 @@ else:\n ...@@ -142,7 +141,7 @@ else:\n
if apd.getStartDate().Date() <= transaction_date.Date() <= apd.getStopDate().Date():\n if apd.getStartDate().Date() <= transaction_date.Date() <= apd.getStopDate().Date():\n
valid_date = True\n valid_date = True\n
if not valid_date :\n if not valid_date :\n
raiseError("Date is not in an openned Accounting Period "\n raise ValidationFailed("Date is not in an openned Accounting Period "\n
"for source section")\n "for source section")\n
# do the same for destination section \n # do the same for destination section \n
if check_destination :\n if check_destination :\n
...@@ -162,7 +161,7 @@ else:\n ...@@ -162,7 +161,7 @@ else:\n
if apd.getStartDate().Date() <= transaction_date.Date() <= apd.getStopDate().Date():\n if apd.getStartDate().Date() <= transaction_date.Date() <= apd.getStopDate().Date():\n
valid_date = True\n valid_date = True\n
if not valid_date :\n if not valid_date :\n
raiseError("Date is not in an openned Accounting Period "+\n raise ValidationFailed("Date is not in an openned Accounting Period "\n
"for destination section")\n "for destination section")\n
...@@ -235,11 +234,12 @@ else:\n ...@@ -235,11 +234,12 @@ else:\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>Products.ERP5Type.Message</string>
<string>Message</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>transaction</string> <string>transaction</string>
<string>_getattr_</string>
<string>N_</string> <string>N_</string>
<string>raiseError</string> <string>_getattr_</string>
<string>skip_period_validation</string> <string>skip_period_validation</string>
<string>transition</string> <string>transition</string>
<string>check_destination</string> <string>check_destination</string>
......
...@@ -68,24 +68,34 @@ ...@@ -68,24 +68,34 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>"""\n <value> <string>"""Validate Transaction Lines for source and destination section.\n
Validate Transaction Lines for source and destination section.\n
"""\n """\n
\n \n
from Products.DCWorkflow.DCWorkflow import ValidationFailed\n from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
from Products.ERP5Type.Message import Message\n
\n \n
SOURCE, DESTINATION = (\'source\', \'destination\')\n SOURCE, DESTINATION = (\'source\', \'destination\')\n
\n
error_message = \'\'\n
transaction = state_change[\'object\']\n transaction = state_change[\'object\']\n
N_ = transaction.Base_translateString\n N_ = lambda msg, **kw: Message(\'erp5_ui\', msg, **kw)\n
\n \n
# first of all, validate the transaction itself\n # first of all, validate the transaction itself\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.getSourceSectionValue(\n
destination_section = transaction.getDestinationSection(portal_type = [\'Person\', \'Organisation\',\'Category\'])\n portal_type=[\'Person\', \'Organisation\'])\n
destination_section = transaction.getDestinationSectionValue(\n
portal_type=[\'Person\', \'Organisation\'])\n
\n
# do we want to check validity for destination as well?\n
check_for_destination = 0\n
if source_section is not None and destination_section is not None:\n
source_section_group = source_section.getGroup().lstrip(\'group/\').split(\'/\')\n
destination_section_group = destination_section\\\n
.getGroup().lstrip(\'group/\').split(\'/\')\n
if destination_section_group and source_section_group and \\\n
destination_section_group[0] == source_section_group[0]:\n
check_for_destination = 1\n
\n \n
source_sum = 0\n source_sum = 0\n
destination_sum = 0\n destination_sum = 0\n
...@@ -96,10 +106,14 @@ if transaction.getPortalType() not in (\'Balance Transaction\',) :\n ...@@ -96,10 +106,14 @@ if transaction.getPortalType() not in (\'Balance Transaction\',) :\n
filter={ \'portal_type\':\n filter={ \'portal_type\':\n
transaction.getPortalAccountingMovementTypeList()})\n transaction.getPortalAccountingMovementTypeList()})\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 # XXX would source_section != destination_section work here ?\n
source_quantity = transaction_line.getSourceInventoriatedTotalAssetPrice() or 0\n if source_section is not None and destination_section is not None and\\\n
destination_quantity = transaction_line.getDestinationInventoriatedTotalAssetPrice() or 0\n source_section.getUid() != destination_section.getUid():\n
else :\n source_quantity = transaction_line\\\n
.getSourceInventoriatedTotalAssetPrice() or 0\n
destination_quantity = transaction_line\\\n
.getDestinationInventoriatedTotalAssetPrice() or 0\n
else:\n
destination_quantity = source_quantity = ((transaction_line\\\n destination_quantity = source_quantity = ((transaction_line\\\n
.getSourceInventoriatedTotalAssetPrice() or 0) + \\\n .getSourceInventoriatedTotalAssetPrice() or 0) + \\\n
(transaction_line.getDestinationInventoriatedTotalAssetPrice() or 0))\n (transaction_line.getDestinationInventoriatedTotalAssetPrice() or 0))\n
...@@ -110,72 +124,108 @@ if transaction.getPortalType() not in (\'Balance Transaction\',) :\n ...@@ -110,72 +124,108 @@ if transaction.getPortalType() not in (\'Balance Transaction\',) :\n
if transaction_line.getSource( portal_type = \'Account\') is None and \\\n if transaction_line.getSource( portal_type = \'Account\') is None and \\\n
transaction_line.getDestination(portal_type = \'Account\') is None and \\\n transaction_line.getDestination(portal_type = \'Account\') is None and \\\n
transaction_line.getQuantity() != 0:\n transaction_line.getQuantity() != 0:\n
raise ValidationFailed, N_("Action failed: no account defined for line \'${line_id}\'."\n raise ValidationFailed, N_(\n
, mapping = {\'line_id\': transaction_line.getId()}\n "Action failed: no account defined for line \'${line_id}\'.",\n
)\n mapping = {\'line_id\': transaction_line.getId()} )\n
\n \n
for side in (SOURCE, DESTINATION) :\n for side in (SOURCE, DESTINATION) :\n
if side == SOURCE:\n if side == SOURCE:\n
account = transaction_line.getSourceValue(portal_type = \'Account\')\n account = transaction_line.getSourceValue(portal_type=\'Account\')\n
payment = transaction_line.getSourcePaymentValue()\n payment = transaction_line.getSourcePaymentValue()\n
third_party_path = transaction_line.getDestinationSection()\n
third_party = transaction_line.getDestinationSectionValue()\n third_party = transaction_line.getDestinationSectionValue()\n
else:\n else:\n
account = transaction_line.getDestinationValue(portal_type = \'Account\')\n account = transaction_line.getDestinationValue(portal_type=\'Account\')\n
payment = transaction_line.getDestinationPaymentValue()\n payment = transaction_line.getDestinationPaymentValue()\n
third_party_path = transaction_line.getSourceSection()\n
third_party = transaction_line.getSourceSectionValue()\n third_party = transaction_line.getSourceSectionValue()\n
\n \n
if account is None:\n if account is None:\n
continue\n continue\n
\n \n
if account.getValidationState() != \'validated\':\n if account.getValidationState() != \'validated\':\n
raise ValidationFailed, N_("Action failed: account \'${account_title}\' is not opened."\n raise ValidationFailed, N_(\n
, mapping = {\'account_title\': unicode(account.getTranslatedTitle(), \'utf8\')}\n "Action failed: account \'${account_title}\' is not opened.",\n
)\n mapping = {\'account_title\':\n
\n unicode(account.getTranslatedTitle(), \'utf8\')})\n
\n
# Test third party related-data\n # Test third party related-data\n
if account.getAccountTypeId() in ("receivable", "payable"):\n if account.getAccountTypeId() in ("receivable", "payable"):\n
# Test existence\n # Test existence\n
if third_party_path in (None, \'\'):\n if third_party is None:\n
raise ValidationFailed, N_("Action failed: no third party defined for line \'${line}\'."\n raise ValidationFailed, N_(\n
, mapping = {\'line\': transaction_line.getId()}\n "Action failed: no third party defined for line \'${line}\'.",\n
)\n mapping = {\'line\': transaction_line.getId()} )\n
if third_party not in (None, \'\') and third_party.getPortalType() in [\'Person\', \'Organisation\']:\n if third_party is not None and third_party.getPortalType() \\\n
# Test state\n in [\'Person\', \'Organisation\']:\n
# Test state :(\n
if third_party.getValidationState() != \'validated\':\n if third_party.getValidationState() != \'validated\':\n
raise ValidationFailed, N_("Action failed: third party \'${third_party_name}\' is not validated."\n raise ValidationFailed, N_(\n
, mapping = {\'third_party_name\': unicode(third_party.getTranslatedTitle(), \'utf8\')}\n "Action failed: third party \'${third_party_name}\' is not "\n
)\n "validated.",\n
mapping = {\'third_party_name\':\n
unicode(third_party.getTranslatedTitle(), \'utf8\')} )\n
# Test region\n # Test region\n
# Note: This test is normally handle by the entity workflow which don\'t allow validation of entity\n # Note: This test is normally handle by the entity workflow which\n
# until region is set. So if the previous condition is not verified, the previous test\n # don\'t allow validation of entity until region is set. So if the\n
# catch it. We add this redundent test for easy upgrade of previous ERP5 accounting system.\n # previous condition is not verified, the previous test catch it. We\n
if third_party.getRegion() in (None, \'\'):\n # add this redundent test for easy upgrade of previous ERP5\n
raise ValidationFailed, N_("Action failed: third party \'${third_party_name}\' has no region."\n # accounting system.\n
, mapping = {\'third_party_name\': unicode(third_party.getTranslatedTitle(), \'utf8\')}\n if not third_party.getRegion():\n
)\n raise ValidationFailed, N_(\n
\n "Action failed: third party \'${third_party_name}\' has no "\n
if (side == SOURCE) and account.isMemberOf("account_type/asset/cash/bank"):\n "region.",\n
if payment in (None, ""):\n mapping = {\'third_party_name\':\n
raise ValidationFailed, N_("Action failed: no bank account defined for line \'${line}\'."\n unicode(third_party.getTranslatedTitle(), \'utf8\')})\n
, mapping = {\'line\': transaction_line.getId()}\n
)\n
elif hasattr(payment, \'getPriceCurrency\') and \\\n
payment.getPriceCurrency() is not None and \\\n
payment.getPriceCurrency() != transaction_line.getResource():\n
raise ValidationFailed, N_("Action failed: bank account for line \'${line}\' "+\n
\'uses ${bank_account_currency} as default currency.\'\n
, mapping = { \'line\' : transaction_line.getId()\n
, \'bank_account_currency\': unicode(payment.getPriceCurrencyValue().getReference(), \'utf8\')\n
}\n
)\n
\n \n
if (side == SOURCE) and account.isMemberOf(\n
"account_type/asset/cash/bank"):\n
# XXX we must check for source only if we are intersted in the\n
# accounting for source. Today, payment transaction cannot be validated\n
# if they do not have a source, so this check is not needed yet.\n
if payment is None:\n
raise ValidationFailed, N_(\n
"Action failed: no source bank account defined for line \'${line}\'.",\n
mapping = {\'line\': transaction_line.getId()} )\n
else:\n
bank_account_currency = payment.getProperty(\'price_currency\')\n
if bank_account_currency is not None and \\\n
bank_account_currency != transaction_line.getResource():\n
raise ValidationFailed, N_(\n
"Action failed: source bank account for line \'${line}\' "\\\n
"uses ${bank_account_currency} as default currency.",\n
mapping = { \'line\' : transaction_line.getId(),\n
\'bank_account_currency\':\n
unicode(payment.getPriceCurrencyReference(), \'utf8\')})\n
\n
if (side == DESTINATION) and account.isMemberOf(\n
"account_type/asset/cash/bank"):\n
# we check account for destination section only if we are interested in\n
# the accounting for this entity.\n
if not check_for_destination:\n
continue\n
if payment is None:\n
raise ValidationFailed, N_(\n
"Action failed: no destination bank account defined for"\n
" line \'${line}\'.",\n
mapping = {\'line\': transaction_line.getId()} )\n
else:\n
bank_account_currency = payment.getProperty(\'price_currency\')\n
if bank_account_currency is not None and \\\n
bank_account_currency != transaction_line.getResource():\n
raise ValidationFailed, N_(\n
"Action failed: bank account for line \'${line}\' "\\\n
"uses ${bank_account_currency} as default currency.",\n
mapping = { \'line\' : transaction_line.getId(),\n
\'bank_account_currency\':\n
unicode(payment.getPriceCurrencyReference(), \'utf8\')})\n
\n
# TODO: should use currency precision instead of hardcoding 100 !\n
if int(source_sum*100) != 0:\n if int(source_sum*100) != 0:\n
raise ValidationFailed, N_(\'Action failed: transaction is not balanced for source section.\')\n raise ValidationFailed, N_(\n
\'Action failed: transaction is not balanced for source section.\')\n
\n \n
if int(destination_sum*100) != 0:\n if int(destination_sum*100) != 0:\n
raise ValidationFailed, N_(\'Action failed: transaction is not balanced for destination section.\')\n raise ValidationFailed, N_(\n
\'Action failed: 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>
...@@ -247,31 +297,34 @@ transaction.AccountingTransaction_deleteEmptyLines(redirect=0)\n ...@@ -247,31 +297,34 @@ 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>Products.ERP5Type.Message</string>
<string>Message</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>SOURCE</string> <string>SOURCE</string>
<string>DESTINATION</string> <string>DESTINATION</string>
<string>error_message</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>transaction</string> <string>transaction</string>
<string>_getattr_</string>
<string>N_</string> <string>N_</string>
<string>_getattr_</string>
<string>container</string> <string>container</string>
<string>source_section</string> <string>source_section</string>
<string>destination_section</string> <string>destination_section</string>
<string>check_for_destination</string>
<string>None</string>
<string>source_section_group</string>
<string>destination_section_group</string>
<string>source_sum</string> <string>source_sum</string>
<string>destination_sum</string> <string>destination_sum</string>
<string>accounting_transaction_line_list</string> <string>accounting_transaction_line_list</string>
<string>transaction_line</string> <string>transaction_line</string>
<string>source_quantity</string> <string>source_quantity</string>
<string>destination_quantity</string> <string>destination_quantity</string>
<string>None</string>
<string>side</string> <string>side</string>
<string>account</string> <string>account</string>
<string>payment</string> <string>payment</string>
<string>third_party_path</string>
<string>third_party</string> <string>third_party</string>
<string>unicode</string> <string>unicode</string>
<string>hasattr</string> <string>bank_account_currency</string>
<string>int</string> <string>int</string>
</tuple> </tuple>
</value> </value>
......
33 41
\ 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