Commit 6eda00f5 authored by Jérome Perrin's avatar Jérome Perrin

accounting: fix error in Journal report with lines with an acquired node

If a transaction is selected but instead of having accounts as
source/destination on lines it acquires the organisation set as
source/destination on the transaction, this causes an AttributeError
getGapList when trying to use this organisation as an account.

To fix this, adjust the getMovementHistoryList parameters to select only
lines using accounts, by passing node_uid, which is O(n) on the number
of accounts, but the number of accounts is not supposed to be too large
and other reports also do this assumption.
parent f1e902b2
Pipeline #34583 failed with stage
in 0 seconds
...@@ -30,14 +30,12 @@ def getAccountId(node_relative_url): ...@@ -30,14 +30,12 @@ def getAccountId(node_relative_url):
return account_title_cache[node_relative_url] return account_title_cache[node_relative_url]
# FIXME: this can be passed as node category to getMovementHistoryList node_search_kw = {
account_in_gap_root_cache = {} 'portal_type': 'Account'
def isAccountInGapRoot(node_relative_url): }
if node_relative_url not in account_in_gap_root_cache: if gap_root:
is_in = portal.restrictedTraverse(node_relative_url).isMemberOf(gap_root) node_search_kw['gap_uid'] = portal.portal_categories.gap.restrictedTraverse(gap_root).getUid()
account_in_gap_root_cache[node_relative_url] = is_in node_uid = [b.uid for b in portal.portal_catalog(**node_search_kw)]
return account_in_gap_root_cache[node_relative_url]
displayed_transaction = {} displayed_transaction = {}
total_credit = 0 total_credit = 0
...@@ -52,6 +50,7 @@ for brain in portal.portal_simulation.getMovementHistoryList( ...@@ -52,6 +50,7 @@ for brain in portal.portal_simulation.getMovementHistoryList(
# may contain some non accounting lines that are in stock table (eg. Pay Sheet Lines) # may contain some non accounting lines that are in stock table (eg. Pay Sheet Lines)
parent_portal_type=portal_type, parent_portal_type=portal_type,
simulation_state=simulation_state, simulation_state=simulation_state,
node_uid=node_uid,
sort_on=(('stock.date', 'ASC'), sort_on=(('stock.date', 'ASC'),
# FIXME: this should actually be sorted on parent_delivery_specific_reference # FIXME: this should actually be sorted on parent_delivery_specific_reference
# a related key which does not exists, and would anyway not be efficient with # a related key which does not exists, and would anyway not be efficient with
...@@ -59,8 +58,6 @@ for brain in portal.portal_simulation.getMovementHistoryList( ...@@ -59,8 +58,6 @@ for brain in portal.portal_simulation.getMovementHistoryList(
('parent_uid', 'descending'), ('parent_uid', 'descending'),
('stock.total_price', 'descending')), ('stock.total_price', 'descending')),
**extra_kw): **extra_kw):
if gap_root and not isAccountInGapRoot(brain.node_relative_url):
continue
debit = max(brain.total_price, 0) or 0 debit = max(brain.total_price, 0) or 0
credit = max(-(brain.total_price or 0), 0) or 0 credit = max(-(brain.total_price or 0), 0) or 0
......
...@@ -489,6 +489,96 @@ class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase): ...@@ -489,6 +489,96 @@ class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase):
self.assertTrue(line_list[-1].isStatLine()) self.assertTrue(line_list[-1].isStatLine())
self.checkLineProperties(line_list[-1], debit=100, credit=100) self.checkLineProperties(line_list[-1], debit=100, credit=100)
def testJournalAcquiredNode(self):
account_module = self.account_module
first = self._makeOne(
portal_type='Accounting Transaction',
title='First One',
simulation_state='delivered',
start_date=DateTime(2006, 2, 2),
destination_section_value=self.organisation_module.client_1,
lines=(
dict(
source_value=account_module.receivable,
source_debit=119.60),
dict(
source_value=account_module.collected_vat,
source_credit=19.60),
dict(
source_value=account_module.goods_sales,
source_credit=100.00)))
# transaction from another entity is not displayed in report and it does not interefer.
self._makeOne(
portal_type='Accounting Transaction',
title='Another entity',
simulation_state='delivered',
start_date=DateTime(2006, 2, 2),
source_section_value=self.organisation_module.client_1,
destination_section_value=self.section,
destination_value=self.section,
lines=(
dict(
source_value=account_module.receivable,
source_debit=11.96),
dict(
source_value=account_module.collected_vat,
source_credit=1.96),
dict(
source_value=account_module.goods_sales,
source_credit=10.00)))
# set request variables and render
request_form = self.portal.REQUEST.form
request_form['at_date'] = DateTime(2006, 2, 2)
request_form['section_category'] = 'group/demo_group'
request_form['section_category_strict'] = False
request_form['portal_type'] = ['Accounting Transaction']
request_form['simulation_state'] = ['delivered']
request_form['hide_analytic'] = False
report_section_list = self.getReportSectionList(
self.portal.accounting_module,
'AccountingTransactionModule_viewJournalReport')
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()]
# we have 1 transaction, with 3 lines
self.assertEqual(3, len(data_line_list))
# First Transaction
self.checkLineProperties(data_line_list[0],
specific_reference=first.getSourceReference(),
date=DateTime(2006, 2, 2),
title='First One',
node_title='41',
debit=119.60,
credit=0)
self.checkLineProperties(data_line_list[1],
specific_reference='',
date=None,
title='',
node_title='4457',
debit=0,
credit=19.60)
self.checkLineProperties(data_line_list[2],
specific_reference='',
date=None,
title='',
node_title='7',
debit=0,
credit=100)
# Stat Line
stat_line = line_list[-1]
self.assertTrue(stat_line.isStatLine())
self.assertFalse(stat_line.getColumnProperty('specific_reference'))
self.assertFalse(stat_line.getColumnProperty('date'))
self.assertFalse(stat_line.getColumnProperty('title'))
self.assertFalse(stat_line.getColumnProperty('node_title'))
self.assertFalse(stat_line.getColumnProperty('mirror_section_title'))
self.assertEqual(stat_line.getColumnProperty('debit'), 119.60)
self.assertEqual(stat_line.getColumnProperty('credit'), 119.60)
def testJournalProject(self): def testJournalProject(self):
self.createProjectAndFunctionDataSet() self.createProjectAndFunctionDataSet()
request_form = self.portal.REQUEST.form request_form = self.portal.REQUEST.form
......
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