Commit 2ee5f8f4 authored by Jérome Perrin's avatar Jérome Perrin

accounting: fix wrong amount on GL when selecting parents node_category

When running General Ledger with some node categories that will select
the same accounts more than once, the balance of these accounts were
counted more than once.

fixes #20170313-7F7FA8
parent bad19050
......@@ -206,13 +206,17 @@ account_type_to_group_by_node = [at for at in balance_sheet_account_type_list
if gap_list or gap_root:
params['node_category'] = gap_list or gap_root
default_selection_params['node_category'] = gap_list or gap_root
if mirror_section_category_list:
params['mirror_section_category'] = mirror_section_category_list
default_selection_params['mirror_section_category'] =\
mirror_section_category_list
# inventory parameters for the total section
total_params = default_selection_params.copy()
# we'll append all the node used, instead of using node_category.
total_params['node_uid'] = set([])
report_section_list = []
existing_section_dict = {}
......@@ -241,6 +245,7 @@ for inventory in portal.portal_simulation.getInventoryList(
addReportSection(path=inventory.node_relative_url,
selection_params=selection_params,
title=getFullAccountName(key))
total_params['node_uid'].add(inventory.node_uid)
# non zero balance at begining of period
for inventory in portal.portal_simulation.getInventoryList(
......@@ -268,6 +273,7 @@ for inventory in portal.portal_simulation.getInventoryList(
addReportSection(path=inventory.node_relative_url,
selection_params=selection_params,
title=getFullAccountName(key))
total_params['node_uid'].add(inventory.node_uid)
# profit & loss -> same, but from date limited to the current period
......@@ -292,6 +298,7 @@ for inventory in portal.portal_simulation.getInventoryList(
addReportSection(path=inventory.node_relative_url,
selection_params=selection_params,
title=getFullAccountName(key))
total_params['node_uid'].add(inventory.node_uid)
# group by mirror_section
# movements in the period
......@@ -317,6 +324,7 @@ for inventory in portal.portal_simulation.getInventoryList(
addReportSection(path=inventory.node_relative_url,
selection_params=selection_params,
title=getFullAccountName(key))
total_params['node_uid'].add(inventory.node_uid)
# non zero balance at begining of period
for inventory in portal.portal_simulation.getInventoryList(
......@@ -345,6 +353,7 @@ for inventory in portal.portal_simulation.getInventoryList(
addReportSection(path=inventory.node_relative_url,
selection_params=selection_params,
title=getFullAccountName(key))
total_params['node_uid'].add(inventory.node_uid)
# group by payment
# movements in the period
......@@ -370,6 +379,7 @@ for inventory in portal.portal_simulation.getInventoryList(
addReportSection(path=inventory.node_relative_url,
selection_params=selection_params,
title=getFullAccountName(key))
total_params['node_uid'].add(inventory.node_uid)
# non zero balance at begining of period
for inventory in portal.portal_simulation.getInventoryList(
......@@ -397,13 +407,14 @@ for inventory in portal.portal_simulation.getInventoryList(
addReportSection(path=inventory.node_relative_url,
selection_params=selection_params,
title=getFullAccountName(key))
total_params['node_uid'].add(inventory.node_uid)
report_section_list = [x[1] for x in sorted(report_section_list, key=lambda x: x[0])]
if not export:
total_params = default_selection_params.copy()
total_params['at_date'] = at_date
total_params['node_uid'] = list(total_params['node_uid'])
report_section_list.append(ReportSection(
path=context.getPhysicalPath(),
title=Base_translateString("Total"),
......
......@@ -23,17 +23,17 @@ if mirror_section_uid:
if ledger_uid:
inventory_kw['ledger_uid'] = ledger_uid
if node_category:
# XXX if node category is passed, income or balance accounts are not
if node_uid:
# XXX if node uid is passed, income or balance accounts are not
# calculated differently. As a result, the summary doesn't take from_date
# into account for income accounts.
return [Object(
debit_price=getInventoryAssetPrice(omit_asset_decrease=1,
node_category=node_category,
node_uid=node_uid,
precision=precision,
**inventory_kw),
credit_price=-getInventoryAssetPrice(omit_asset_increase=1,
node_category=node_category,
node_uid=node_uid,
precision=precision,
**inventory_kw) or 0 ) ]
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>section_uid, simulation_state, at_date, period_start_date, precision, node_category=None, function_category=None, function_uid=None, funding_category=None, funding_uid=None, project_uid=None, ledger_uid=None, from_date=\'ignored\', mirror_section_category=None, mirror_section_uid=None, **kw</string> </value>
<value> <string>section_uid, simulation_state, at_date, period_start_date, precision, node_uid=None, function_category=None, function_uid=None, funding_category=None, funding_uid=None, project_uid=None, ledger_uid=None, from_date=\'ignored\', mirror_section_category=None, mirror_section_uid=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -4181,6 +4181,74 @@ class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase):
self.assertEqual(1, len(data_line_list))
self.checkLineProperties(data_line_list[0], debit_price=200, credit_price=100)
def testGeneralLedgerGAPFilterSameGAPSelectedTwice(self):
# General Ledger filtered by GAP category. Edge case: selecting
# a gap and its parent. This use to double the amount because
# node is twice member of node_category
# we will use the same data set as account statement
self.createAccountStatementDataSetOnTwoPeriods()
# set request variables and render
request_form = self.portal.REQUEST.form
request_form['from_date'] = DateTime(2006, 2, 1)
request_form['at_date'] = DateTime(2006, 12, 31)
# Here we select 4 and 41
request_form['gap_list'] = [
'my_country/my_accounting_standards/4',
'my_country/my_accounting_standards/4/41']
request_form['section_category'] = 'group/demo_group'
request_form['section_category_strict'] = False
request_form['simulation_state'] = ['delivered']
request_form['hide_analytic'] = False
request_form['export'] = False
report_section_list = self.getReportSectionList(
self.portal.accounting_module,
'AccountModule_viewGeneralLedgerReport')
self.assertEqual(2, len(report_section_list))
self.assertEqual(
'41 - Receivable (Client 1)',
report_section_list[0].getTitle())
line_list = self.getListBoxLineList(report_section_list[0])
data_line_list = [l for l in line_list if l.isDataLine()]
self.assertEqual(2, len(data_line_list))
self.checkLineProperties(
data_line_list[0],
Movement_getSpecificReference='Previous Balance',
date=DateTime(2006, 2, 1),
debit_price=300,
credit_price=0,
running_total_price=300, )
self.checkLineProperties(
data_line_list[1],
Movement_getSpecificReference='3',
Movement_getExplanationTitleAndAnalytics='Transaction 3\nref3',
date=DateTime(2006, 2, 2),
debit_price=300,
credit_price=0,
running_total_price=600, )
self.assertTrue(line_list[-1].isStatLine())
self.checkLineProperties(line_list[-1],
Movement_getSpecificReference=None,
Movement_getExplanationTitleAndAnalytics=None,
date=None,
debit_price=600, credit_price=0, )
self.assertEqual('Total', report_section_list[1].getTitle())
line_list = self.getListBoxLineList(report_section_list[1])
data_line_list = [l for l in line_list if l.isDataLine()]
self.assertEqual(1, len(data_line_list))
self.checkLineProperties(
data_line_list[0],
debit_price=600,
credit_price=0)
def testGeneralLedgerFunction(self):
# general ledger restricted to a function
self.createProjectAndFunctionDataSet()
......
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