Commit 8e72ae12 authored by Jérome Perrin's avatar Jérome Perrin

Use organisation related to group mapping to check accounting periods and to...

Use organisation related to group mapping to check accounting periods and to check if it's the same group for grouping reference

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29408 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d658aad0
......@@ -67,18 +67,25 @@ assert context.getGroupingReference()\n
\n
if context.AccountingTransaction_isSourceView():\n
node_uid = context.getSourceUid()\n
section_uid = context.getSourceSectionUid()\n
section_category = None\n
section = context.getSourceSectionValue()\n
if section is not None:\n
section = section.Organisation_getMappingRelatedOrganisation()\n
section_category = section.getGroup(base=1)\n
mirror_section_uid = context.getDestinationSectionUid()\n
else:\n
node_uid = context.getDestinationUid()\n
section_uid = context.getDestinationSectionUid()\n
section = context.getDestinationSectionValue()\n
if section is not None:\n
section = section.Organisation_getMappingRelatedOrganisation()\n
section_category = section.getGroup(base=1)\n
mirror_section_uid = context.getSourceSectionUid()\n
\n
line_list = portal.portal_simulation.getMovementHistoryList(\n
portal_type=portal.getPortalAccountingMovementTypeList(),\n
grouping_reference=context.getGroupingReference(),\n
node_uid=node_uid,\n
section_uid=section_uid,\n
section_category=section_category,\n
mirror_section_uid=mirror_section_uid)\n
\n
# If the group is still valid, we may want to keep it as is.\n
......@@ -132,7 +139,9 @@ return line_list\n
<string>precision</string>
<string>AssertionError</string>
<string>node_uid</string>
<string>section_uid</string>
<string>None</string>
<string>section_category</string>
<string>section</string>
<string>mirror_section_uid</string>
<string>line_list</string>
<string>round</string>
......@@ -142,7 +151,6 @@ return line_list\n
<string>_getiter_</string>
<string>l</string>
<string>line</string>
<string>None</string>
</tuple>
</value>
</item>
......
......@@ -65,6 +65,7 @@ if not operation_date:\n
\n
section = context.getDestinationSectionValue(portal_type=\'Organisation\')\n
if section is not None:\n
section = section.Organisation_getMappingRelatedOrganisation()\n
for accounting_period in section.contentValues(\n
portal_type=\'Accounting Period\',\n
checked_permission=\'Access contents information\'):\n
......
......@@ -65,6 +65,7 @@ if not operation_date:\n
\n
section = context.getSourceSectionValue(portal_type=\'Organisation\')\n
if section is not None:\n
section = section.Organisation_getMappingRelatedOrganisation()\n
for accounting_period in section.contentValues(\n
portal_type=\'Accounting Period\',\n
checked_permission=\'Access contents information\'):\n
......
......@@ -101,16 +101,29 @@ else:\n
for line in accounting_transaction_line_value_list:\n
accounting_transaction = line.getParentValue()\n
if accounting_transaction.AccountingTransaction_isSourceView():\n
section_relative_url = None\n
source_section = line.getSourceSectionValue(portal_type=\'Organisation\')\n
if source_section is not None:\n
source_section = \\\n
source_section.Organisation_getMappingRelatedOrganisation()\n
section_relative_url = source_section.getRelativeUrl()\n
lines_per_node.setdefault(\n
(line.getSource(portal_type=\'Account\'),\n
line.getSourceSection(portal_type=\'Organisation\'),\n
section_relative_url,\n
line.getDestinationSection(), ), []).append(\n
dict(total_price=line.getSourceInventoriatedTotalAssetPrice() or 0,\n
path=line.getRelativeUrl()))\n
else:\n
section_relative_url = None\n
destination_section = line.getDestinationSectionValue(\n
portal_type=\'Organisation\')\n
if destination_section is not None:\n
destination_section = \\\n
destination_section.Organisation_getMappingRelatedOrganisation()\n
section_relative_url = destination_section.getRelativeUrl()\n
lines_per_node.setdefault(\n
(line.getDestination(portal_type=\'Account\'),\n
line.getDestinationSection(portal_type=\'Organisation\'),\n
section_relative_url,\n
line.getSourceSection(), ), []).append(\n
dict(total_price=line.getDestinationInventoriatedTotalAssetPrice() or 0,\n
path=line.getRelativeUrl()))\n
......@@ -195,7 +208,10 @@ return changed_lines\n
<string>append</string>
<string>$append0</string>
<string>uid</string>
<string>section_relative_url</string>
<string>source_section</string>
<string>dict</string>
<string>destination_section</string>
<string>changed_lines</string>
<string>node</string>
<string>section</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</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>_body</string> </key>
<value> <string>"""Returns the main organisation for that group.\n
"""\n
\n
def getOrganisationForSectionCategory(section):\n
mapping = section.getMappingRelatedValue(portal_type=\'Organisation\',\n
checked_permission=\'Access contents information\')\n
if mapping is not None:\n
return mapping\n
\n
organisation_list = section.getGroupRelatedValueList(portal_type=\'Organisation\',\n
strict_membership=1,\n
checked_permission=\'Access contents information\')\n
\n
for organisation in organisation_list:\n
if organisation.getProperty(\'validation_state\', \'unset\') not in (\'deleted\', \'cancelled\'):\n
return organisation\n
\n
\n
group = context.getGroupValue()\n
if group is None:\n
return context\n
\n
group_chain = []\n
while group.getPortalType() != \'Base Category\':\n
group_chain.append(group)\n
group = group.getParentValue()\n
\n
group_chain.reverse()\n
\n
for group in group_chain:\n
organisation = getOrganisationForSectionCategory(group)\n
if organisation is not None:\n
return organisation\n
\n
return context\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>getOrganisationForSectionCategory</string>
<string>_getattr_</string>
<string>context</string>
<string>group</string>
<string>None</string>
<string>group_chain</string>
<string>_getiter_</string>
<string>organisation</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Organisation_getMappingRelatedOrganisation</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -59,7 +59,6 @@
\n
XXX why proxy role ???\n
"""\n
\n
from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
from Products.ERP5Type.Message import translateString\n
\n
......@@ -124,26 +123,24 @@ if not skip_period_validation :\n
no_accounts = False\n
if no_accounts:\n
valid_date = True\n
transaction_date = transaction.getStartDate().earliestTime()\n
openned_accounting_period_list = source_section.searchFolder(\n
portal_type="Accounting Period",\n
# planned is for b/w compatibility\n
simulation_state=(\'planned\', \'started\'))\n
if not len(source_section.contentValues(\n
else:\n
section = transaction.getSourceSectionValue()\n
if section is not None and not len(section.contentValues(\n
filter=dict(portal_type="Accounting Period"))):\n
# if the entity doesn\'t have any accounting period, we can\n
# consider that they do not want to use accounting periods or\n
# we do not account from their side.\n
valid_date = True\n
for apd in openned_accounting_period_list:\n
apd = apd.getObject()\n
if apd.getStartDate().earliestTime() <= transaction_date <= \\\n
apd.getStopDate().latestTime():\n
valid_date = checkAccountingPeriodRecusivly(apd, transaction_date)\n
valid_date = True\n
else:\n
accounting_period = transaction\\\n
.AccountingTransaction_getAccountingPeriodForSourceSection()\n
transaction_date = transaction.getStartDate().earliestTime()\n
valid_date = False\n
if accounting_period is not None:\n
valid_date = checkAccountingPeriodRecusivly(accounting_period,\n
transaction_date)\n
\n
if not valid_date:\n
raise ValidationFailed(translateString("Date is not in a started Accounting Period "\n
"for source section."))\n
\n
# do the same for destination section \n
if destination_section is not None:\n
# if we don\'t have any accounts on this side, we don\'t enforce date checks\n
......@@ -154,18 +151,19 @@ if not skip_period_validation :\n
no_accounts = False\n
if no_accounts:\n
valid_date = True\n
transaction_date = transaction.getStopDate().earliestTime()\n
openned_accounting_period_list = destination_section.searchFolder(\n
portal_type = "Accounting Period",\n
simulation_state=(\'planned\', \'started\'))\n
if not len(destination_section.contentValues(\n
else:\n
section = transaction.getDestinationSectionValue()\n
if section is not None and not len(section.contentValues(\n
filter=dict(portal_type="Accounting Period"))):\n
valid_date = True\n
for apd in openned_accounting_period_list:\n
apd = apd.getObject()\n
if apd.getStartDate().earliestTime() <= transaction_date <= \\\n
apd.getStopDate().latestTime():\n
valid_date = checkAccountingPeriodRecusivly(apd, transaction_date)\n
valid_date = True\n
else:\n
accounting_period = transaction\\\n
.AccountingTransaction_getAccountingPeriodForDestinationSection()\n
transaction_date = transaction.getStopDate().earliestTime()\n
valid_date = False\n
if accounting_period is not None:\n
valid_date = checkAccountingPeriodRecusivly(accounting_period,\n
transaction_date)\n
\n
if not valid_date:\n
raise ValidationFailed(translateString("Date is not in a started Accounting Period "\n
......@@ -247,11 +245,11 @@ if not skip_period_validation :\n
<string>no_accounts</string>
<string>_getiter_</string>
<string>line</string>
<string>transaction_date</string>
<string>openned_accounting_period_list</string>
<string>section</string>
<string>len</string>
<string>dict</string>
<string>apd</string>
<string>accounting_period</string>
<string>transaction_date</string>
</tuple>
</value>
</item>
......
974
\ No newline at end of file
978
\ 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