Commit 4592d542 authored by Jérome Perrin's avatar Jérome Perrin

add more tests for multiple resources and Balance Transaction indexing, and fix

the bug in this case.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18707 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2455e226
...@@ -164,12 +164,14 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -164,12 +164,14 @@ class BalanceTransaction(AccountingTransaction, Inventory):
node_uid = movement.getDestinationUid() node_uid = movement.getDestinationUid()
if not node_uid: if not node_uid:
raise ValueError, "No destination uid for %s" % movement raise ValueError, "No destination uid for %s" % movement
resource_uid = movement.getResourceUid()
stock_list = current_stock.setdefault( stock_list = current_stock.setdefault(
InventoryKey(node_uid=node_uid, InventoryKey(node_uid=node_uid,
section_uid=section_uid), []) section_uid=section_uid), [])
for inventory in getInventoryList( for inventory in getInventoryList(
node_uid=node_uid, node_uid=node_uid,
resource_uid=resource_uid,
group_by_node=1, group_by_node=1,
group_by_resource=1, group_by_resource=1,
**default_inventory_params): **default_inventory_params):
...@@ -177,7 +179,7 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -177,7 +179,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
stock_list.append( stock_list.append(
dict(destination_uid=node_uid, dict(destination_uid=node_uid,
destination_section_uid=section_uid, destination_section_uid=section_uid,
resource_uid=inventory.resource_uid, resource_uid=resource_uid,
quantity=inventory.total_quantity, quantity=inventory.total_quantity,
total_price=inventory.total_price, )) total_price=inventory.total_price, ))
...@@ -187,6 +189,7 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -187,6 +189,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
if not node_uid: if not node_uid:
raise ValueError, "No destination uid for %s" % movement raise ValueError, "No destination uid for %s" % movement
mirror_section_uid = movement.getSourceSectionUid() mirror_section_uid = movement.getSourceSectionUid()
resource_uid = movement.getResourceUid()
stock_list = current_stock.setdefault( stock_list = current_stock.setdefault(
InventoryKey(node_uid=node_uid, InventoryKey(node_uid=node_uid,
...@@ -195,6 +198,7 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -195,6 +198,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
for inventory in getInventoryList( for inventory in getInventoryList(
node_uid=node_uid, node_uid=node_uid,
mirror_section_uid=mirror_section_uid, mirror_section_uid=mirror_section_uid,
resource_uid=resource_uid,
group_by_node=1, group_by_node=1,
group_by_mirror_section=1, group_by_mirror_section=1,
group_by_resource=1, group_by_resource=1,
...@@ -204,7 +208,7 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -204,7 +208,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
dict(destination_uid=node_uid, dict(destination_uid=node_uid,
destination_section_uid=section_uid, destination_section_uid=section_uid,
source_section_uid=mirror_section_uid, source_section_uid=mirror_section_uid,
resource_uid=inventory.resource_uid, resource_uid=resource_uid,
quantity=inventory.total_quantity, quantity=inventory.total_quantity,
total_price=inventory.total_price, )) total_price=inventory.total_price, ))
...@@ -214,6 +218,7 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -214,6 +218,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
if not node_uid: if not node_uid:
raise ValueError, "No destination uid for %s" % movement raise ValueError, "No destination uid for %s" % movement
payment_uid = movement.getDestinationPaymentUid() payment_uid = movement.getDestinationPaymentUid()
resource_uid = movement.getResourceUid()
stock_list = current_stock.setdefault( stock_list = current_stock.setdefault(
InventoryKey(node_uid=node_uid, InventoryKey(node_uid=node_uid,
...@@ -222,6 +227,7 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -222,6 +227,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
for inventory in getInventoryList( for inventory in getInventoryList(
node_uid=node_uid, node_uid=node_uid,
payment_uid=payment_uid, payment_uid=payment_uid,
resource_uid=resource_uid,
group_by_node=1, group_by_node=1,
group_by_payment=1, group_by_payment=1,
group_by_resource=1, group_by_resource=1,
...@@ -231,7 +237,7 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -231,7 +237,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
dict(destination_uid=node_uid, dict(destination_uid=node_uid,
destination_section_uid=section_uid, destination_section_uid=section_uid,
destination_payment_uid=payment_uid, destination_payment_uid=payment_uid,
resource_uid=inventory.resource_uid, resource_uid=resource_uid,
quantity=inventory.total_quantity, quantity=inventory.total_quantity,
total_price=inventory.total_price, )) total_price=inventory.total_price, ))
......
...@@ -895,6 +895,138 @@ class TestClosingPeriod(AccountingTestCase): ...@@ -895,6 +895,138 @@ class TestClosingPeriod(AccountingTestCase):
accounting_currency_precision) accounting_currency_precision)
def test_createBalanceOnMirrorSectionMultiCurrencySameMirrorSection(self):
pl = self.portal.account_module.newContent(
portal_type='Account',
account_type='equity')
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))
transaction1 = self._makeOne(
start_date=DateTime(2006, 1, 1),
title='Yen',
resource='currency_module/yen',
destination_section_value=organisation_module.client_1,
portal_type='Sale Invoice Transaction',
simulation_state='delivered',
lines=(dict(source_value=self.account_module.goods_sales,
source_asset_debit=1.1,
source_debit=100),
dict(source_value=self.account_module.receivable,
source_asset_credit=1.1,
source_credit=100)))
transaction2 = self._makeOne(
start_date=DateTime(2006, 1, 2),
title='Dollar',
resource='currency_module/usd',
destination_section_value=organisation_module.client_1,
portal_type='Sale Invoice Transaction',
simulation_state='delivered',
lines=(dict(source_value=self.account_module.goods_sales,
source_asset_debit=2.2,
source_debit=200),
dict(source_value=self.account_module.receivable,
source_asset_credit=2.2,
source_credit=200)))
get_transaction().commit()
self.tic()
period.AccountingPeriod_createBalanceTransaction(
profit_and_loss_account=pl.getRelativeUrl())
accounting_transaction_list = self.accounting_module.contentValues()
self.assertEquals(3, len(accounting_transaction_list))
balance_transaction_list = self.accounting_module.contentValues(
portal_type='Balance Transaction')
self.assertEquals(1, len(balance_transaction_list))
balance_transaction = balance_transaction_list[0]
self.assertEquals(self.section,
balance_transaction.getDestinationSectionValue())
self.assertEquals(None, balance_transaction.getSourceSection())
self.assertEquals(DateTime(2007, 1, 1),
balance_transaction.getStartDate())
self.assertEquals('currency_module/euro',
balance_transaction.getResource())
# this should create a balance with 3 lines,
# pl = 3.3 D ( resource acquired )
# receivable/client1 = 1.1 C ( resource yen ) qty=100
# receivable/client1 = 2.2 C ( resource usd ) qyt=200
accounting_currency_precision = \
self.portal.currency_module.euro.getQuantityPrecision()
self.assertEquals(accounting_currency_precision, 2)
movement_list = balance_transaction.getMovementList()
self.assertEquals(3, len(movement_list))
client1_movement_list = [m for m in movement_list
if m.getSourceSectionValue() == organisation_module.client_1]
self.assertEquals(2, len(client1_movement_list))
yen_movement = [x for x in client1_movement_list if
x.getResource() == 'currency_module/yen'][0]
self.assertEquals([], yen_movement.getValueList('destination_section'))
self.assertEquals(None, yen_movement.getSource())
self.assertEquals(self.account_module.receivable,
yen_movement.getDestinationValue())
self.assertEquals(organisation_module.client_1,
yen_movement.getSourceSectionValue())
self.assertAlmostEquals(1.1,
yen_movement.getDestinationInventoriatedTotalAssetCredit(),
accounting_currency_precision)
self.assertEquals(None, yen_movement.getSourceTotalAssetPrice())
self.assertEquals(100, yen_movement.getDestinationCredit())
dollar_movement = [x for x in client1_movement_list if
x.getResource() == 'currency_module/usd'][0]
self.assertEquals([], dollar_movement.getValueList('destination_section'))
self.assertEquals(None, dollar_movement.getSource())
self.assertEquals(self.account_module.receivable,
dollar_movement.getDestinationValue())
self.assertEquals(organisation_module.client_1,
dollar_movement.getSourceSectionValue())
self.assertAlmostEquals(2.2,
dollar_movement.getDestinationInventoriatedTotalAssetCredit(),
accounting_currency_precision)
self.assertEquals(None, dollar_movement.getSourceTotalAssetPrice())
self.assertEquals(200, dollar_movement.getDestinationCredit())
get_transaction().commit()
self.tic()
# now check content of stock table
q = self.portal.erp5_sql_connection.manage_test
self.assertEquals(1, q(
"SELECT count(*) FROM stock WHERE portal_type="
"'Balance Transaction Line'")[0][0])
self.assertEquals(3.3, q(
"SELECT total_price FROM stock WHERE portal_type="
"'Balance Transaction Line'")[0][0])
self.assertEquals(3.3, q(
"SELECT quantity FROM stock WHERE portal_type="
"'Balance Transaction Line'")[0][0])
self.assertEquals(self.portal.currency_module.euro.getUid(), q(
"SELECT resource_uid FROM stock WHERE portal_type="
"'Balance Transaction Line'")[0][0])
self.assertEquals(self.section.getUid(), q(
"SELECT section_uid FROM stock WHERE portal_type="
"'Balance Transaction Line'")[0][0])
self.assertEquals(None, q(
"SELECT mirror_section_uid FROM stock WHERE portal_type="
"'Balance Transaction Line'")[0][0])
self.assertEquals(pl.getUid(), q(
"SELECT node_uid FROM stock WHERE portal_type="
"'Balance Transaction Line'")[0][0])
self.assertEquals(None, q(
"SELECT mirror_node_uid FROM stock WHERE portal_type="
"'Balance Transaction Line'")[0][0])
self.assertEquals(DateTime(2007, 1, 1), q(
"SELECT date FROM stock WHERE portal_type="
"'Balance Transaction Line'")[0][0])
def test_AccountingPeriodWorkflow(self): def test_AccountingPeriodWorkflow(self):
"""Tests that accounting_period_workflow creates a balance transaction. """Tests that accounting_period_workflow creates a balance 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