Commit 0d00bfe0 authored by Kevin Deldycke's avatar Kevin Deldycke

* Remove previous hack to round value.

  * Use generic script Base_getPreferredPrecision and Base_getRoundValue to get the right amount of money.
  * Clean up code (supress old-school 80-character limitation, regroup similar statement together for easy human-eye parsing).
  * Use section_portal_type_list to break acquisition of 'group' property from Person to Organisaiton.
  * Show the the right date on the previous balance line.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6367 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b3f8265c
...@@ -66,140 +66,144 @@ ...@@ -66,140 +66,144 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>LOG=lambda message: context.log("Account_getAccountingTransactionList", message)\n
LOG=lambda message: context.log("Account_getAccountingTransactionList", message)\n
\n \n
from Products.ERP5Type.Document import newTempAccountingTransaction\n from Products.ERP5Type.Document import newTempAccountingTransaction\n
\n \n
# WARNINGS by Vincent (2006/01/31)\n precision = context.Base_getPreferredPrecision()\n
# This hack do a rounding on intermediate amount values.\n params = {"omit_simulation": 1}\n
# This prevent floating point bugs such as :\n pref = context.getPortalObject().portal_preferences\n
# >>> 54.99\n r_ = lambda x: context.Base_getRoundValue(x, precision)\n
# 54.990000000000002\n
# kev: isn\'t it better to set precision as an integer ?\n
precision = float(10 ** context.Section_getCurrencyPrecision())\n
\n \n
kwd={"omit_simulation" : 1}\n ###\n
# read settings from user preference\n # Get the \'from_date\' parameter\n
preference = context.getPortalObject().portal_preferences\n if kw.get(\'no_from_date\', 0):\n
if kw.get(\'no_from_date\', 0) :\n
from_date = None\n from_date = None\n
else :\n else:\n
from_date = kw.get(\'from_date\', preference\\\n from_date = kw.get( \'from_date\'\n
.getPreferredAccountingTransactionFromDate())\n , pref.getPreferredAccountingTransactionFromDate()\n
)\n
if from_date:\n if from_date:\n
kwd[\'from_date\'] = from_date\n params[\'from_date\'] = from_date\n
at_date = kw.get(\'at_date\', preference\\\n
.getPreferredAccountingTransactionAtDate())\n
if at_date :\n
kwd[\'at_date\'] = at_date\n
simulation_state = kw.get(\'simulation_state\', preference\\\n
.getPreferredAccountingTransactionSimulationStateList())\n
if simulation_state :\n
kwd[\'transaction_simulation_state\'] = simulation_state\n
section_category = preference\\\n
.getPreferredAccountingTransactionSectionCategory()\n
if section_category :\n
kwd[\'transaction_section_category\'] = section_category\n
kwd[\'section_category\'] = section_category\n
\n \n
###\n
# Get the \'simulation_state\' parameter\n
simulation_state = kw.get( \'simulation_state\'\n
, pref.getPreferredAccountingTransactionSimulationStateList()\n
)\n
if simulation_state:\n
params[\'transaction_simulation_state\'] = simulation_state\n
\n
###\n
# Get the \'section_category\' parameter\n
section_category = pref.getPreferredAccountingTransactionSectionCategory()\n
if section_category:\n
params[\'transaction_section_category\'] = section_category\n
\n
###\n
# Get payment and mirror related parameters\n
# Special filtering for GL\n # Special filtering for GL\n
# XXX this script could also be used for entity / bank account ?\n # XXX this script could also be used for entity / bank account ?\n
MARKER = []\n MARKER = []\n
payment_uid = kw.get(\'payment_uid\', MARKER)\n no_payment_uid = kw.get(\'no_source_uid\', MARKER)\n
if payment_uid is not MARKER:\n
kwd[\'payment_uid\'] = payment_uid\n
no_payment_uid = kw.get(\'no_payment_uid\', MARKER)\n
if no_payment_uid is not MARKER:\n
kwd[\'no_payment_uid\'] = 1\n
\n
mirror_section_uid = kw.get(\'mirror_section_uid\', MARKER)\n
if mirror_section_uid is not MARKER:\n
kwd[\'mirror_section_uid\'] = mirror_section_uid\n
no_mirror_section_uid = kw.get(\'no_mirror_section_uid\', MARKER)\n no_mirror_section_uid = kw.get(\'no_mirror_section_uid\', MARKER)\n
if no_mirror_section_uid is not MARKER:\n payment_uid = kw.get(\'source_uid\', MARKER)\n
kwd[\'no_mirror_section_uid\'] = 1\n mirror_section_uid = kw.get(\'mirror_section_uid\', MARKER)\n
\n if no_payment_uid is not MARKER: params[\'no_payment_uid\'] = 1\n
node_uid = kw.get(\'node_uid\', MARKER)\n if no_mirror_section_uid is not MARKER: params[\'no_mirror_section_uid\'] = 1\n
if node_uid is not MARKER:\n if payment_uid is not MARKER: params[\'payment_uid\'] = payment_uid\n
kwd[\'node_uid\'] = node_uid\n if mirror_section_uid is not MARKER: params[\'mirror_section_uid\'] = mirror_section_uid\n
kwd[\'getUid\'] = node_uid # Account_zGetAccountingTransactionList compat\n
\n
# TODO: optimize this part\n
# ie evaluate only the displayed lines\n
\n \n
# Initialize the final line list and the net balance\n
new_result = []\n new_result = []\n
#LOG(\'kwd %s\' % kwd)\n
#LOG(\'SQL:\\n%s\'%context.Account_zGetAccountingTransactionList(src__=1, **kwd))\n
result = context.Account_zGetAccountingTransactionList(**kwd)\n
\n
net_balance = 0.0\n net_balance = 0.0\n
\n \n
if from_date not in (None, MARKER) and kw.get(\'from_date_summary\', 0) :\n ### Add a previous balance line\n
get_inventory_kw = {}\n if from_date not in (None, MARKER) and kw.get(\'from_date_summary\', 0):\n
get_inventory_kw[\'omit_simulation\'] = 1\n \n
get_inventory_kw[\'section_category\'] = section_category\n ## Normal use of inventory stuff\n
get_inventory_kw[\'node_uid\'] = kw.get(\'node_uid\', context.getUid())\n get_inventory_kw = { \'omit_simulation\' : 1\n
if simulation_state :\n , \'section_category\' : section_category\n
get_inventory_kw[\'simulation_state\'] = simulation_state\n , \'node_uid\' : kw.get(\'node_uid\', context.getUid())\n
if mirror_section_uid is not MARKER :\n , \'to_date\' : from_date\n
get_inventory_kw[\'mirror_section_uid\'] = mirror_section_uid\n , \'section_portal_type_list\': [\'Organisation\']\n
if payment_uid is not MARKER :\n }\n
get_inventory_kw[\'payment_uid\'] = payment_uid\n if simulation_state : get_inventory_kw[\'simulation_state\'] = simulation_state\n
if payment_uid is not MARKER : get_inventory_kw[\'payment_uid\'] = payment_uid\n
if mirror_section_uid is not MARKER: get_inventory_kw[\'mirror_section_uid\'] = mirror_section_uid\n
\n \n
getInventoryAssetPrice = context.getPortalObject()\\\n getInventoryAssetPrice = context.getPortalObject().portal_simulation.getInventoryAssetPrice\n
.portal_simulation.getInventoryAssetPrice\n previous_total_debit = r_(getInventoryAssetPrice(omit_output = 1, **get_inventory_kw))\n
last_total_debit = getInventoryAssetPrice(omit_output=1,\n previous_total_credit = r_(getInventoryAssetPrice(omit_input = 1, **get_inventory_kw))\n
to_date=from_date, **get_inventory_kw)\n
last_total_credit = getInventoryAssetPrice(omit_input=1,\n
to_date=from_date, **get_inventory_kw)\n
if last_total_credit != 0 :\n
last_total_credit = - last_total_credit\n
\n \n
if last_total_debit != 0 or last_total_credit != 0 :\n if previous_total_credit != 0 :\n
from_date_summary = newTempAccountingTransaction(\n previous_total_credit = - previous_total_credit\n
context.getPortalObject(), "temp_%s" % context.getUid())\n \n
# Add a new line at the top of the listbox called "Previous Balance"\n
if previous_total_credit != 0 or previous_total_debit!= 0:\n
net_balance = r_(previous_total_debit - previous_total_credit)\n
from_date_summary = newTempAccountingTransaction( context.getPortalObject()\n
, "temp_%s" % context.getUid()\n
)\n
from_date_summary.setUid(\'new_000\')\n from_date_summary.setUid(\'new_000\')\n
net_balance = (last_total_debit - last_total_credit) * precision # WARNING : See Above\n
from_date_summary.edit( \\\n from_date_summary.edit( \\\n
title = context.Base_translateString("Previous Balance")\n title = context.Base_translateString("Previous Balance")\n
, date = from_date - 1\n
, translated_portal_type = ""\n , translated_portal_type = ""\n
, translated_simulation_state_title = ""\n , translated_simulation_state_title = ""\n
, net_balance = net_balance / precision\n , net_balance = net_balance\n
, balance = net_balance / precision\n , balance = net_balance\n
, credit = last_total_credit\n , credit = previous_total_credit\n
, debit = last_total_debit\n , debit = previous_total_debit\n
, current_transaction_line_path = None\n , current_transaction_line_path = None\n
, third_party = None\n , third_party = None\n
, date = from_date\n
)\n )\n
new_result.append(from_date_summary)\n new_result.append(from_date_summary)\n
\n \n
\n
###\n
# Get the \'at_date\' parameter\n
at_date = kw.get( \'at_date\'\n
, pref.getPreferredAccountingTransactionAtDate()\n
)\n
if at_date:\n
params[\'at_date\'] = at_date\n
\n
###\n
# Get the node UID\n
node_uid = kw.get(\'node_uid\', MARKER)\n
if node_uid is not MARKER:\n
params[\'node_uid\'] = node_uid\n
params[\'getUid\'] = node_uid # Account_zGetAccountingTransactionList compat\n
\n
###\n
# Get the list of lines\n
# TODO: optimize this part by giving necessary parameters to only get the displayed lines\n
# LOG(\'kwd %s\' % kwd)\n
# LOG(\'SQL:\\n%s\'%context.Account_zGetAccountingTransactionList(src__=1, **params))\n
result = context.Account_zGetAccountingTransactionList(**params)\n
\n
if src__:\n if src__:\n
return result\n return result\n
\n \n
for l in result:\n for l in result:\n
o = l.getObject()\n o = l.getObject()\n
net_balance += (l.balance or 0.0) * precision # WARNING : See above\n net_balance = r_(net_balance) + r_(l.balance)\n
if o is not None:\n if o is not None:\n
c = o.asContext( net_balance = net_balance / precision, # WARNING : See above\n c = o.asContext( net_balance = r_(net_balance)\n
balance = l.balance,\n , balance = r_(l.balance)\n
credit = l.credit,\n , credit = r_(l.credit)\n
debit = l.debit,\n , debit = r_(l.debit)\n
date = l.date,\n , date = l.date\n
current_transaction_line_path =\n , current_transaction_line_path = l.current_transaction_line_path\n
l.current_transaction_line_path,\n , third_party = l.third_party\n
third_party = l.third_party,\n , payment = l.payment_uid\n
payment = l.payment_uid,\n , specific_reference = l.specific_reference\n
specific_reference = l.specific_reference,\n )\n
)\n
new_result.append(c)\n new_result.append(c)\n
\n \n
return new_result\n return new_result\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_code</string> </key> <key> <string>_code</string> </key>
...@@ -250,33 +254,33 @@ return new_result\n ...@@ -250,33 +254,33 @@ return new_result\n
<string>LOG</string> <string>LOG</string>
<string>Products.ERP5Type.Document</string> <string>Products.ERP5Type.Document</string>
<string>newTempAccountingTransaction</string> <string>newTempAccountingTransaction</string>
<string>float</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>precision</string> <string>precision</string>
<string>kwd</string> <string>params</string>
<string>preference</string> <string>pref</string>
<string>r_</string>
<string>None</string> <string>None</string>
<string>from_date</string> <string>from_date</string>
<string>_write_</string> <string>_write_</string>
<string>at_date</string>
<string>simulation_state</string> <string>simulation_state</string>
<string>section_category</string> <string>section_category</string>
<string>MARKER</string> <string>MARKER</string>
<string>payment_uid</string>
<string>no_payment_uid</string> <string>no_payment_uid</string>
<string>mirror_section_uid</string>
<string>no_mirror_section_uid</string> <string>no_mirror_section_uid</string>
<string>node_uid</string> <string>payment_uid</string>
<string>mirror_section_uid</string>
<string>new_result</string> <string>new_result</string>
<string>_apply_</string>
<string>result</string>
<string>net_balance</string> <string>net_balance</string>
<string>get_inventory_kw</string> <string>get_inventory_kw</string>
<string>getInventoryAssetPrice</string> <string>getInventoryAssetPrice</string>
<string>last_total_debit</string> <string>_apply_</string>
<string>last_total_credit</string> <string>previous_total_debit</string>
<string>previous_total_credit</string>
<string>from_date_summary</string> <string>from_date_summary</string>
<string>at_date</string>
<string>node_uid</string>
<string>result</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>l</string> <string>l</string>
<string>o</string> <string>o</string>
......
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