Commit 3e874abb authored by Jérome Perrin's avatar Jérome Perrin

Support multiple sections properly in accounting periods.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31059 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5f6dd24d
...@@ -76,179 +76,186 @@ at_date = context.getStopDate()\n ...@@ -76,179 +76,186 @@ at_date = context.getStopDate()\n
assert at_date\n assert at_date\n
\n \n
section = context.getParentValue()\n section = context.getParentValue()\n
section_uid = context.getParentUid()\n
section_currency = section.getPriceCurrency()\n section_currency = section.getPriceCurrency()\n
section_currency_precision = section.getPriceCurrencyValue().getQuantityPrecision()\n section_currency_precision = section.getPriceCurrencyValue().getQuantityPrecision()\n
section_category = section.getGroup(base=True)\n
\n \n
balance_transaction = portal.accounting_module.newContent(\n # we use Base_getSectionUidListForSectionCategory as the only API to get the\n
activate_kw=dict(tag=activity_tag),\n # organisation member of that "accounting entity"\n
portal_type=\'Balance Transaction\',\n for section_uid in \\\n
start_date=(at_date + 1).earliestTime(),\n portal.Base_getSectionUidListForSectionCategory(section_category):\n
title=context.getTitle() or Base_translateString(\'Balance Transaction\'),\n \n
destination_section_value=section,\n section = portal.portal_catalog.getObject(uid=section_uid)\n
resource=section_currency,\n
causality_value=context)\n
\n \n
group_by_node_node_category_list = []\n balance_transaction = portal.accounting_module.newContent(\n
group_by_mirror_section_node_category_list = []\n activate_kw=dict(tag=activity_tag),\n
group_by_payment_node_category_list = []\n portal_type=\'Balance Transaction\',\n
profit_and_loss_node_category_list = []\n start_date=(at_date + 1).earliestTime(),\n
title=context.getTitle() or Base_translateString(\'Balance Transaction\'),\n
destination_section_value=section,\n
resource=section_currency,\n
causality_value=context)\n
\n \n
node_category_list = portal.portal_categories\\\n group_by_node_node_category_list = []\n
.account_type.getCategoryChildValueList()\n group_by_mirror_section_node_category_list = []\n
for node_category in node_category_list:\n group_by_payment_node_category_list = []\n
node_category_url = node_category.getRelativeUrl()\n profit_and_loss_node_category_list = []\n
if node_category_url in (\n
\'account_type/asset/cash/bank\',):\n
group_by_payment_node_category_list.append(node_category_url)\n
elif node_category_url in (\n
\'account_type/asset/receivable\',\n
\'account_type/liability/payable\'):\n
group_by_mirror_section_node_category_list.append(node_category_url)\n
elif node_category_url in (\'account_type/income\', \'account_type/expense\'):\n
profit_and_loss_node_category_list.append(node_category_url)\n
else:\n
group_by_node_node_category_list.append(node_category_url)\n
\n \n
getInventoryList = portal.portal_simulation.getInventoryList\n node_category_list = portal.portal_categories\\\n
.account_type.getCategoryChildValueList()\n
for node_category in node_category_list:\n
node_category_url = node_category.getRelativeUrl()\n
if node_category_url in (\n
\'account_type/asset/cash/bank\',):\n
group_by_payment_node_category_list.append(node_category_url)\n
elif node_category_url in (\n
\'account_type/asset/receivable\',\n
\'account_type/liability/payable\'):\n
group_by_mirror_section_node_category_list.append(node_category_url)\n
elif node_category_url in (\'account_type/income\', \'account_type/expense\'):\n
profit_and_loss_node_category_list.append(node_category_url)\n
else:\n
group_by_node_node_category_list.append(node_category_url)\n
\n \n
inventory_param_dict = dict(section_uid=section_uid,\n getInventoryList = portal.portal_simulation.getInventoryList\n
simulation_state=(\'delivered\',),\n
precision=section_currency_precision,\n
portal_type=portal.getPortalAccountingMovementTypeList(),\n
at_date=at_date.latestTime(),)\n
\n
section_currency_uid = context.getParentValue().getPriceCurrencyUid()\n
\n \n
profit_and_loss_quantity = 0\n inventory_param_dict = dict(section_uid=section_uid,\n
line_count = 0\n simulation_state=(\'delivered\',),\n
precision=section_currency_precision,\n
portal_type=portal.getPortalAccountingMovementTypeList(),\n
at_date=at_date.latestTime(),)\n
\n
section_currency_uid = context.getParentValue().getPriceCurrencyUid()\n
\n \n
for inventory in getInventoryList(\n profit_and_loss_quantity = 0\n
node_category_strict_membership=group_by_node_node_category_list,\n line_count = 0\n
group_by_node=1,\n \n
group_by_resource=1,\n for inventory in getInventoryList(\n
**inventory_param_dict):\n node_category_strict_membership=group_by_node_node_category_list,\n
\n group_by_node=1,\n
total_price = roundCurrency(inventory.total_price or 0, section_currency)\n group_by_resource=1,\n
quantity = roundCurrency(inventory.total_quantity or 0,\n **inventory_param_dict):\n
inventory.resource_relative_url)\n \n
\n total_price = roundCurrency(inventory.total_price or 0, section_currency)\n
if not total_price and not quantity:\n quantity = roundCurrency(inventory.total_quantity or 0,\n
continue\n inventory.resource_relative_url)\n
\n \n
line_count += 1\n if not total_price and not quantity:\n
if inventory.resource_uid != section_currency_uid:\n continue\n
if inventory.node_relative_url == profit_and_loss_account:\n \n
raise ValueError(\'Using multiple currencies on profit and loss account \'\n line_count += 1\n
\'is not supported\')\n if inventory.resource_uid != section_currency_uid:\n
if inventory.node_relative_url == profit_and_loss_account:\n
raise ValueError(\'Using multiple currencies on profit and loss account \'\n
\'is not supported\')\n
profit_and_loss_quantity += total_price\n
balance_transaction.newContent(\n
id=\'%03d\' % line_count,\n
portal_type=\'Balance Transaction Line\',\n
destination=inventory.node_relative_url,\n
resource=inventory.resource_relative_url,\n
quantity=quantity,\n
destination_total_asset_price=total_price)\n
else:\n
if total_price != quantity:\n
# If this fail for you, your accounting doesn\'t use currencies with\n
# consistency\n
raise ValueError(\'Different price: %s != %s \' % (\n
total_price, quantity))\n
\n
if inventory.node_relative_url != profit_and_loss_account:\n
profit_and_loss_quantity += total_price\n
balance_transaction.newContent(\n
id=\'%03d\' % line_count,\n
portal_type=\'Balance Transaction Line\',\n
destination=inventory.node_relative_url,\n
quantity=total_price)\n
\n
\n
for inventory in getInventoryList(\n
node_category_strict_membership=group_by_mirror_section_node_category_list,\n
group_by_node=1,\n
group_by_mirror_section=1,\n
group_by_resource=1,\n
**inventory_param_dict):\n
\n
total_price = roundCurrency(inventory.total_price or 0, section_currency)\n
quantity = roundCurrency(inventory.total_quantity or 0,\n
inventory.resource_relative_url)\n
\n
if not total_price and not quantity:\n
continue\n
profit_and_loss_quantity += total_price\n profit_and_loss_quantity += total_price\n
balance_transaction.newContent(\n line_count += 1\n
\n
if inventory.resource_uid != section_currency_uid:\n
balance_transaction.newContent(\n
id=\'%03d\' % line_count,\n id=\'%03d\' % line_count,\n
portal_type=\'Balance Transaction Line\',\n portal_type=\'Balance Transaction Line\',\n
destination=inventory.node_relative_url,\n destination=inventory.node_relative_url,\n
source_section_uid=inventory.mirror_section_uid,\n
resource=inventory.resource_relative_url,\n resource=inventory.resource_relative_url,\n
quantity=quantity,\n quantity=quantity,\n
destination_total_asset_price=total_price)\n destination_total_asset_price=total_price)\n
else:\n else:\n
if total_price != quantity:\n if total_price != quantity:\n
# If this fail for you, your accounting doesn\'t use currencies with\n raise ValueError(\'Different price: %s != %s \' % (\n
# consistency\n total_price, quantity))\n
raise ValueError(\'Different price: %s != %s \' % (\n
total_price, quantity))\n
\n
if inventory.node_relative_url != profit_and_loss_account:\n
profit_and_loss_quantity += total_price\n
balance_transaction.newContent(\n balance_transaction.newContent(\n
id=\'%03d\' % line_count,\n id=\'%03d\' % line_count,\n
portal_type=\'Balance Transaction Line\',\n portal_type=\'Balance Transaction Line\',\n
destination=inventory.node_relative_url,\n destination=inventory.node_relative_url,\n
source_section_uid=inventory.mirror_section_uid,\n
quantity=total_price)\n quantity=total_price)\n
\n \n
\n
for inventory in getInventoryList(\n
node_category_strict_membership=group_by_mirror_section_node_category_list,\n
group_by_node=1,\n
group_by_mirror_section=1,\n
group_by_resource=1,\n
**inventory_param_dict):\n
\n
total_price = roundCurrency(inventory.total_price or 0, section_currency)\n
quantity = roundCurrency(inventory.total_quantity or 0,\n
inventory.resource_relative_url)\n
\n
if not total_price and not quantity:\n
continue\n
profit_and_loss_quantity += total_price\n
line_count += 1\n
\n
if inventory.resource_uid != section_currency_uid:\n
balance_transaction.newContent(\n
id=\'%03d\' % line_count,\n
portal_type=\'Balance Transaction Line\',\n
destination=inventory.node_relative_url,\n
source_section_uid=inventory.mirror_section_uid,\n
resource=inventory.resource_relative_url,\n
quantity=quantity,\n
destination_total_asset_price=total_price)\n
else:\n
if total_price != quantity:\n
raise ValueError(\'Different price: %s != %s \' % (\n
total_price, quantity))\n
balance_transaction.newContent(\n
id=\'%03d\' % line_count,\n
portal_type=\'Balance Transaction Line\',\n
destination=inventory.node_relative_url,\n
source_section_uid=inventory.mirror_section_uid,\n
quantity=total_price)\n
\n \n
for inventory in getInventoryList(\n
node_category_strict_membership=group_by_payment_node_category_list,\n
group_by_node=1,\n
group_by_payment=1,\n
group_by_resource=1,\n
**inventory_param_dict):\n
\n \n
for inventory in getInventoryList(\n total_price = roundCurrency(inventory.total_price or 0, section_currency)\n
node_category_strict_membership=group_by_payment_node_category_list,\n quantity = roundCurrency(inventory.total_quantity or 0,\n
group_by_node=1,\n inventory.resource_relative_url)\n
group_by_payment=1,\n \n
group_by_resource=1,\n if not total_price and not quantity:\n
**inventory_param_dict):\n continue\n
\n profit_and_loss_quantity += total_price\n
total_price = roundCurrency(inventory.total_price or 0, section_currency)\n \n
quantity = roundCurrency(inventory.total_quantity or 0,\n line_count += 1\n
inventory.resource_relative_url)\n
\n
if not total_price and not quantity:\n
continue\n
profit_and_loss_quantity += total_price\n
\n
line_count += 1\n
\n \n
if inventory.resource_uid != section_currency_uid:\n if inventory.resource_uid != section_currency_uid:\n
balance_transaction.newContent(\n balance_transaction.newContent(\n
id=\'%03d\' % line_count,\n id=\'%03d\' % line_count,\n
portal_type=\'Balance Transaction Line\',\n portal_type=\'Balance Transaction Line\',\n
destination=inventory.node_relative_url,\n destination=inventory.node_relative_url,\n
resource=inventory.resource_relative_url,\n resource=inventory.resource_relative_url,\n
quantity=quantity,\n quantity=quantity,\n
destination_payment_uid=inventory.payment_uid,\n destination_payment_uid=inventory.payment_uid,\n
destination_total_asset_price=total_price)\n destination_total_asset_price=total_price)\n
else:\n else:\n
if total_price != quantity:\n if total_price != quantity:\n
raise ValueError(\'Different price: %s != %s \' % (\n raise ValueError(\'Different price: %s != %s \' % (\n
total_price, quantity))\n total_price, quantity))\n
balance_transaction.newContent(\n balance_transaction.newContent(\n
id=\'%03d\' % line_count,\n id=\'%03d\' % line_count,\n
portal_type=\'Balance Transaction Line\',\n portal_type=\'Balance Transaction Line\',\n
destination=inventory.node_relative_url,\n destination=inventory.node_relative_url,\n
destination_payment_uid=inventory.payment_uid,\n destination_payment_uid=inventory.payment_uid,\n
quantity=total_price)\n quantity=total_price)\n
\n \n
# add a final line for p&l\n # add a final line for p&l\n
balance_transaction.newContent(\n balance_transaction.newContent(\n
id=\'%03d\' % (line_count + 1),\n id=\'%03d\' % (line_count + 1),\n
portal_type=\'Balance Transaction Line\',\n portal_type=\'Balance Transaction Line\',\n
destination=profit_and_loss_account,\n destination=profit_and_loss_account,\n
quantity=-profit_and_loss_quantity)\n quantity=-profit_and_loss_quantity)\n
\n \n
# and go to delivered state directly (the user is not supposed to edit this document)\n # and go to delivered state directly (the user is not supposed to edit this document)\n
balance_transaction.stop()\n balance_transaction.stop()\n
balance_transaction.deliver()\n balance_transaction.deliver()\n
\n \n
# make sure this Accounting Period has an activity pending during the indexing\n # make sure this Accounting Period has an activity pending during the indexing\n
# of the balance transaction.\n # of the balance transaction.\n
...@@ -303,16 +310,18 @@ context.activate(after_tag=activity_tag).getTitle()\n ...@@ -303,16 +310,18 @@ context.activate(after_tag=activity_tag).getTitle()\n
<string>at_date</string> <string>at_date</string>
<string>AssertionError</string> <string>AssertionError</string>
<string>section</string> <string>section</string>
<string>section_uid</string>
<string>section_currency</string> <string>section_currency</string>
<string>section_currency_precision</string> <string>section_currency_precision</string>
<string>True</string>
<string>section_category</string>
<string>_getiter_</string>
<string>section_uid</string>
<string>balance_transaction</string> <string>balance_transaction</string>
<string>group_by_node_node_category_list</string> <string>group_by_node_node_category_list</string>
<string>group_by_mirror_section_node_category_list</string> <string>group_by_mirror_section_node_category_list</string>
<string>group_by_payment_node_category_list</string> <string>group_by_payment_node_category_list</string>
<string>profit_and_loss_node_category_list</string> <string>profit_and_loss_node_category_list</string>
<string>node_category_list</string> <string>node_category_list</string>
<string>_getiter_</string>
<string>node_category</string> <string>node_category</string>
<string>node_category_url</string> <string>node_category_url</string>
<string>getInventoryList</string> <string>getInventoryList</string>
......
...@@ -69,12 +69,19 @@ section = period.getParentValue()\n ...@@ -69,12 +69,19 @@ section = period.getParentValue()\n
while section.getPortalType() == period.getPortalType():\n while section.getPortalType() == period.getPortalType():\n
section = section.getParentValue()\n section = section.getParentValue()\n
\n \n
section_category = section.getGroup(base=True)\n
if not section_category:\n
raise ValidationFailed, translateString("This Organisation must be member of a Group")\n
\n
section_uid = portal.Base_getSectionUidListForSectionCategory(section_category)\n
\n
movement_list = portal.portal_simulation.getMovementHistoryList(\n movement_list = portal.portal_simulation.getMovementHistoryList(\n
section_uid=section.getUid(),\n section_uid=section_uid,\n
from_date=period.getStartDate().earliestTime(),\n from_date=period.getStartDate().earliestTime(),\n
at_date=period.getStopDate().latestTime(),\n at_date=period.getStopDate().latestTime(),\n
simulation_state=invalid_simulation_state_list,\n simulation_state=invalid_simulation_state_list,\n
portal_type=portal.getPortalAccountingMovementTypeList(),)\n portal_type=portal.getPortalAccountingMovementTypeList(),\n
limit=1)\n
\n \n
if movement_list:\n if movement_list:\n
raise ValidationFailed, translateString(\n raise ValidationFailed, translateString(\n
...@@ -133,6 +140,9 @@ if movement_list:\n ...@@ -133,6 +140,9 @@ if movement_list:\n
<string>state</string> <string>state</string>
<string>invalid_simulation_state_list</string> <string>invalid_simulation_state_list</string>
<string>section</string> <string>section</string>
<string>True</string>
<string>section_category</string>
<string>section_uid</string>
<string>movement_list</string> <string>movement_list</string>
</tuple> </tuple>
</value> </value>
......
1071 1073
\ 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