Commit 2af9351e authored by Nicolas Wavrant's avatar Nicolas Wavrant

BalanceTransaction.py: correctly indexes Balance Transactions, including their ledgers.

_computeStockDifferenceList also now returns a correct result
parent 59c2507d
......@@ -32,6 +32,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.Document.Inventory import Inventory
from Products.ERP5.Document.AccountingTransaction import AccountingTransaction
from Products.ZSQLCatalog.SQLCatalog import Query
import types
......@@ -136,6 +137,10 @@ class BalanceTransaction(AccountingTransaction, Inventory):
getInventoryList = self.getPortalObject()\
.portal_simulation.getInventoryList
section_uid = self.getDestinationSectionUid()
ledger_uid = self.getLedgerUid()
if ledger_uid is None:
ledger_uid = Query(ledger_uid=None)
precision = 2
if section_uid is not None:
accounting_currency = \
......@@ -150,7 +155,8 @@ class BalanceTransaction(AccountingTransaction, Inventory):
section_uid=section_uid,
precision=precision,
portal_type=self.getPortalAccountingMovementTypeList(),
simulation_state=('delivered', ))
simulation_state=('delivered', ),
ledger_uid=ledger_uid)
# node
for movement in self._getGroupByNodeMovementList():
......@@ -267,7 +273,8 @@ class BalanceTransaction(AccountingTransaction, Inventory):
relative_url=movement.getRelativeUrl(),
quantity=movement.getQuantity(),
total_price=movement\
.getDestinationInventoriatedTotalAssetPrice(), ))
.getDestinationInventoriatedTotalAssetPrice(),
ledger_uid=movement.getLedgerUid(), ))
# mirror section
for movement in self._getGroupByMirrorSectionMovementList():
......@@ -291,7 +298,8 @@ class BalanceTransaction(AccountingTransaction, Inventory):
relative_url=movement.getRelativeUrl(),
quantity=movement.getQuantity(),
total_price=movement\
.getDestinationInventoriatedTotalAssetPrice(), ))
.getDestinationInventoriatedTotalAssetPrice(),
ledger_uid=movement.getLedgerUid(), ))
# payment
for movement in self._getGroupByPaymentMovementList():
......@@ -315,7 +323,8 @@ class BalanceTransaction(AccountingTransaction, Inventory):
relative_url=movement.getRelativeUrl(),
quantity=movement.getQuantity(),
total_price=movement\
.getDestinationInventoriatedTotalAssetPrice(), ))
.getDestinationInventoriatedTotalAssetPrice(),
ledger_uid=movement.getLedgerUid(), ))
return new_stock
......
......@@ -1490,6 +1490,36 @@ class TestClosingPeriod(AccountingTestCase):
self.assertEqual(result['pl'], pl_movement.getDestinationDebit())
self.tic()
def testStockTableContent():
q = self.portal.erp5_sql_connection.manage_test
self.assertEqual(2, q(
"SELECT count(*) FROM stock WHERE portal_type="
"'Balance Transaction Line'")[0][0])
self.assertEqual(300, q(
"SELECT sum(total_price) FROM stock WHERE portal_type="
"'Balance Transaction Line' AND ledger_uid="
"%s GROUP BY ledger_uid" %
self.portal.portal_categories.ledger.accounting.general.getUid())[0][0])
self.assertEqual(300, q(
"SELECT sum(quantity) FROM stock WHERE portal_type="
"'Balance Transaction Line' AND ledger_uid="
"%s GROUP BY ledger_uid" %
self.portal.portal_categories.ledger.accounting.general.getUid())[0][0])
self.assertEqual(1200, q(
"SELECT sum(total_price) FROM stock WHERE portal_type="
"'Balance Transaction Line' AND ledger_uid="
"%s GROUP BY ledger_uid" % self.portal.portal_categories.ledger.accounting.detailed.getUid())[0][0])
self.assertEqual(1200, q(
"SELECT sum(quantity) FROM stock WHERE portal_type="
"'Balance Transaction Line' AND ledger_uid="
"%s GROUP BY ledger_uid" % self.portal.portal_categories.ledger.accounting.detailed.getUid())[0][0])
# now check content of stock table
testStockTableContent()
balance_transaction.immediateReindexObject()
self.tic()
testStockTableContent()
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