Commit 1ab4fc47 authored by Jérome Perrin's avatar Jérome Perrin

accounting: rewrite account statements' initial balance detail

This is now based on getMovementHistoryList + grouping_date instead of
Base_zGetNotGroupedMovementList
parent 9cc2191c
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
from Products.PythonScripts.standard import Object
portal = context.getPortalObject()
getObject = portal.portal_catalog.getObject
params = portal.ERP5Accounting_getParams(selection_name)
# this also prevents to be called directly
assert 'node_uid' in kw
mirror_section_relative_url = None
if kw.get('mirror_section_uid'):
mirror_section_relative_url =\
getObject(kw['mirror_section_uid']).getRelativeUrl()
payment_uid = kw.get('payment_uid', None)
portal_type_filter = 0
if 'parent_portal_type' in params:
portal_type_filter = 1
portal_type_list = params['parent_portal_type']
total_debit = 0
total_credit = 0
total_debit_price = 0
total_credit_price = 0
at_date = (from_date - 1).latestTime()
inventory_query = {
'at_date': at_date, # this is not to_date
'grouping_query': ComplexQuery(
Query(grouping_reference=None),
Query(grouping_date=at_date, range="min"),
operator="OR"),
'simulation_state': params['simulation_state'],
'node_uid': kw['node_uid'],
'portal_type': portal.getPortalAccountingMovementTypeList(),
'section_uid': params['section_uid'],
'sort_on': (
('stock.date', 'ASC'),
('stock.uid', 'ASC'),
)
}
if kw.get('mirror_section_uid'):
inventory_query['mirror_section_uid'] = kw['mirror_section_uid']
if kw.get('payment_uid'):
inventory_query['payment_uid'] = kw['payment_uid']
if project_uid:
inventory_query['project_uid'] = project_uid
if function:
inventory_query['function_category'] = function
if 'parent_portal_type' in params:
portal_type_list = params['parent_portal_type']
# only apply this filter if not all portal_types where selected,
# because it is then unnecessary.
if set(portal_type_list) != set(portal.getPortalAccountingTransactionTypeList()):
inventory_query['parent_portal_type'] = portal_type_list
line_list = []
for brain in portal.Base_zGetNotGroupedMovementList(
at_date=(from_date - 1).latestTime(), # this is not to_date
simulation_state=params['simulation_state'],
node_uid=[kw['node_uid']],
portal_type=portal.getPortalAccountingMovementTypeList(),
section_uid=params['section_uid']):
# manually filter out not interesting lines
# XXX this is because Base_zGetNotGroupedMovementList is really
# minimalistic
if mirror_section_relative_url and \
brain.mirror_section_relative_url != mirror_section_relative_url:
continue
for brain in portal.portal_simulation.getMovementHistoryList(**inventory_query):
mvt = brain.getObject()
transaction = mvt.getParentValue()
if portal_type_filter and \
transaction.getPortalType() not in portal_type_list:
continue
is_source = (brain.mirror_section_relative_url == mvt.getDestinationSection())
if is_source:
if payment_uid and mvt.getSourcePaymentUid() != payment_uid:
continue
if project_uid and mvt.getSourceProjectUid() != project_uid:
continue
if function and not (mvt.getSourceFunction() or '').startswith(function):
continue
specific_reference = transaction.getSourceReference()
mirror_section_title = mvt.getDestinationSectionTitle()
section_title = mvt.getSourceSectionTitle()
else:
if payment_uid and mvt.getDestinationPaymentUid() != payment_uid:
continue
if project_uid and mvt.getDestinationProjectUid() != project_uid:
continue
if function and not (mvt.getDestinationFunction() or '').startswith(function):
continue
specific_reference = transaction.getDestinationReference()
mirror_section_title = mvt.getSourceSectionTitle()
section_title = mvt.getDestinationSectionTitle()
debit = max(brain.total_quantity, 0)
total_debit += debit
......@@ -78,10 +70,6 @@ for brain in portal.Base_zGetNotGroupedMovementList(
credit_price = max(-brain.total_price, 0)
total_credit_price += credit_price
brain_date = brain.date
if mvt.getStartDate():
brain_date = brain_date.toZone(mvt.getStartDate().timezone())
line = Object(uid='new_000',
total_price=brain.total_price,
date=brain.date,
......
......@@ -1226,6 +1226,7 @@ class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase):
start_date=DateTime(2006, 2, 4),
lines=(dict(source_value=account_module.receivable,
grouping_reference='B',
grouping_date=DateTime(2006, 3, 1),
source_debit=400.0),
dict(source_value=account_module.payable,
source_credit=400.0)))
......@@ -1243,6 +1244,7 @@ class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase):
source_debit=400.0),
dict(source_value=account_module.receivable,
grouping_reference='B',
grouping_date=DateTime(2006, 3, 1),
source_credit=400.0)))
t4.stop()
t4.deliver()
......@@ -1347,6 +1349,7 @@ class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase):
start_date=DateTime(2006, 2, 2),
lines=(dict(source_value=account_module.receivable,
grouping_reference='A',
grouping_date=DateTime(2006, 2, 25, 2, 3),
source_debit=200.0),
dict(source_value=account_module.payable,
source_credit=200.0)))
......@@ -1366,6 +1369,7 @@ class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase):
source_debit=200.0),
dict(source_value=account_module.receivable,
grouping_reference='A',
grouping_date=DateTime(2006, 2, 25, 2, 3),
source_credit=200.0)))
# we validate t2 later, otherwise grouping reference will be cleaned up
t2.stop()
......
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