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

accounting: Add an option to break down Trial Balance by entity (section_uid)

parent 72dfb2c4
...@@ -59,7 +59,6 @@ from ZTUtils import LazyFilter\n ...@@ -59,7 +59,6 @@ from ZTUtils import LazyFilter\n
request = container.REQUEST\n request = container.REQUEST\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
getInventoryList = portal.portal_simulation.getInventoryList\n getInventoryList = portal.portal_simulation.getInventoryList\n
getInventory = portal.portal_simulation.getInventoryAssetPrice\n
traverse = context.getPortalObject().restrictedTraverse\n traverse = context.getPortalObject().restrictedTraverse\n
getObject = context.getPortalObject().portal_catalog.getObject\n getObject = context.getPortalObject().portal_catalog.getObject\n
Base_translateString = portal.Base_translateString\n Base_translateString = portal.Base_translateString\n
...@@ -186,6 +185,19 @@ def getAnalyticTitleFromUid(uid):\n ...@@ -186,6 +185,19 @@ def getAnalyticTitleFromUid(uid):\n
title = \'%s - %s\' % (reference, title)\n title = \'%s - %s\' % (reference, title)\n
return analytic_title_dict.setdefault(uid, title)\n return analytic_title_dict.setdefault(uid, title)\n
\n \n
section_price_currency_dict = {None: \'\'}\n
def getSectionPriceCurrencyFromSectionUid(uid):\n
if uid is MARKER:\n
return \'\'\n
try:\n
return section_price_currency_dict[uid]\n
except KeyError:\n
section = getObject(uid)\n
price_currency = \'\'\n
if section is not None:\n
price_currency = section.getProperty(\'price_currency_reference\')\n
return section_price_currency_dict.setdefault(uid, price_currency)\n
\n
# standards accounts {{{\n # standards accounts {{{\n
for node in getInventoryList(\n for node in getInventoryList(\n
node_category_strict_membership=account_type_to_group_by_node,\n node_category_strict_membership=account_type_to_group_by_node,\n
...@@ -662,7 +674,6 @@ for key, data in line_per_account.items():\n ...@@ -662,7 +674,6 @@ for key, data in line_per_account.items():\n
total_final_balance_if_debit += round(max(closing_balance, 0), precision)\n total_final_balance_if_debit += round(max(closing_balance, 0), precision)\n
total_final_balance_if_credit += round(max(-closing_balance, 0) or 0, precision)\n total_final_balance_if_credit += round(max(-closing_balance, 0) or 0, precision)\n
\n \n
\n
line = Object(uid=\'new_\',\n line = Object(uid=\'new_\',\n
node_id=node_id,\n node_id=node_id,\n
node_title=node_title,\n node_title=node_title,\n
...@@ -682,11 +693,14 @@ for key, data in line_per_account.items():\n ...@@ -682,11 +693,14 @@ for key, data in line_per_account.items():\n
for analytic, uid in zip(group_analytic, analytic_key_list):\n for analytic, uid in zip(group_analytic, analytic_key_list):\n
title = getAnalyticTitleFromUid(uid)\n title = getAnalyticTitleFromUid(uid)\n
analytic_dict[analytic] = title\n analytic_dict[analytic] = title\n
if analytic == \'section_uid\':\n
analytic_dict[\'Movement_getSectionPriceCurrency\'] = getSectionPriceCurrencyFromSectionUid(uid)\n
# We sort on section title first\n
sort_key = (title, ) + sort_key\n
sort_key += (title, )\n sort_key += (title, )\n
\n \n
analytic_dict[\'sort_key\'] = sort_key\n analytic_dict[\'sort_key\'] = sort_key\n
line.update(analytic_dict)\n line.update(analytic_dict)\n
\n
line_list.append(line)\n line_list.append(line)\n
\n \n
\n \n
...@@ -756,7 +770,7 @@ for account_class in account_class_list:\n ...@@ -756,7 +770,7 @@ for account_class in account_class_list:\n
final_balance_if_debit += account.final_balance_if_debit\n final_balance_if_debit += account.final_balance_if_debit\n
final_balance_if_credit += account.final_balance_if_credit\n final_balance_if_credit += account.final_balance_if_credit\n
add_line(account)\n add_line(account)\n
\n \n
# summary\n # summary\n
add_line(Object(node_title=Base_translateString(\'Total for class ${account_class}\',\n add_line(Object(node_title=Base_translateString(\'Total for class ${account_class}\',\n
mapping=dict(account_class=account_class or \'???\')),\n mapping=dict(account_class=account_class or \'???\')),\n
......
...@@ -119,6 +119,9 @@ for analytic in group_analytic:\n ...@@ -119,6 +119,9 @@ for analytic in group_analytic:\n
extra_columns += ((\'funding_uid\',\n extra_columns += ((\'funding_uid\',\n
context.AccountingTransactionLine_getFundingBaseCategoryTitle()),)\n context.AccountingTransactionLine_getFundingBaseCategoryTitle()),)\n
group_analytic_uid += (\'funding_uid\',)\n group_analytic_uid += (\'funding_uid\',)\n
elif analytic == \'section\':\n
extra_columns += ((\'section_uid\', \'Section\'), (\'Movement_getSectionPriceCurrency\', \'Accounting Currency\'))\n
group_analytic_uid += (\'section_uid\',)\n
else:\n else:\n
for analytic_column in possible_analytic_column_list:\n for analytic_column in possible_analytic_column_list:\n
if analytic_column[0] == analytic:\n if analytic_column[0] == analytic:\n
......
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: [(context.Base_translateString(x[1]), x[0]) for x in context.AccountModule_getAnalyticColumnList()]</string> </value> <value> <string>python: [(context.Base_translateString(x[1]), x[0]) for x in (context.AccountModule_getAnalyticColumnList() + ((\'section\', \'Section\'), )) ]</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -2248,6 +2248,90 @@ class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase): ...@@ -2248,6 +2248,90 @@ class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase):
credit=3600, final_debit_balance=3600, final_credit_balance=3600, credit=3600, final_debit_balance=3600, final_credit_balance=3600,
final_balance_if_debit=3300, final_balance_if_credit=3300) final_balance_if_debit=3300, final_balance_if_credit=3300)
def testTrialBalanceMultipleSection(self):
account_module = self.portal.account_module
t1 = self._makeOne(
portal_type='Accounting Transaction',
title='Transaction 1',
source_reference='1',
simulation_state='delivered',
destination_section_value=self.organisation_module.client_1,
start_date=DateTime(2006, 2, 1),
lines=(dict(source_value=account_module.receivable,
source_debit=100.0),
dict(source_value=account_module.payable,
source_credit=100.0)))
t2 = self._makeOne(
portal_type='Accounting Transaction',
title='Transaction 2',
source_reference='2',
source_section_value=self.main_section,
simulation_state='delivered',
destination_section_value=self.organisation_module.client_1,
start_date=DateTime(2006, 2, 1, 0, 1),
lines=(dict(source_value=account_module.payable,
source_debit=200.0),
dict(source_value=account_module.receivable,
source_credit=200.0)))
# set request variables and render
request_form = self.portal.REQUEST.form
request_form['from_date'] = DateTime(2006, 1, 1)
request_form['at_date'] = DateTime(2006, 2, 2)
request_form['section_category'] = 'group/demo_group'
request_form['section_category_strict'] = False
request_form['simulation_state'] = ['delivered']
request_form['show_empty_accounts'] = 0
request_form['expand_accounts'] = 0
request_form['per_account_class_summary'] = 0
request_form['group_analytic'] = ["section"]
report_section_list = self.getReportSectionList(
self.portal.accounting_module,
'AccountModule_viewTrialBalanceReport')
self.assertEqual(1, len(report_section_list))
line_list = self.getListBoxLineList(report_section_list[0])
data_line_list = [l for l in line_list if l.isDataLine()]
self.assertEqual(['node_id', 'node_title',
'section_uid', 'Movement_getSectionPriceCurrency',
'initial_debit_balance', 'initial_credit_balance', 'debit',
'credit', 'final_debit_balance', 'final_credit_balance',
'final_balance_if_debit', 'final_balance_if_credit'],
data_line_list[0].column_id_list)
self.assertEqual(4, len(data_line_list))
self.checkLineProperties(data_line_list[0],
node_id='40', node_title='Payable',
section_uid='My Master Organisation', Movement_getSectionPriceCurrency='EUR',
initial_debit_balance=0, initial_credit_balance=0,
debit=200, credit=0, final_debit_balance=200, final_credit_balance=0,
final_balance_if_debit=200, final_balance_if_credit=0)
self.checkLineProperties(data_line_list[1],
node_id='41', node_title='Receivable',
section_uid='My Master Organisation', Movement_getSectionPriceCurrency='EUR',
initial_debit_balance=0, initial_credit_balance=0,
debit=0, credit=200, final_debit_balance=0, final_credit_balance=200,
final_balance_if_debit=0, final_balance_if_credit=200)
self.checkLineProperties(data_line_list[2],
node_id='40', node_title='Payable',
section_uid='My Organisation', Movement_getSectionPriceCurrency='EUR',
initial_debit_balance=0, initial_credit_balance=0,
debit=0, credit=100, final_debit_balance=0, final_credit_balance=100,
final_balance_if_debit=0, final_balance_if_credit=100)
self.checkLineProperties(data_line_list[3],
node_id='41', node_title='Receivable',
section_uid='My Organisation', Movement_getSectionPriceCurrency='EUR',
initial_debit_balance=0, initial_credit_balance=0,
debit=100, credit=0, final_debit_balance=100, final_credit_balance=0,
final_balance_if_debit=100, final_balance_if_credit=0)
self.assertTrue(line_list[-1].isStatLine())
self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
initial_debit_balance=0, initial_credit_balance=0, debit=300,
credit=300, final_debit_balance=300, final_credit_balance=300,
final_balance_if_debit=300, final_balance_if_credit=300)
def testTrialBalanceExpandAccounts(self): def testTrialBalanceExpandAccounts(self):
# Test of "expand accounts" feature of trial balance # Test of "expand accounts" feature of trial balance
......
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