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
assert at_date\n
\n
section = context.getParentValue()\n
section_uid = context.getParentUid()\n
section_currency = section.getPriceCurrency()\n
section_currency_precision = section.getPriceCurrencyValue().getQuantityPrecision()\n
section_category = section.getGroup(base=True)\n
\n
balance_transaction = portal.accounting_module.newContent(\n
activate_kw=dict(tag=activity_tag),\n
portal_type=\'Balance Transaction\',\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
# we use Base_getSectionUidListForSectionCategory as the only API to get the\n
# organisation member of that "accounting entity"\n
for section_uid in \\\n
portal.Base_getSectionUidListForSectionCategory(section_category):\n
\n
section = portal.portal_catalog.getObject(uid=section_uid)\n
\n
group_by_node_node_category_list = []\n
group_by_mirror_section_node_category_list = []\n
group_by_payment_node_category_list = []\n
profit_and_loss_node_category_list = []\n
balance_transaction = portal.accounting_module.newContent(\n
activate_kw=dict(tag=activity_tag),\n
portal_type=\'Balance Transaction\',\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
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
group_by_node_node_category_list = []\n
group_by_mirror_section_node_category_list = []\n
group_by_payment_node_category_list = []\n
profit_and_loss_node_category_list = []\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
inventory_param_dict = dict(section_uid=section_uid,\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
getInventoryList = portal.portal_simulation.getInventoryList\n
\n
profit_and_loss_quantity = 0\n
line_count = 0\n
inventory_param_dict = dict(section_uid=section_uid,\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
for inventory in getInventoryList(\n
node_category_strict_membership=group_by_node_node_category_list,\n
group_by_node=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
\n
line_count += 1\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 = 0\n
line_count = 0\n
\n
for inventory in getInventoryList(\n
node_category_strict_membership=group_by_node_node_category_list,\n
group_by_node=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
\n
line_count += 1\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
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
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
# 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
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_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
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
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
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
\n
line_count += 1\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
\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
resource=inventory.resource_relative_url,\n
quantity=quantity,\n
destination_payment_uid=inventory.payment_uid,\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
destination_payment_uid=inventory.payment_uid,\n
quantity=total_price)\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
resource=inventory.resource_relative_url,\n
quantity=quantity,\n
destination_payment_uid=inventory.payment_uid,\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
destination_payment_uid=inventory.payment_uid,\n
quantity=total_price)\n
\n
# add a final line for p&l\n
balance_transaction.newContent(\n
id=\'%03d\' % (line_count + 1),\n
portal_type=\'Balance Transaction Line\',\n
destination=profit_and_loss_account,\n
quantity=-profit_and_loss_quantity)\n
# add a final line for p&l\n
balance_transaction.newContent(\n
id=\'%03d\' % (line_count + 1),\n
portal_type=\'Balance Transaction Line\',\n
destination=profit_and_loss_account,\n
quantity=-profit_and_loss_quantity)\n
\n
# and go to delivered state directly (the user is not supposed to edit this document)\n
balance_transaction.stop()\n
balance_transaction.deliver()\n
# and go to delivered state directly (the user is not supposed to edit this document)\n
balance_transaction.stop()\n
balance_transaction.deliver()\n
\n
# make sure this Accounting Period has an activity pending during the indexing\n
# of the balance transaction.\n
......@@ -303,16 +310,18 @@ context.activate(after_tag=activity_tag).getTitle()\n
<string>at_date</string>
<string>AssertionError</string>
<string>section</string>
<string>section_uid</string>
<string>section_currency</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>group_by_node_node_category_list</string>
<string>group_by_mirror_section_node_category_list</string>
<string>group_by_payment_node_category_list</string>
<string>profit_and_loss_node_category_list</string>
<string>node_category_list</string>
<string>_getiter_</string>
<string>node_category</string>
<string>node_category_url</string>
<string>getInventoryList</string>
......
......@@ -69,12 +69,19 @@ section = period.getParentValue()\n
while section.getPortalType() == period.getPortalType():\n
section = section.getParentValue()\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
section_uid=section.getUid(),\n
section_uid=section_uid,\n
from_date=period.getStartDate().earliestTime(),\n
at_date=period.getStopDate().latestTime(),\n
simulation_state=invalid_simulation_state_list,\n
portal_type=portal.getPortalAccountingMovementTypeList(),)\n
portal_type=portal.getPortalAccountingMovementTypeList(),\n
limit=1)\n
\n
if movement_list:\n
raise ValidationFailed, translateString(\n
......@@ -133,6 +140,9 @@ if movement_list:\n
<string>state</string>
<string>invalid_simulation_state_list</string>
<string>section</string>
<string>True</string>
<string>section_category</string>
<string>section_uid</string>
<string>movement_list</string>
</tuple>
</value>
......
1071
\ No newline at end of file
1073
\ 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