Commit 5709d731 authored by Jérome Perrin's avatar Jérome Perrin

Fix parallelism of accounting grouping alarms and add basic tests

/reviewed-on !850
parents 439ff1b3 778bfa55
...@@ -41,14 +41,15 @@ for brain in portal.portal_simulation.getInventoryList(**search_params): ...@@ -41,14 +41,15 @@ for brain in portal.portal_simulation.getInventoryList(**search_params):
grouped_line_list = tr.AccountingTransaction_guessGroupedLines() grouped_line_list = tr.AccountingTransaction_guessGroupedLines()
if not grouped_line_list: if not grouped_line_list:
# Group whatever can be grouped. XXX maybe we want to make this optional. # Group whatever can be grouped. XXX maybe we want to make this optional.
grouped_line_list = tr.AccountingTransaction_guessGroupedLines(accounting_transaction_line_uid_list=[ grouped_line_list = tr.AccountingTransaction_guessGroupedLines(
accounting_transaction_line_uid_list=[
line.uid for line in portal.portal_simulation.getMovementHistoryList( line.uid for line in portal.portal_simulation.getMovementHistoryList(
node_uid=brain.node_uid, node_uid=brain.node_uid,
mirror_section_uid=brain.mirror_section_uid, mirror_section_uid=brain.mirror_section_uid,
section_uid=section_uid_list, section_uid=section_uid_list,
simulation_state=('stopped', 'delivered'), simulation_state=('stopped', 'delivered'),
portal_type=portal.getPortalAccountingMovementTypeList(), portal_type=portal.getPortalAccountingMovementTypeList(),
grouping_reference=None,)]) grouping_reference=None,) if not line.getObject().getGroupingReference()])
if grouped_line_list: if grouped_line_list:
print 'FIXED', grouped_line_list print 'FIXED', grouped_line_list
else: else:
......
...@@ -30,13 +30,11 @@ ...@@ -30,13 +30,11 @@
""" """
import unittest
from DateTime import DateTime from DateTime import DateTime
from Products.CMFCore.utils import _checkPermission from Products.CMFCore.utils import _checkPermission
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.CodingStyleTestCase import CodingStyleTestCase from Products.ERP5Type.tests import CodingStyleTestCase
from Products.ERP5Type.tests.utils import reindex from Products.ERP5Type.tests.utils import reindex
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.DCWorkflow.DCWorkflow import ValidationFailed
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
...@@ -5921,7 +5919,7 @@ class TestInternalInvoiceTransaction(AccountingTestCase): ...@@ -5921,7 +5919,7 @@ class TestInternalInvoiceTransaction(AccountingTestCase):
portal_type='Internal Invoice Transaction Line')]) portal_type='Internal Invoice Transaction Line')])
class TestAccountingCodingStyle(CodingStyleTestCase, AccountingTestCase): class TestAccountingCodingStyle(CodingStyleTestCase.CodingStyleTestCase, AccountingTestCase):
"""Runs CodingStyleTestCase checks on erp5_accounting """Runs CodingStyleTestCase checks on erp5_accounting
""" """
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
...@@ -5937,15 +5935,95 @@ class TestAccountingCodingStyle(CodingStyleTestCase, AccountingTestCase): ...@@ -5937,15 +5935,95 @@ class TestAccountingCodingStyle(CodingStyleTestCase, AccountingTestCase):
pass pass
def test_suite(): class TestAccountingAlarms(AccountingTestCase):
suite = unittest.TestSuite() def test_check_payable_receivable_account_grouped(self):
suite.addTest(unittest.makeSuite(TestAccountingWithSequences)) invoice = self._makeOne(
suite.addTest(unittest.makeSuite(TestTransactions)) title='First Invoice',
suite.addTest(unittest.makeSuite(TestAccounts)) destination_section_value=self.organisation_module.client_1,
suite.addTest(unittest.makeSuite(TestClosingPeriod)) simulation_state='stopped',
suite.addTest(unittest.makeSuite(TestTransactionValidation)) lines=(dict(source_value=self.account_module.goods_purchase,
suite.addTest(unittest.makeSuite(TestAccountingExport)) source_debit=100),
suite.addTest(unittest.makeSuite(TestAccountingTransactionTemplate)) dict(source_value=self.account_module.goods_sales,
suite.addTest(unittest.makeSuite(TestInternalInvoiceTransaction)) id='line_to_group_with_itself',
suite.addTest(unittest.makeSuite(TestAccountingCodingStyle)) source_debit=0),
return suite dict(source_value=self.account_module.receivable,
source_credit=100,
id='line_to_group',),))
payment = self._makeOne(
title='First Invoice Payment',
portal_type='Payment Transaction',
source_payment_value=self.section.newContent(
portal_type='Bank Account'),
destination_section_value=self.organisation_module.client_1,
simulation_state='stopped',
lines=(dict(source_value=self.account_module.receivable,
id='line_to_group',
source_debit=100),
dict(source_value=self.account_module.bank,
source_credit=100,)))
self.tic()
self.login()
alarm = self.portal.portal_alarms.check_payable_receivable_account_grouped
alarm.edit(section_category='group/demo_group')
# this alarm detect problem
alarm.activeSense()
self.tic()
self.assertEqual(
['organisation_module/client_1 has a 0 balance but some not grouped transactions.\n'],
[x.getProperty('detail') for x in alarm.getLastActiveProcess().getResultList()])
self.assertTrue(alarm.sense())
# and can fix problems
alarm.activeSense(fixit=True)
self.tic()
self.assertTrue(alarm.sense())
self.assertTrue(invoice.line_to_group.getGroupingReference())
self.assertEqual(
invoice.line_to_group.getGroupingReference(),
payment.line_to_group.getGroupingReference())
self.assertTrue(invoice.line_to_group_with_itself.getGroupingReference())
def test_check_grouping_reference_validity(self):
# Two transactions grouped together, but grouped quantities do not match (3 != 7)
invoice = self._makeOne(
title='First Invoice',
destination_section_value=self.organisation_module.client_1,
simulation_state='stopped',
lines=(dict(source_value=self.account_module.goods_purchase,
source_debit=3),
dict(source_value=self.account_module.receivable,
source_credit=3,
id='grouped_line',
grouping_reference='A',
grouping_date=DateTime(),),))
payment = self._makeOne(
title='First Invoice Payment',
portal_type='Payment Transaction',
source_payment_value=self.section.newContent(
portal_type='Bank Account'),
destination_section_value=self.organisation_module.client_1,
simulation_state='stopped',
lines=(dict(source_value=self.account_module.receivable,
source_debit=7,
id='grouped_line',
grouping_reference='A',
grouping_date=DateTime(),),
dict(source_value=self.account_module.bank,
source_credit=7,)))
self.tic()
self.login()
alarm = self.portal.portal_alarms.check_grouping_reference_validity
# this alarm detect problem
alarm.activeSense()
self.tic()
self.assertEqual(
sorted([
# 4.0 is the difference in grouping ( 7 - 3 )
'{} has wrong grouping (4.0)'.format(invoice.grouped_line.getRelativeUrl()),
'{} has wrong grouping (4.0)'.format(payment.grouped_line.getRelativeUrl()),]),
sorted([x.getProperty('detail') for x in alarm.getLastActiveProcess().getResultList()]))
self.assertTrue(alarm.sense())
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