Commit 928445b5 authored by Kevin Deldycke's avatar Kevin Deldycke

Make the code very similar to other _getAccountingTransactionList script to...

Make the code very similar to other _getAccountingTransactionList script to prepare the unification of those scripts.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6421 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eb31529e
......@@ -66,144 +66,133 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>LOG=lambda message: context.log("Account_getAccountingTransactionList", message)\n
\n
from Products.ERP5Type.Document import newTempAccountingTransaction\n
\n
<value> <string encoding="cdata"><![CDATA[
src__ = 0\n
if kw.has_key(\'src__\'): src__ = kw[\'src__\']\n
precision = context.Base_getPreferredPrecision()\n
params = {"omit_simulation": 1}\n
pref = context.getPortalObject().portal_preferences\n
r_ = lambda x: context.Base_getRoundValue(x, precision)\n
\n
###\n
# Get the \'from_date\' parameter\n
if kw.get(\'no_from_date\', 0):\n
from_date = None\n
else:\n
from_date = kw.get( \'from_date\'\n
, pref.getPreferredAccountingTransactionFromDate()\n
)\n
if from_date:\n
params[\'from_date\'] = from_date\n
# Read settings from user preference\n
preference = context.getPortalObject().portal_preferences\n
simulation_state = preference.getPreferredAccountingTransactionSimulationStateList()\n
section_category = preference.getPreferredAccountingTransactionSectionCategory()\n
from_date = preference.getPreferredAccountingTransactionFromDate()\n
at_date = preference.getPreferredAccountingTransactionAtDate()\n
\n
# Build the common inventory dict\n
params = {}\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
if kw.get(\'no_from_date\', 0): from_date = None\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
if simulation_state: params[\'simulation_state\'] = simulation_state\n
if section_category: params[\'section_category\'] = section_category\n
\n
###\n
# Get payment and mirror related parameters\n
# Special filtering for GL\n
# XXX this script could also be used for entity / bank account ?\n
MARKER = []\n
no_payment_uid = kw.get(\'no_source_uid\', MARKER)\n
no_payment_uid = kw.get(\'no_payment_uid\', MARKER)\n
payment_uid = kw.get( \'payment_uid\', MARKER)\n
no_mirror_section_uid = kw.get(\'no_mirror_section_uid\', MARKER)\n
payment_uid = kw.get(\'source_uid\', MARKER)\n
mirror_section_uid = kw.get(\'mirror_section_uid\', MARKER)\n
mirror_section_uid = kw.get( \'mirror_section_uid\', MARKER)\n
# Try alternate method to get payment_uid\n
if no_payment_uid is MARKER: no_payment_uid = kw.get(\'no_source_uid\', MARKER)\n
if payment_uid is MARKER: payment_uid = kw.get( \'source_uid\', MARKER)\n
# Save results in the dict\n
if no_payment_uid is not MARKER: params[\'no_payment_uid\'] = 1\n
if payment_uid is not MARKER: params[ \'payment_uid\'] = payment_uid\n
if no_mirror_section_uid is not MARKER: params[\'no_mirror_section_uid\'] = 1\n
if payment_uid is not MARKER: params[\'payment_uid\'] = payment_uid\n
if mirror_section_uid is not MARKER: params[\'mirror_section_uid\'] = mirror_section_uid\n
\n
# Initialize the final line list and the net balance\n
new_result = []\n
net_balance = 0.0\n
if mirror_section_uid is not MARKER: params[ \'mirror_section_uid\'] = mirror_section_uid\n
\n
### Add a previous balance line\n
if from_date not in (None, MARKER) and kw.get(\'from_date_summary\', 0):\n
\n
## Normal use of inventory stuff\n
get_inventory_kw = { \'omit_simulation\' : 1\n
, \'section_category\' : section_category\n
, \'node_uid\' : kw.get(\'node_uid\', context.getUid())\n
, \'to_date\' : from_date\n
, \'section_portal_type_list\': [\'Organisation\']\n
}\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
# Get node_uid parameters\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
getInventoryAssetPrice = context.getPortalObject().portal_simulation.getInventoryAssetPrice\n
previous_total_debit = r_(getInventoryAssetPrice(omit_output = 1, **get_inventory_kw))\n
previous_total_credit = r_(getInventoryAssetPrice(omit_input = 1, **get_inventory_kw))\n
# Create the related accouting line list\n
new_result = []\n
net_balance = 0.0\n
\n
if previous_total_credit != 0 :\n
previous_total_credit = - previous_total_credit\n
# Create a new parameter list to get the previous balance\n
get_inventory_kw = params.copy()\n
get_inventory_kw.update({ \'omit_simulation\' : 1\n
, \'to_date\' : from_date\n
, \'section_portal_type_list\': [\'Organisation\']\n
, \'stat\' : 1\n
})\n
get_inventory_kw[\'node_uid\'] = kw.get(\'node_uid\', 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.edit( \\\n
title = context.Base_translateString("Previous Balance")\n
, date = from_date - 1\n
, translated_portal_type = ""\n
, translated_simulation_state_title = ""\n
, net_balance = net_balance\n
, balance = net_balance\n
, credit = previous_total_credit\n
, debit = previous_total_debit\n
, current_transaction_line_path = None\n
, third_party = None\n
)\n
new_result.append(from_date_summary)\n
# Get previous debit and credit\n
getInventoryAssetPrice = context.getPortalObject().portal_simulation.getInventoryAssetPrice\n
previous_total_debit = getInventoryAssetPrice(omit_output=1, **get_inventory_kw)\n
previous_total_credit = getInventoryAssetPrice(omit_input =1, **get_inventory_kw)\n
\n
# previous_total_debit = r_(previous_total_debit[0].quantity)\n
# previous_total_credit = r_(previous_total_credit[0].quantity)\n
# Get Absolute value of debit and credit\n
if previous_total_debit < 0: previous_total_debit = - previous_total_debit\n
if previous_total_credit < 0: previous_total_credit = - previous_total_credit\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
# Show the previous balance if not empty\n
if previous_total_credit != 0 or previous_total_debit != 0:\n
from Products.ERP5Type.Document import newTempAccountingTransaction\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
net_balance = r_(previous_total_debit - previous_total_credit)\n
previous_balance = newTempAccountingTransaction( context.getPortalObject()\n
, "temp_%s" % context.getUid()\n
)\n
previous_balance.setUid(\'new_000\')\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
previous_balance.edit( \\\n
title = context.Base_translateString("Previous Balance")\n
, date = from_date - 1\n
, portal_type = ""\n
, simulation_state_title = ""\n
, debit = previous_total_debit\n
, credit = previous_total_credit\n
, balance = net_balance\n
, net_balance = net_balance\n
, is_previous_balance = True\n
)\n
new_result.append(previous_balance)\n
\n
# FIXME:\n
# using listbox current page number * number of line per listbox page, you can call a\n
# ZSQL Method to initialize net_balance and calculate this only for this page.\n
#\n
# But this is just temporary because some day, erp5_accounting will be rewritten using\n
# only portal_catalog and getInventory. The Iventory API should provide a way to implement\n
# such a net_balance column (in one instruction, so that we do not need to write a wrapping\n
# list method like this one)\n
result = context.Account_zGetAccountingTransactionList( from_date = from_date\n
, at_date = at_date\n
, src__ = src__\n
, **params\n
)\n
if src__:\n
return result\n
\n
# Add related accounting lines one by one in order to calculate intermediate balance\n
for l in result:\n
o = l.getObject()\n
net_balance = r_(net_balance) + r_(l.balance)\n
net_balance += l.balance or 0.0\n
if o is not None:\n
c = o.asContext( net_balance = r_(net_balance)\n
, balance = r_(l.balance)\n
, credit = r_(l.credit)\n
, debit = r_(l.debit)\n
, date = l.date\n
c = o.asContext( net_balance = net_balance\n
, balance = l.balance\n
, credit = l.credit\n
, debit = l.debit\n
, date = l.date\n
, specific_reference = l.specific_reference\n
, current_transaction_line_path = l.current_transaction_line_path\n
, third_party = l.third_party\n
, payment = l.payment_uid\n
, specific_reference = l.specific_reference\n
)\n
new_result.append(c)\n
\n
return new_result\n
</string> </value>
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
......@@ -223,7 +212,7 @@ return new_result\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>src__=0, **kw</string> </value>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
......@@ -243,33 +232,33 @@ return new_result\n
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>1</int> </value>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>src__</string>
<string>kw</string>
<string>LOG</string>
<string>Products.ERP5Type.Document</string>
<string>newTempAccountingTransaction</string>
<string>src__</string>
<string>_getattr_</string>
<string>_getitem_</string>
<string>context</string>
<string>precision</string>
<string>params</string>
<string>pref</string>
<string>r_</string>
<string>None</string>
<string>from_date</string>
<string>_write_</string>
<string>preference</string>
<string>simulation_state</string>
<string>section_category</string>
<string>from_date</string>
<string>at_date</string>
<string>params</string>
<string>None</string>
<string>_write_</string>
<string>MARKER</string>
<string>no_payment_uid</string>
<string>no_mirror_section_uid</string>
<string>payment_uid</string>
<string>no_mirror_section_uid</string>
<string>mirror_section_uid</string>
<string>node_uid</string>
<string>new_result</string>
<string>net_balance</string>
<string>get_inventory_kw</string>
......@@ -277,9 +266,10 @@ return new_result\n
<string>_apply_</string>
<string>previous_total_debit</string>
<string>previous_total_credit</string>
<string>from_date_summary</string>
<string>at_date</string>
<string>node_uid</string>
<string>Products.ERP5Type.Document</string>
<string>newTempAccountingTransaction</string>
<string>previous_balance</string>
<string>True</string>
<string>result</string>
<string>_getiter_</string>
<string>l</string>
......@@ -296,9 +286,7 @@ return new_result\n
<item>
<key> <string>func_defaults</string> </key>
<value>
<tuple>
<int>0</int>
</tuple>
<none/>
</value>
</item>
<item>
......
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