Commit 68c37523 authored by Jérome Perrin's avatar Jérome Perrin

accounting: prevent user from creating balance transaction while previous one...

accounting: prevent user from creating balance transaction while previous one is still beeing reindexed
parent 35f4f631
...@@ -67,8 +67,8 @@ def roundCurrency(value, resource_relative_url):\n ...@@ -67,8 +67,8 @@ def roundCurrency(value, resource_relative_url):\n
qty_precision = precision_cache[resource_relative_url]\n qty_precision = precision_cache[resource_relative_url]\n
return round(value, qty_precision)\n return round(value, qty_precision)\n
\n \n
# This tag is checked in accounting period workflow\n
activity_tag = \'BalanceTransactionCreation\'\n activity_tag = \'BalanceTransactionCreation\'\n
activate_kw=dict(tag=activity_tag)\n
\n \n
at_date = context.getStopDate()\n at_date = context.getStopDate()\n
assert at_date\n assert at_date\n
...@@ -109,7 +109,7 @@ def getDependantSectionList(group, main_section):\n ...@@ -109,7 +109,7 @@ def getDependantSectionList(group, main_section):\n
section_list.extend(getDependantSectionList(subgroup, main_section))\n section_list.extend(getDependantSectionList(subgroup, main_section))\n
\n \n
return section_list\n return section_list\n
\n \n
group_value = section.getGroupValue()\n group_value = section.getGroupValue()\n
section_list = [section]\n section_list = [section]\n
if group_value is not None:\n if group_value is not None:\n
...@@ -117,7 +117,6 @@ if group_value is not None:\n ...@@ -117,7 +117,6 @@ if group_value is not None:\n
\n \n
def createBalanceTransaction(section):\n def createBalanceTransaction(section):\n
return portal.accounting_module.newContent(\n return portal.accounting_module.newContent(\n
activate_kw=activate_kw,\n
portal_type=\'Balance Transaction\',\n portal_type=\'Balance Transaction\',\n
start_date=(at_date + 1).earliestTime(),\n start_date=(at_date + 1).earliestTime(),\n
title=context.getTitle() or Base_translateString(\'Balance Transaction\'),\n title=context.getTitle() or Base_translateString(\'Balance Transaction\'),\n
...@@ -125,7 +124,8 @@ def createBalanceTransaction(section):\n ...@@ -125,7 +124,8 @@ def createBalanceTransaction(section):\n
resource=section_currency,\n resource=section_currency,\n
causality_value=context)\n causality_value=context)\n
\n \n
for section in section_list:\n with context.defaultActivateParameterDict({\'tag\': activity_tag}, placeless=True):\n
for section in section_list:\n
section_uid = section.getUid()\n section_uid = section.getUid()\n
balance_transaction = None\n balance_transaction = None\n
\n \n
...@@ -169,7 +169,7 @@ for section in section_list:\n ...@@ -169,7 +169,7 @@ for section in section_list:\n
node=profit_and_loss_account,\n node=profit_and_loss_account,\n
resource=section_currency,\n resource=section_currency,\n
**inventory_param_dict)\n **inventory_param_dict)\n
\n \n
section_currency_uid = context.getParentValue().getPriceCurrencyUid()\n section_currency_uid = context.getParentValue().getPriceCurrencyUid()\n
\n \n
profit_and_loss_quantity = 0\n profit_and_loss_quantity = 0\n
...@@ -180,24 +180,23 @@ for section in section_list:\n ...@@ -180,24 +180,23 @@ for section in section_list:\n
group_by_node=1,\n group_by_node=1,\n
group_by_resource=1,\n group_by_resource=1,\n
**inventory_param_dict):\n **inventory_param_dict):\n
\n \n
total_price = roundCurrency(inventory.total_price or 0, section_currency)\n total_price = roundCurrency(inventory.total_price or 0, section_currency)\n
quantity = roundCurrency(inventory.total_quantity or 0,\n quantity = roundCurrency(inventory.total_quantity or 0,\n
inventory.resource_relative_url)\n inventory.resource_relative_url)\n
\n \n
if not total_price and not quantity:\n if not total_price and not quantity:\n
continue\n continue\n
\n \n
line_count += 1\n line_count += 1\n
if inventory.resource_uid != section_currency_uid:\n if inventory.resource_uid != section_currency_uid:\n
profit_and_loss_quantity += total_price\n profit_and_loss_quantity += total_price\n
\n \n
if balance_transaction is None:\n if balance_transaction is None:\n
balance_transaction = createBalanceTransaction(section)\n balance_transaction = createBalanceTransaction(section)\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
activate_kw=activate_kw,\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
...@@ -208,7 +207,7 @@ for section in section_list:\n ...@@ -208,7 +207,7 @@ for section in section_list:\n
# consistency\n # consistency\n
raise ValueError(\'Different price: %s != %s \' % (\n raise ValueError(\'Different price: %s != %s \' % (\n
total_price, quantity))\n total_price, quantity))\n
\n \n
if inventory.node_relative_url != profit_and_loss_account:\n if inventory.node_relative_url != profit_and_loss_account:\n
profit_and_loss_quantity += total_price\n profit_and_loss_quantity += total_price\n
if balance_transaction is None:\n if balance_transaction is None:\n
...@@ -216,11 +215,10 @@ for section in section_list:\n ...@@ -216,11 +215,10 @@ for section in section_list:\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
activate_kw=activate_kw,\n
destination=inventory.node_relative_url,\n destination=inventory.node_relative_url,\n
quantity=total_price)\n quantity=total_price)\n
\n \n
\n \n
for inventory in getInventoryList(\n for inventory in getInventoryList(\n
node_category_strict_membership=group_by_mirror_section_node_category_list,\n node_category_strict_membership=group_by_mirror_section_node_category_list,\n
group_by_node=1,\n group_by_node=1,\n
...@@ -231,7 +229,7 @@ for section in section_list:\n ...@@ -231,7 +229,7 @@ for section in section_list:\n
total_price = roundCurrency(inventory.total_price or 0, section_currency)\n total_price = roundCurrency(inventory.total_price or 0, section_currency)\n
quantity = roundCurrency(inventory.total_quantity or 0,\n quantity = roundCurrency(inventory.total_quantity or 0,\n
inventory.resource_relative_url)\n inventory.resource_relative_url)\n
\n \n
if not total_price and not quantity:\n if not total_price and not quantity:\n
continue\n continue\n
profit_and_loss_quantity += total_price\n profit_and_loss_quantity += total_price\n
...@@ -243,7 +241,6 @@ for section in section_list:\n ...@@ -243,7 +241,6 @@ for section in section_list:\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
activate_kw=activate_kw,\n
destination=inventory.node_relative_url,\n destination=inventory.node_relative_url,\n
source_section_uid=inventory.mirror_section_uid,\n source_section_uid=inventory.mirror_section_uid,\n
resource=inventory.resource_relative_url,\n resource=inventory.resource_relative_url,\n
...@@ -258,7 +255,6 @@ for section in section_list:\n ...@@ -258,7 +255,6 @@ for section in section_list:\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
activate_kw=activate_kw,\n
destination=inventory.node_relative_url,\n destination=inventory.node_relative_url,\n
source_section_uid=inventory.mirror_section_uid,\n source_section_uid=inventory.mirror_section_uid,\n
quantity=total_price)\n quantity=total_price)\n
...@@ -274,11 +270,11 @@ for section in section_list:\n ...@@ -274,11 +270,11 @@ for section in section_list:\n
total_price = roundCurrency(inventory.total_price or 0, section_currency)\n total_price = roundCurrency(inventory.total_price or 0, section_currency)\n
quantity = roundCurrency(inventory.total_quantity or 0,\n quantity = roundCurrency(inventory.total_quantity or 0,\n
inventory.resource_relative_url)\n inventory.resource_relative_url)\n
\n \n
if not total_price and not quantity:\n if not total_price and not quantity:\n
continue\n continue\n
profit_and_loss_quantity += total_price\n profit_and_loss_quantity += total_price\n
\n \n
line_count += 1\n line_count += 1\n
\n \n
if inventory.resource_uid != section_currency_uid:\n if inventory.resource_uid != section_currency_uid:\n
...@@ -287,7 +283,6 @@ for section in section_list:\n ...@@ -287,7 +283,6 @@ for section in section_list:\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
activate_kw=activate_kw,\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
...@@ -302,14 +297,13 @@ for section in section_list:\n ...@@ -302,14 +297,13 @@ for section in section_list:\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
activate_kw=activate_kw,\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
if balance_transaction is None:\n if balance_transaction is None:\n
# we did not have any transaction for this section\n # we did not have any transaction for this section\n
\n \n
# One possible corner case is that we have only transactions that brings\n # One possible corner case is that we have only transactions that brings\n
# the balance of all balance sheets accounts to 0. In this case we want to\n # the balance of all balance sheets accounts to 0. In this case we want to\n
# create a balance transaction that notes that the current balance of profit\n # create a balance transaction that notes that the current balance of profit\n
...@@ -317,7 +311,6 @@ for section in section_list:\n ...@@ -317,7 +311,6 @@ for section in section_list:\n
if profit_and_loss_accounts_balance:\n if profit_and_loss_accounts_balance:\n
balance_transaction = createBalanceTransaction(section)\n balance_transaction = createBalanceTransaction(section)\n
balance_transaction.newContent(\n balance_transaction.newContent(\n
activate_kw=activate_kw,\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=0)\n quantity=0)\n
...@@ -328,11 +321,10 @@ for section in section_list:\n ...@@ -328,11 +321,10 @@ for section in section_list:\n
assert roundCurrency(profit_and_loss_accounts_balance, section_currency) == roundCurrency(\n assert roundCurrency(profit_and_loss_accounts_balance, section_currency) == roundCurrency(\n
- roundCurrency(selected_profit_and_loss_account_balance, section_currency)\n - roundCurrency(selected_profit_and_loss_account_balance, section_currency)\n
- roundCurrency(profit_and_loss_quantity, section_currency), section_currency)\n - roundCurrency(profit_and_loss_quantity, section_currency), section_currency)\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
activate_kw=activate_kw,\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
......
...@@ -60,6 +60,10 @@ portal = period.getPortalObject()\n ...@@ -60,6 +60,10 @@ portal = period.getPortalObject()\n
\n \n
period.Base_checkConsistency()\n period.Base_checkConsistency()\n
\n \n
# This tag is used in AccountingPeriod_createBalanceTransaction\n
if portal.portal_activities.countMessageWithTag(\'BalanceTransactionCreation\'):\n
raise ValidationFailed(translateString("Balance transaction creation already in progress. Please try again later."))\n
\n
valid_simulation_state_list = [\'cancelled\', \'delivered\', \'deleted\', \'rejected\']\n valid_simulation_state_list = [\'cancelled\', \'delivered\', \'deleted\', \'rejected\']\n
all_state_list = [x[1] for x in\n all_state_list = [x[1] for x in\n
portal.Base_getTranslatedWorkflowStateItemList(wf_id=\'accounting_workflow\')]\n portal.Base_getTranslatedWorkflowStateItemList(wf_id=\'accounting_workflow\')]\n
......
...@@ -2499,6 +2499,40 @@ class TestClosingPeriod(AccountingTestCase): ...@@ -2499,6 +2499,40 @@ class TestClosingPeriod(AccountingTestCase):
section_uid=self.section.getUid(), section_uid=self.section.getUid(),
node_uid=self.account_module.receivable.getUid())) node_uid=self.account_module.receivable.getUid()))
def test_ParrallelClosingRefused(self):
organisation_module = self.organisation_module
stool = self.portal.portal_simulation
period = self.section.newContent(portal_type='Accounting Period')
period.setStartDate(DateTime(2006, 1, 1))
period.setStopDate(DateTime(2006, 12, 31))
period.start()
period2 = self.section.newContent(portal_type='Accounting Period')
period2.setStartDate(DateTime(2007, 1, 1))
period2.setStopDate(DateTime(2007, 12, 31))
period2.start()
pl = self.portal.account_module.newContent(
portal_type='Account',
account_type='equity')
transaction1 = self._makeOne(
start_date=DateTime(2006, 1, 1),
destination_section_value=organisation_module.client_1,
portal_type='Sale Invoice Transaction',
simulation_state='delivered',
lines=(dict(source_value=self.account_module.goods_sales,
source_credit=100),
dict(source_value=self.account_module.receivable,
source_debit=100)))
self.portal.portal_workflow.doActionFor(
period, 'stop_action',
profit_and_loss_account=pl.getRelativeUrl())
self.assertRaises(ValidationFailed,
self.getPortal().portal_workflow.doActionFor,
period2, 'stop_action' )
class TestAccountingExport(AccountingTestCase): class TestAccountingExport(AccountingTestCase):
......
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