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

display detailed debit & credit, not only the balance



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13168 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 79e6864d
......@@ -72,6 +72,7 @@
from Products.PythonScripts.standard import Object\n
portal = context.getPortalObject()\n
request = portal.REQUEST\n
precision = 2 # XXX M9 use hardcoded precision for now\n
\n
account = request.get(\'account\', \'\')\n
at_date = request[\'at_date\']\n
......@@ -146,9 +147,10 @@ for account_value in account_value_list:\n
transaction = brain.getObject().getParentValue()\n
dunning_info = transaction.SaleInvoiceTransaction_getDunningInfo()\n
\n
debit = max(brain.total_price, 0)\n
qty = round(brain.total_price, precision)\n
debit = max(qty, 0)\n
total_debit += debit\n
credit = max(-brain.total_price, 0)\n
credit = max(-qty, 0)\n
total_credit += credit\n
\n
movement_list.append(\n
......@@ -251,6 +253,7 @@ return report_section_list\n
<string>context</string>
<string>portal</string>
<string>request</string>
<string>precision</string>
<string>account</string>
<string>_getitem_</string>
<string>at_date</string>
......@@ -279,6 +282,8 @@ return report_section_list\n
<string>brain</string>
<string>transaction</string>
<string>dunning_info</string>
<string>round</string>
<string>qty</string>
<string>max</string>
<string>debit</string>
<string>credit</string>
......
......@@ -75,6 +75,8 @@ request = context.REQUEST\n
cache_storage = request.other\n
portal = context.portal_url.getPortalObject()\n
N_ = portal.Base_translateString\n
precision = 2 # XXX M9 uses EUR, so we hardcode 2 places for now\n
\n
\n
at_date = request[\'at_date\']\n
from_date = request.get(\'from_date\', None) or at_date\n
......@@ -119,9 +121,24 @@ def getAccountClass(account_url):\n
# fr / m9 / ${classe} / ...\n
classe = account.getGap().split(\'/\')[2]\n
# XXX this can raise with bad account. add a constraint checker on accounts\n
# XXX also this only work if you have only m9 installed. But anyway, it\'s\n
# not planned to support m9 and other accounting version on the same\n
# instance.\n
account_class_cache[account_url] = classe\n
return classe\n
\n
origin_id_cache = {}\n
def getOriginId(origin_url):\n
try:\n
return origin_id_cache[origin_url]\n
except KeyError:\n
origin = portal.portal_categories.origin.restrictedTraverse(origin_url)\n
origin_id = origin.getId()\n
if origin_id in portal.portal_types.objectIds():\n
origin_id = \'\'\n
origin_id_cache[origin_url] = origin_id\n
return origin_id\n
\n
for brain in simtool.getMovementHistoryList(\n
from_date=from_date.earliestTime(),\n
at_date=at_date.latestTime(),\n
......@@ -133,23 +150,32 @@ for brain in simtool.getMovementHistoryList(\n
if payment_mode_url and not \\\n
mvt.getPaymentMode(\'\').startswith(payment_mode_url):\n
continue\n
origin = mvt.getOriginId()\n
sheet = mvt.getParentValue().getAggregateTitle(portal_type=\'Invoice Transmission Sheet\')\n
\n
origin = getOriginId(mvt.getOrigin())\n
sheet = mvt.getParentValue().getAggregateTitle(\n
portal_type=\'Invoice Transmission Sheet\')\n
if brain.node_relative_url:\n
# per account and origin\n
account = per_account_and_origin_cache.setdefault(\n
brain.node_relative_url, {})\n
qty = brain.total_price or 0\n
total = account.setdefault(origin, 0)\n
account[origin] = total + qty\n
qty = round(brain.total_price or 0, precision)\n
debit = max(qty, 0)\n
credit = max(-qty, 0)\n
\n
total_debit, total_credit = account.get(origin, (0, 0))\n
account[origin] = ( total_debit + debit, total_credit + credit )\n
# per origin and sheet\n
origin_cache = per_origin_and_sheet_cache.setdefault(origin, {})\n
total = origin_cache.get((sheet, brain.node_relative_url), 0)\n
origin_cache[(sheet, brain.node_relative_url)] = total + qty\n
total_debit, total_credit = origin_cache.get(\n
(sheet, brain.node_relative_url), (0, 0))\n
origin_cache[(sheet, brain.node_relative_url)] = \\\n
( total_debit + debit,\n
total_credit + credit )\n
# per account class\n
cache = per_account_cache[getAccountClass(brain.node_relative_url)]\n
total = cache.get(brain.node_relative_url, 0)\n
cache[brain.node_relative_url] = total + qty\n
total_debit, total_credit = cache.get(brain.node_relative_url, (0, 0))\n
cache[brain.node_relative_url] = ( total_debit + debit,\n
total_credit + credit )\n
\n
report_section_list = [ ReportSection(\n
title=N_(\'Transactions\'),\n
......@@ -237,6 +263,7 @@ return report_section_list\n
<string>cache_storage</string>
<string>portal</string>
<string>N_</string>
<string>precision</string>
<string>_getitem_</string>
<string>at_date</string>
<string>None</string>
......@@ -254,14 +281,21 @@ return report_section_list\n
<string>per_account_cache</string>
<string>account_class_cache</string>
<string>getAccountClass</string>
<string>origin_id_cache</string>
<string>getOriginId</string>
<string>_getiter_</string>
<string>brain</string>
<string>mvt</string>
<string>origin</string>
<string>sheet</string>
<string>account</string>
<string>round</string>
<string>qty</string>
<string>total</string>
<string>max</string>
<string>debit</string>
<string>credit</string>
<string>total_debit</string>
<string>total_credit</string>
<string>_write_</string>
<string>origin_cache</string>
<string>cache</string>
......
......@@ -73,17 +73,16 @@ line_list = []\n
cache_storage = context.REQUEST.other\n
selection_name = \'accounting_selection\'\n
accounting_movement_type_list = context.getPortalAccountingMovementTypeList()\n
precision = 2 # XXX M9 uses EUR for now\n
\n
stool = context.getPortalObject().portal_selections\n
portal = context.getPortalObject()\n
stool = portal.portal_selections\n
selection = stool.getSelectionFor(selection_name)\n
per_account_and_origin_cache = cache_storage.setdefault(\n
\'m9_report_per_account_and_origin_summary\', {})\n
per_origin_and_sheet_cache = cache_storage.setdefault(\n
\'m9_report_per_origin_and_sheet_summary\', {})\n
\n
simtool = context.portal_simulation\n
# FIXME: how to pass pass parameter in the selection without\n
# making them persistent ?\n
context.REQUEST.other[\'src__\'] = 1\n
context.REQUEST.other[\'no_limit\'] = 1\n
context.REQUEST.other[\'search_result_keys\'] = [\'catalog.uid\']\n
......@@ -97,9 +96,21 @@ def getPaymentModeCodification(payment_mode):\n
payment_mode_cache[payment_mode] = category_title\n
return category_title\n
\n
origin_id_cache = {}\n
def getOriginId(origin_url):\n
try:\n
return origin_id_cache[origin_url]\n
except KeyError:\n
origin = portal.portal_categories.origin.restrictedTraverse(origin_url)\n
origin_id = origin.getId()\n
if origin_id in portal.portal_types.objectIds():\n
origin_id = \'\'\n
origin_id_cache[origin_url] = origin_id\n
return origin_id\n
\n
# call getMovementHistory by building a subquery with accounting module\n
# selection\'s query, using the src__=1 trick from above\n
for brain in simtool.getMovementHistoryList(\n
for brain in portal.portal_simulation.getMovementHistoryList(\n
where_expression="catalog.parent_uid IN (%s)" %\n
stool.callSelectionFor(selection_name),\n
section_category=selection.getParams().get(\'section_category\'),\n
......@@ -109,14 +120,18 @@ for brain in simtool.getMovementHistoryList(\n
\n
movement = brain.getObject()\n
transaction = movement.getParentValue()\n
origin = transaction.getProperty(\'origin_id\')\n
origin = getOriginId(transaction.getProperty(\'origin\'))\n
sheet = transaction.getProperty(\'aggregate_title\')\n
payment_mode_codification = getPaymentModeCodification(\n
transaction.getPaymentMode())\n
qty = round((brain.total_price or 0), precision)\n
debit = max(qty, 0)\n
credit = max(-qty, 0)\n
\n
obj = Object(\n
parent_portal_type=transaction.getTranslatedPortalType(),\n
parent_int_index="%05d" % transaction.getIntIndex(0),\n
parent_int_index=transaction.getIntIndex() and\n
("%05d" % transaction.getIntIndex()) or \'\',\n
payment_mode_codification=payment_mode_codification,\n
parent_aggregate_title=sheet,\n
parent_origin_id=origin,\n
......@@ -125,25 +140,26 @@ for brain in simtool.getMovementHistoryList(\n
section_uid=brain.section_uid,\n
node_relative_url=brain.node_relative_url,\n
getObject=brain.getObject,\n
# asContext=movement.asContext,\n
# asContext=lambda *args, **kw: movement, # optim ?\n
# Movement_getExplanationUrl=movement.Movement_getExplanationUrl,\n
\n
date=brain.date,\n
debit=max(brain.total_price, 0),\n
credit=max(-(brain.total_price or 0), 0), )\n
debit=debit,\n
credit=credit )\n
line_list.append(obj)\n
\n
if brain.node_relative_url:\n
# per account and origin\n
account = per_account_and_origin_cache.setdefault(\n
brain.node_relative_url, {})\n
total = account.setdefault(origin, 0)\n
account[origin] = total + (brain.total_price or 0)\n
total_debit, total_credit = account.get(origin, (0, 0))\n
account[origin] = ( total_debit + debit, total_credit + credit )\n
\n
# per origin and sheet\n
origin_cache = per_origin_and_sheet_cache.setdefault(origin, {})\n
total = origin_cache.setdefault((sheet, brain.node_relative_url), 0)\n
origin_cache[(sheet, brain.node_relative_url)] = total + (brain.total_price or 0)\n
total_debit, total_credit = origin_cache.get(\n
(sheet, brain.node_relative_url), (0, 0))\n
origin_cache[(sheet, brain.node_relative_url)] = (\n
total_debit + debit,\n
total_credit + credit )\n
\n
return line_list\n
</string> </value>
......@@ -197,15 +213,18 @@ return line_list\n
<string>cache_storage</string>
<string>selection_name</string>
<string>accounting_movement_type_list</string>
<string>precision</string>
<string>portal</string>
<string>stool</string>
<string>selection</string>
<string>per_account_and_origin_cache</string>
<string>per_origin_and_sheet_cache</string>
<string>simtool</string>
<string>_write_</string>
<string>None</string>
<string>payment_mode_cache</string>
<string>getPaymentModeCodification</string>
<string>origin_id_cache</string>
<string>getOriginId</string>
<string>_getiter_</string>
<string>brain</string>
<string>movement</string>
......@@ -213,10 +232,15 @@ return line_list\n
<string>origin</string>
<string>sheet</string>
<string>payment_mode_codification</string>
<string>round</string>
<string>qty</string>
<string>max</string>
<string>debit</string>
<string>credit</string>
<string>obj</string>
<string>account</string>
<string>total</string>
<string>total_debit</string>
<string>total_credit</string>
<string>origin_cache</string>
</tuple>
</value>
......
......@@ -69,7 +69,7 @@
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.PythonScripts.standard import Object\n
cache_storage = context.REQUEST.other\n
cache_storage = container.REQUEST.other\n
line_list = []\n
portal = context.getPortalObject()\n
total_debit = 0\n
......@@ -82,10 +82,9 @@ account_list.sort()\n
for account_url in account_list:\n
values = account_cache[account_url]\n
account_title = portal.restrictedTraverse(account_url).Account_getFormattedTitle()\n
for origin, total_price in values.items():\n
debit = max(total_price, 0)\n
\n
for origin, (debit, credit) in values.items():\n
total_debit += debit\n
credit = -min(total_price, 0)\n
total_credit += credit\n
line_list.append(Object(uid=\'new_\',\n
origin=origin,\n
......@@ -142,9 +141,10 @@ return line_list\n
<string>Products.PythonScripts.standard</string>
<string>Object</string>
<string>_getattr_</string>
<string>context</string>
<string>container</string>
<string>cache_storage</string>
<string>line_list</string>
<string>context</string>
<string>portal</string>
<string>total_debit</string>
<string>total_credit</string>
......@@ -156,10 +156,7 @@ return line_list\n
<string>values</string>
<string>account_title</string>
<string>origin</string>
<string>total_price</string>
<string>max</string>
<string>debit</string>
<string>min</string>
<string>credit</string>
<string>_write_</string>
</tuple>
......
......@@ -81,10 +81,8 @@ account_list = account_cache.keys()\n
account_list.sort()\n
\n
for account_url in account_list:\n
total_price = account_cache[account_url]\n
debit = round(max(total_price, 0), 2)\n
debit, credit = account_cache[account_url]\n
total_debit += debit\n
credit = round(-min(total_price, 0), 2)\n
total_credit += credit\n
\n
line_list.append(Object(uid=\'new_\',\n
......@@ -158,11 +156,7 @@ return line_list\n
<string>account_list</string>
<string>_getiter_</string>
<string>account_url</string>
<string>total_price</string>
<string>round</string>
<string>max</string>
<string>debit</string>
<string>min</string>
<string>credit</string>
<string>_write_</string>
</tuple>
......
......@@ -69,7 +69,7 @@
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.PythonScripts.standard import Object\n
cache_storage = context.REQUEST.other\n
cache_storage = container.REQUEST.other\n
line_list = []\n
portal = context.getPortalObject()\n
total_debit = 0\n
......@@ -83,13 +83,9 @@ for origin in origin_list:\n
values = origin_cache[origin]\n
items = values.items()\n
items.sort()\n
for (sheet, account_url), total_price in items:\n
for (sheet, account_url), (debit, credit) in items:\n
account = portal.restrictedTraverse(account_url)\n
\n
# XXX assume a precision of 2 places, because we use EUR for M9\n
debit = round(max(total_price, 0), 2)\n
total_debit += debit\n
credit = round(-min(total_price, 0), 2)\n
total_credit += credit\n
line_list.append(Object(uid=\'new_\',\n
origin=origin,\n
......@@ -149,9 +145,10 @@ return line_list\n
<string>Products.PythonScripts.standard</string>
<string>Object</string>
<string>_getattr_</string>
<string>context</string>
<string>container</string>
<string>cache_storage</string>
<string>line_list</string>
<string>context</string>
<string>portal</string>
<string>total_debit</string>
<string>total_credit</string>
......@@ -164,13 +161,9 @@ return line_list\n
<string>items</string>
<string>sheet</string>
<string>account_url</string>
<string>total_price</string>
<string>account</string>
<string>round</string>
<string>max</string>
<string>debit</string>
<string>min</string>
<string>credit</string>
<string>account</string>
<string>_write_</string>
</tuple>
</value>
......
79
\ No newline at end of file
82
\ No newline at end of file
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