Commit 59c2507d authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_accounting: be sure to not create a Balance Transaction on the None...

erp5_accounting: be sure to not create a Balance Transaction on the None ledger if no movements have a None ledger
parent 82cd2983
......@@ -80,8 +80,31 @@ def createBalanceTransaction(section, ledger=None):
resource=section_currency,
causality_value=context)
getInventoryList = portal.portal_simulation.getInventoryList
with context.defaultActivateParameterDict({'tag': activity_tag}, placeless=True):
# List ledgers on which there are movements
inventory_ledger_uid_list = [inventory.ledger_uid for inventory \
in getInventoryList(at_date=at_date.latestTime(),
portal_type=portal.getPortalAccountingMovementTypeList(),
group_by_ledger=True)]
for ledger in ledger_list:
# If there are no movements within this ledger, we can
# directly go to another
if ledger is None and None not in inventory_ledger_uid_list:
continue
elif ledger is not None and ledger.getUid() not in inventory_ledger_uid_list:
continue
if ledger is not None:
ledger_uid = ledger.getUid()
ledger_url = ledger.getCategoryRelativeUrl()
else:
ledger_uid = Query(ledger_uid=None)
ledger_url = ''
for section in section_list:
section_uid = section.getUid()
balance_transaction = None
......@@ -108,15 +131,6 @@ with context.defaultActivateParameterDict({'tag': activity_tag}, placeless=True)
else:
group_by_node_node_category_list.append(node_category_url)
getInventoryList = portal.portal_simulation.getInventoryList
if ledger is not None:
ledger_uid = ledger.getUid()
ledger_url = ledger.getCategoryRelativeUrl()
else:
ledger_uid = Query(ledger_uid=None)
ledger_url = ''
inventory_param_dict = dict(section_uid=section_uid,
simulation_state=('delivered',),
precision=section_currency_precision,
......
......@@ -1187,7 +1187,7 @@ class TestClosingPeriod(AccountingTestCase):
self.portal.portal_types['Sale Invoice Transaction'].edit(
ledger=['accounting/general', 'accounting/detailed'])
def test_createBalanceOnLedger(self):
def test_createBalanceOnLedgerWithTransactionsWithNoLedger(self):
self.setUpLedger()
organisation_module = self.organisation_module
period = self.section.newContent(portal_type='Accounting Period')
......@@ -1353,6 +1353,143 @@ class TestClosingPeriod(AccountingTestCase):
self.assertEqual(result['pl'], pl_movement.getDestinationDebit())
self.tic()
def test_createBalanceOnLedgerWithAllTransactionsWithLedger(self):
self.setUpLedger()
organisation_module = self.organisation_module
period = self.section.newContent(portal_type='Accounting Period')
period.setStartDate(DateTime(2006, 1, 1))
period.setStopDate(DateTime(2006, 12, 31))
pl = self.portal.account_module.newContent(
portal_type='Account',
account_type='equity')
# 2 Transactions for clients 1 and 2 on ledger accounting/general
transaction1 = self._makeOne(
start_date=DateTime(2006, 1, 1),
portal_type='Sale Invoice Transaction',
ledger='accounting/general',
destination_section_value=organisation_module.client_1,
simulation_state='delivered',
lines=(dict(source_value=self.account_module.goods_sales,
source_debit=100),
dict(source_value=self.account_module.receivable,
source_credit=100)))
transaction2 = self._makeOne(
start_date=DateTime(2006, 1, 2),
portal_type='Sale Invoice Transaction',
ledger='accounting/general',
destination_section_value=organisation_module.client_2,
simulation_state='delivered',
lines=(dict(source_value=self.account_module.goods_sales,
source_debit=200),
dict(source_value=self.account_module.receivable,
source_credit=200)))
# 2 Transactions for clients 1 and 2 on ledger accounting/detailed
transaction3 = self._makeOne(
start_date=DateTime(2006, 1, 1),
portal_type='Sale Invoice Transaction',
ledger='accounting/detailed',
destination_section_value=organisation_module.client_1,
simulation_state='delivered',
lines=(dict(source_value=self.account_module.goods_sales,
source_debit=400),
dict(source_value=self.account_module.receivable,
source_credit=400)))
transaction4 = self._makeOne(
start_date=DateTime(2006, 1, 2),
portal_type='Sale Invoice Transaction',
ledger='accounting/detailed',
destination_section_value=organisation_module.client_2,
simulation_state='delivered',
lines=(dict(source_value=self.account_module.goods_sales,
source_debit=800),
dict(source_value=self.account_module.receivable,
source_credit=800)))
period.AccountingPeriod_createBalanceTransaction(
profit_and_loss_account=pl.getRelativeUrl())
accounting_transaction_list = self.accounting_module.contentValues()
self.assertEqual(6, len(accounting_transaction_list))
balance_transaction_list = self.accounting_module.contentValues(
portal_type='Balance Transaction')
self.assertEqual(2, len(balance_transaction_list))
# 1st balance has 3 lines : # 2nd balance has 3 lines :
# on ledger/accounting/general # on ledger/accounting/detailed
# pl = 300 D # pl = 1200 D
# receivable/client1 = 200 C # receivable/client1 = 800 C
# receivable/client2 = 100 C # receivable/client2 = 400 C
result_mapping = {}
result_mapping['accounting/general'] = {'client1': 100., 'client2': 200., 'pl': 300.}
result_mapping['accounting/detailed'] = {'client1': 400., 'client2': 800., 'pl': 1200.}
for balance_transaction in balance_transaction_list:
self.assertEqual(self.section,
balance_transaction.getDestinationSectionValue())
self.assertEqual(None, balance_transaction.getSourceSection())
self.assertEqual(DateTime(2007, 1, 1),
balance_transaction.getStartDate())
self.assertEqual('currency_module/euro',
balance_transaction.getResource())
self.assertEqual('delivered', balance_transaction.getSimulationState())
movement_list = balance_transaction.getMovementList()
self.assertEqual(3, len(movement_list))
current_ledger = balance_transaction.getLedger()
assert current_ledger in ('accounting/general', 'accounting/detailed')
result = result_mapping[current_ledger]
client1_movement_list = [m for m in movement_list
if m.getSourceSectionValue() == organisation_module.client_1]
self.assertEqual(1, len(client1_movement_list))
client1_movement = client1_movement_list[0]
self.assertEqual([], client1_movement.getValueList('resource'))
self.assertEqual([], client1_movement.getValueList('destination_section'))
self.assertEqual(None, client1_movement.getSource())
self.assertEqual(self.account_module.receivable,
client1_movement.getDestinationValue())
self.assertEqual(organisation_module.client_1,
client1_movement.getSourceSectionValue())
self.assertEqual(None, client1_movement.getDestinationTotalAssetPrice())
self.assertEqual(None, client1_movement.getSourceTotalAssetPrice())
self.assertEqual(result['client1'], client1_movement.getDestinationCredit())
client2_movement_list = [m for m in movement_list
if m.getSourceSectionValue() == organisation_module.client_2]
self.assertEqual(1, len(client2_movement_list))
client2_movement = client2_movement_list[0]
self.assertEqual([], client2_movement.getValueList('resource'))
self.assertEqual([], client2_movement.getValueList('destination_section'))
self.assertEqual(None, client2_movement.getSource())
self.assertEqual(self.account_module.receivable,
client2_movement.getDestinationValue())
self.assertEqual(organisation_module.client_2,
client2_movement.getSourceSectionValue())
self.assertEqual(None, client2_movement.getDestinationTotalAssetPrice())
self.assertEqual(None, client2_movement.getSourceTotalAssetPrice())
self.assertEqual(result['client2'], client2_movement.getDestinationCredit())
pl_movement_list = [m for m in movement_list
if m.getDestinationValue() == pl]
self.assertEqual(1, len(pl_movement_list))
pl_movement = pl_movement_list[0]
self.assertEqual([], pl_movement.getValueList('resource'))
self.assertEqual(None, pl_movement.getSource())
self.assertEqual(pl,
pl_movement.getDestinationValue())
self.assertEqual(None,
pl_movement.getSourceSection())
self.assertEqual(None, pl_movement.getDestinationTotalAssetPrice())
self.assertEqual(None, pl_movement.getSourceTotalAssetPrice())
self.assertEqual(result['pl'], pl_movement.getDestinationDebit())
self.tic()
def test_createBalanceOnMirrorSectionMultiCurrency(self):
pl = self.portal.account_module.newContent(
portal_type='Account',
......
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