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

accounting: do not group lines from different ledgers

parent 86b90bb1
......@@ -6,11 +6,14 @@ For instance, we can refuse to group together lines for different order by retur
The returned value must be hashable.
"""
# By default we take into account mirror section.
# The rationale is that when using internal accounting transaction between
# By default we take into account ledger and mirror accounting.
# We consider ledger so that, by default we don't group lines from different ledger.
# This may be customized too, depending on how ledgers are used in customized implementations.
# We consider mirror accounting because that when using internal accounting transaction between
# two entities of the group, the grouping has to be valid for both sides
# (source_section & destination_section).
# This behavior was introduced in nexedi/erp5@f3bebea3 for compatibility,
# some old sites where accounting lines have been grouped together regardless of
# the mirror node can decide to ignore the mirror account.
......@@ -19,5 +22,5 @@ The returned value must be hashable.
# This can be achieved easily by customizing this script.
if source:
return context.getSource(portal_type='Account')
return context.getDestination(portal_type='Account')
return context.getLedger(), context.getSource(portal_type='Account')
return context.getLedger(), context.getDestination(portal_type='Account')
......@@ -241,6 +241,25 @@ class AccountingTestCase(ERP5TypeTestCase):
'erp5_configurator_standard_invoicing_template',
'erp5_simulation_test')
@UnrestrictedMethod
def setUpLedger(self):
# Create Ledger Categories
ledger_category = self.portal.portal_categories.ledger
ledger_accounting_category = ledger_category.get('accounting', None)
if ledger_accounting_category is None:
ledger_accounting_category = ledger_category.newContent(portal_type='Category', id='accounting')
if ledger_accounting_category.get('general', None) is None:
ledger_accounting_category.newContent(portal_type='Category', id='general')
if ledger_accounting_category.get('detailed', None) is None:
ledger_accounting_category.newContent(portal_type='Category', id='detailed')
if ledger_accounting_category.get('other', None) is None:
ledger_accounting_category.newContent(portal_type='Category', id='other')
# Allow some ledgers on the 'Sale Invoice Transaction' portal type
self.portal.portal_types['Sale Invoice Transaction'].edit(
ledger=['accounting/general', 'accounting/detailed'])
class TestAccounts(AccountingTestCase):
"""Tests Accounts.
......@@ -1169,24 +1188,6 @@ class TestClosingPeriod(AccountingTestCase):
self.assertEqual(None, pl_movement.getSourceTotalAssetPrice())
self.assertEqual(200., pl_movement.getDestinationCredit())
@UnrestrictedMethod
def setUpLedger(self):
# Create Ledger Categories
ledger_category = self.portal.portal_categories.ledger
ledger_accounting_category = ledger_category.get('accounting', None)
if ledger_accounting_category is None:
ledger_accounting_category = ledger_category.newContent(portal_type='Category', id='accounting')
if ledger_accounting_category.get('general', None) is None:
ledger_accounting_category.newContent(portal_type='Category', id='general')
if ledger_accounting_category.get('detailed', None) is None:
ledger_accounting_category.newContent(portal_type='Category', id='detailed')
if ledger_accounting_category.get('other', None) is None:
ledger_accounting_category.newContent(portal_type='Category', id='other')
# Allow some ledgers on the 'Sale Invoice Transaction' portal type
self.portal.portal_types['Sale Invoice Transaction'].edit(
ledger=['accounting/general', 'accounting/detailed'])
def test_createBalanceOnLedgerWithTransactionsWithNoLedger(self):
self.setUpLedger()
organisation_module = self.organisation_module
......@@ -3662,6 +3663,72 @@ class TestTransactions(AccountingTestCase):
for line in invoice.contentValues():
self.assertTrue(line.getGroupingReference())
def test_automatically_setting_grouping_reference_when_same_ledger(self):
self.setUpLedger()
invoice = self._makeOne(
title='First Invoice',
ledger_value=self.portal.portal_categories.ledger.accounting.general,
destination_section_value=self.organisation_module.client_1,
lines=(dict(source_value=self.account_module.goods_purchase,
source_debit=100),
dict(source_value=self.account_module.receivable,
source_credit=100,
id='line_for_grouping_reference',)))
invoice_line = invoice.line_for_grouping_reference
payment = self._makeOne(
title='First Invoice Payment',
portal_type='Payment Transaction',
simulation_state='delivered',
causality_value=invoice,
ledger_value=self.portal.portal_categories.ledger.accounting.general,
source_payment_value=self.section.newContent(
portal_type='Bank Account'),
destination_section_value=self.organisation_module.client_1,
lines=(dict(source_value=self.account_module.receivable,
id='line_for_grouping_reference',
source_debit=100),
dict(source_value=self.account_module.bank,
source_credit=100,)))
payment_line = payment.line_for_grouping_reference
invoice.stop()
self.assertTrue(invoice_line.getGroupingReference())
self.assertTrue(payment_line.getGroupingReference())
def test_not_automatically_setting_grouping_reference_when_different_ledger(self):
self.setUpLedger()
invoice = self._makeOne(
title='First Invoice',
ledger_value=self.portal.portal_categories.ledger.accounting.general,
destination_section_value=self.organisation_module.client_1,
lines=(dict(source_value=self.account_module.goods_purchase,
source_debit=100),
dict(source_value=self.account_module.receivable,
source_credit=100,
id='line_for_grouping_reference',)))
invoice_line = invoice.line_for_grouping_reference
payment = self._makeOne(
title='First Invoice Payment',
portal_type='Payment Transaction',
simulation_state='delivered',
causality_value=invoice,
ledger_value=self.portal.portal_categories.ledger.accounting.detailed,
source_payment_value=self.section.newContent(
portal_type='Bank Account'),
destination_section_value=self.organisation_module.client_1,
lines=(dict(source_value=self.account_module.receivable,
id='line_for_grouping_reference',
source_debit=100),
dict(source_value=self.account_module.bank,
source_credit=100,)))
payment_line = payment.line_for_grouping_reference
invoice.stop()
self.assertFalse(invoice_line.getGroupingReference())
self.assertFalse(payment_line.getGroupingReference())
def test_roundDebitCredit_raises_if_big_difference(self):
invoice = self._makeOne(
portal_type='Sale Invoice Transaction',
......
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