Commit 62ebc573 authored by Jérome Perrin's avatar Jérome Perrin

Make sure balance transaction line from getMovementHistoryList can be retrieved with getObject


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16407 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b7077fe2
...@@ -227,6 +227,8 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -227,6 +227,8 @@ class BalanceTransaction(AccountingTransaction, Inventory):
dict(destination_uid=node_uid, dict(destination_uid=node_uid,
destination_section_uid=section_uid, destination_section_uid=section_uid,
resource_uid=movement.getResourceUid(), resource_uid=movement.getResourceUid(),
uid=movement.getUid(),
relative_url=movement.getRelativeUrl(),
quantity=movement.getQuantity(), quantity=movement.getQuantity(),
total_price=movement\ total_price=movement\
.getDestinationInventoriatedTotalAssetPrice(), )) .getDestinationInventoriatedTotalAssetPrice(), ))
...@@ -246,6 +248,8 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -246,6 +248,8 @@ class BalanceTransaction(AccountingTransaction, Inventory):
destination_section_uid=section_uid, destination_section_uid=section_uid,
source_section_uid=mirror_section_uid, source_section_uid=mirror_section_uid,
resource_uid=movement.getResourceUid(), resource_uid=movement.getResourceUid(),
uid=movement.getUid(),
relative_url=movement.getRelativeUrl(),
quantity=movement.getQuantity(), quantity=movement.getQuantity(),
total_price=movement\ total_price=movement\
.getDestinationInventoriatedTotalAssetPrice(), )) .getDestinationInventoriatedTotalAssetPrice(), ))
...@@ -265,6 +269,8 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -265,6 +269,8 @@ class BalanceTransaction(AccountingTransaction, Inventory):
destination_section_uid=section_uid, destination_section_uid=section_uid,
destination_payment_uid=payment_uid, destination_payment_uid=payment_uid,
resource_uid=movement.getResourceUid(), resource_uid=movement.getResourceUid(),
uid=movement.getUid(),
relative_url=movement.getRelativeUrl(),
quantity=movement.getQuantity(), quantity=movement.getQuantity(),
total_price=movement\ total_price=movement\
.getDestinationInventoriatedTotalAssetPrice(), )) .getDestinationInventoriatedTotalAssetPrice(), ))
...@@ -288,7 +294,7 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -288,7 +294,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
matching_diff = None matching_diff = None
for diff in stock_diff_list: for diff in stock_diff_list:
for prop in [k for k in diff.keys() if k not in ('quantity', for prop in [k for k in diff.keys() if k not in ('quantity',
'total_price')]: 'total_price', 'uid', 'relative_url')]:
if diff[prop] != new_stock.get(prop): if diff[prop] != new_stock.get(prop):
break break
else: else:
...@@ -347,10 +353,26 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -347,10 +353,26 @@ class BalanceTransaction(AccountingTransaction, Inventory):
def factory(*args, **kw): def factory(*args, **kw):
doc = newTempBalanceTransactionLine(self, self.getId(), doc = newTempBalanceTransactionLine(self, self.getId(),
uid=self.getUid()) uid=self.getUid())
relative_url = kw.pop('relative_url', None)
destination_total_asset_price = kw.pop('total_price', None) destination_total_asset_price = kw.pop('total_price', None)
if destination_total_asset_price is not None: if destination_total_asset_price is not None:
kw['destination_total_asset_price'] = destination_total_asset_price kw['destination_total_asset_price'] = destination_total_asset_price
doc._edit(*args, **kw) doc._edit(*args, **kw)
if relative_url:
def URLGetter(url):
def getRelativeUrl():
return url
return getRelativeUrl
doc.getRelativeUrl = URLGetter(relative_url)
def PathGetter(path):
def getPath():
return path
return getPath
doc.getPath = PathGetter(relative_url)
return doc return doc
return factory return factory
...@@ -396,6 +418,8 @@ class BalanceTransaction(AccountingTransaction, Inventory): ...@@ -396,6 +418,8 @@ class BalanceTransaction(AccountingTransaction, Inventory):
# Catalog differences calculated from lines # Catalog differences calculated from lines
self.portal_catalog.catalogObjectList(stock_object_list, self.portal_catalog.catalogObjectList(stock_object_list,
method_id_list=('z_catalog_stock_list',), method_id_list=('z_catalog_stock_list',
'z_catalog_object_list',
'z_catalog_movement_category_list'),
disable_cache=1, check_uid=0) disable_cache=1, check_uid=0)
...@@ -219,6 +219,13 @@ class AccountingTestCase(ERP5TypeTestCase): ...@@ -219,6 +219,13 @@ class AccountingTestCase(ERP5TypeTestCase):
class TestClosingPeriod(AccountingTestCase): class TestClosingPeriod(AccountingTestCase):
"""Various tests for closing the period. """Various tests for closing the period.
""" """
def beforeTearDown(self):
# we manually remove the content of stock table, because unindexObject
# might not work correctly on Balance Transaction, and we don't want
# leave something in stock table that will change the next test.
self.portal.erp5_sql_connection.manage_test('truncate stock')
get_transaction().commit()
def test_createBalanceOnNode(self): def test_createBalanceOnNode(self):
period = self.section.newContent(portal_type='Accounting Period') period = self.section.newContent(portal_type='Accounting Period')
period.setStartDate(DateTime(2006, 1, 1)) period.setStartDate(DateTime(2006, 1, 1))
...@@ -944,7 +951,116 @@ class TestClosingPeriod(AccountingTestCase): ...@@ -944,7 +951,116 @@ class TestClosingPeriod(AccountingTestCase):
node_uid=node_uid)) node_uid=node_uid))
def test_BalanceTransactionLineBrainGetObject(self):
# Balance Transaction Line can be retrieved using Brain.getObject
balance = self.accounting_module.newContent(
portal_type='Balance Transaction',
destination_section_value=self.section,
start_date=DateTime(2006, 12, 31),
resource_value=self.currency_module.euro,)
balance_line = balance.newContent(
portal_type='Balance Transaction Line',
destination_value=self.account_module.receivable,
destination_debit=100,)
balance_line2 = balance.newContent(
portal_type='Balance Transaction Line',
destination_value=self.account_module.payable,
destination_credit=100,)
balance.stop()
get_transaction().commit()
self.tic()
stool = self.portal.portal_simulation
# the account 'receivable' has a balance of 100
node_uid = self.account_module.receivable.getUid()
self.assertEquals(100, stool.getInventory(
section_uid=self.section.getUid(),
node_uid=node_uid))
# there is one line in getMovementHistoryList:
mvt_history_list = stool.getMovementHistoryList(
section_uid=self.section.getUid(),
node_uid=node_uid)
self.assertEquals(1, len(mvt_history_list))
self.assertEquals(mvt_history_list[0].getObject(),
balance_line)
# There is also one line on payable account
node_uid = self.account_module.payable.getUid()
mvt_history_list = stool.getMovementHistoryList(
section_uid=self.section.getUid(),
node_uid=node_uid)
self.assertEquals(1, len(mvt_history_list))
self.assertEquals(mvt_history_list[0].getObject(),
balance_line2)
def test_BalanceTransactionDate(self):
# check that dates are correctly used for Balance Transaction indexing
balance = self.accounting_module.newContent(
portal_type='Balance Transaction',
destination_section_value=self.section,
start_date=DateTime(2006, 12, 31),
resource_value=self.currency_module.euro,)
balance_line = balance.newContent(
portal_type='Balance Transaction Line',
destination_value=self.account_module.receivable,
destination_debit=100,)
balance.stop()
get_transaction().commit()
self.tic()
stool = self.portal.portal_simulation
# the account 'receivable' has a balance of 100 after 2006/12/31
node_uid = self.account_module.receivable.getUid()
self.assertEquals(100, stool.getInventory(
at_date=DateTime(2006, 12, 31),
section_uid=self.section.getUid(),
node_uid=node_uid))
self.assertEquals(1, len(stool.getMovementHistoryList(
at_date=DateTime(2006, 12, 31),
section_uid=self.section.getUid(),
node_uid=node_uid)))
# and 0 before
self.assertEquals(0, stool.getInventory(
at_date=DateTime(2005, 12, 31),
section_uid=self.section.getUid(),
node_uid=node_uid))
self.assertEquals(0, len(stool.getMovementHistoryList(
at_date=DateTime(2005, 12, 31),
section_uid=self.section.getUid(),
node_uid=node_uid)))
def test_BalanceTransactionLineInventoryAPIParentPortalType(self):
# related keys like parent_portal_type= can be used in inventory API to get
# balance transaction lines
balance = self.accounting_module.newContent(
portal_type='Balance Transaction',
destination_section_value=self.section,
start_date=DateTime(2006, 12, 31),
resource_value=self.currency_module.euro,)
balance_line = balance.newContent(
portal_type='Balance Transaction Line',
destination_value=self.account_module.receivable,
destination_debit=100,)
balance.stop()
get_transaction().commit()
self.tic()
stool = self.portal.portal_simulation
# the account 'receivable' has a balance of 100
node_uid = self.account_module.receivable.getUid()
self.assertEquals(100, stool.getInventory(
parent_portal_type='Balance Transaction',
section_uid=self.section.getUid(),
node_uid=node_uid))
# there is one line in getMovementHistoryList:
mvt_history_list = stool.getMovementHistoryList(
parent_portal_type='Balance Transaction',
section_uid=self.section.getUid(),
node_uid=node_uid)
self.assertEquals(1, len(mvt_history_list))
# TODO : test deletion ?
class TestAccounting(ERP5TypeTestCase): class TestAccounting(ERP5TypeTestCase):
"""The first test for Accounting """The first test for Accounting
......
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