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 @@ ...@@ -66,144 +66,133 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>LOG=lambda message: context.log("Account_getAccountingTransactionList", message)\n <value> <string encoding="cdata"><![CDATA[
\n
from Products.ERP5Type.Document import newTempAccountingTransaction\n src__ = 0\n
\n if kw.has_key(\'src__\'): src__ = kw[\'src__\']\n
precision = context.Base_getPreferredPrecision()\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 r_ = lambda x: context.Base_getRoundValue(x, precision)\n
\n \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 simulation_state = preference.getPreferredAccountingTransactionSimulationStateList()\n
from_date = None\n section_category = preference.getPreferredAccountingTransactionSectionCategory()\n
else:\n from_date = preference.getPreferredAccountingTransactionFromDate()\n
from_date = kw.get( \'from_date\'\n at_date = preference.getPreferredAccountingTransactionAtDate()\n
, pref.getPreferredAccountingTransactionFromDate()\n
)\n
if from_date:\n
params[\'from_date\'] = from_date\n
\n \n
###\n # Build the common inventory dict\n
# Get the \'simulation_state\' parameter\n params = {}\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
###\n if kw.get(\'no_from_date\', 0): from_date = None\n
# Get the \'section_category\' parameter\n \n
section_category = pref.getPreferredAccountingTransactionSectionCategory()\n if simulation_state: params[\'simulation_state\'] = simulation_state\n
if section_category:\n if section_category: params[\'section_category\'] = section_category\n
params[\'transaction_section_category\'] = section_category\n
\n \n
###\n
# Get payment and mirror related parameters\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 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 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 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 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
if mirror_section_uid is not MARKER: params[\'mirror_section_uid\'] = mirror_section_uid\n
\n \n
# Initialize the final line list and the net balance\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
# Create the related accouting line list\n
new_result = []\n new_result = []\n
net_balance = 0.0\n net_balance = 0.0\n
\n \n
### Add a previous balance line\n # Create a new parameter list to get the previous balance\n
if from_date not in (None, MARKER) and kw.get(\'from_date_summary\', 0):\n get_inventory_kw = params.copy()\n
\n get_inventory_kw.update({ \'omit_simulation\' : 1\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 , \'to_date\' : from_date\n
, \'section_portal_type_list\': [\'Organisation\']\n , \'section_portal_type_list\': [\'Organisation\']\n
}\n , \'stat\' : 1\n
if simulation_state : get_inventory_kw[\'simulation_state\'] = simulation_state\n })\n
if payment_uid is not MARKER : get_inventory_kw[\'payment_uid\'] = payment_uid\n get_inventory_kw[\'node_uid\'] = kw.get(\'node_uid\', context.getUid())\n
if mirror_section_uid is not MARKER: get_inventory_kw[\'mirror_section_uid\'] = mirror_section_uid\n \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 \n
getInventoryAssetPrice = context.getPortalObject().portal_simulation.getInventoryAssetPrice\n # previous_total_debit = r_(previous_total_debit[0].quantity)\n
previous_total_debit = r_(getInventoryAssetPrice(omit_output = 1, **get_inventory_kw))\n # previous_total_credit = r_(previous_total_credit[0].quantity)\n
previous_total_credit = r_(getInventoryAssetPrice(omit_input = 1, **get_inventory_kw))\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
if previous_total_credit != 0 :\n # Show the previous balance if not empty\n
previous_total_credit = - previous_total_credit\n if previous_total_credit != 0 or previous_total_debit != 0:\n
from Products.ERP5Type.Document import newTempAccountingTransaction\n
\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 net_balance = r_(previous_total_debit - previous_total_credit)\n
from_date_summary = newTempAccountingTransaction( context.getPortalObject()\n previous_balance = newTempAccountingTransaction( context.getPortalObject()\n
, "temp_%s" % context.getUid()\n , "temp_%s" % context.getUid()\n
)\n )\n
from_date_summary.setUid(\'new_000\')\n previous_balance.setUid(\'new_000\')\n
from_date_summary.edit( \\\n \n
previous_balance.edit( \\\n
title = context.Base_translateString("Previous Balance")\n title = context.Base_translateString("Previous Balance")\n
, date = from_date - 1\n , date = from_date - 1\n
, translated_portal_type = ""\n , portal_type = ""\n
, translated_simulation_state_title = ""\n , simulation_state_title = ""\n
, net_balance = net_balance\n
, balance = net_balance\n
, credit = previous_total_credit\n
, debit = previous_total_debit\n , debit = previous_total_debit\n
, current_transaction_line_path = None\n , credit = previous_total_credit\n
, third_party = None\n , balance = net_balance\n
, net_balance = net_balance\n
, is_previous_balance = True\n
)\n )\n
new_result.append(from_date_summary)\n new_result.append(previous_balance)\n
\n
\n \n
###\n # FIXME:\n
# Get the \'at_date\' parameter\n # using listbox current page number * number of line per listbox page, you can call a\n
at_date = kw.get( \'at_date\'\n # ZSQL Method to initialize net_balance and calculate this only for this page.\n
, pref.getPreferredAccountingTransactionAtDate()\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 )\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
# Add related accounting lines one by one in order to calculate intermediate balance\n
for l in result:\n for l in result:\n
o = l.getObject()\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 if o is not None:\n
c = o.asContext( net_balance = r_(net_balance)\n c = o.asContext( net_balance = net_balance\n
, balance = r_(l.balance)\n , balance = l.balance\n
, credit = r_(l.credit)\n , credit = l.credit\n
, debit = r_(l.debit)\n , debit = l.debit\n
, date = l.date\n , date = l.date\n
, specific_reference = l.specific_reference\n
, current_transaction_line_path = l.current_transaction_line_path\n , current_transaction_line_path = 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
)\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>
...@@ -223,7 +212,7 @@ return new_result\n ...@@ -223,7 +212,7 @@ return new_result\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>src__=0, **kw</string> </value> <value> <string>**kw</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -243,33 +232,33 @@ return new_result\n ...@@ -243,33 +232,33 @@ return new_result\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>1</int> </value> <value> <int>0</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>src__</string>
<string>kw</string> <string>kw</string>
<string>LOG</string> <string>src__</string>
<string>Products.ERP5Type.Document</string>
<string>newTempAccountingTransaction</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>_getitem_</string>
<string>context</string> <string>context</string>
<string>precision</string> <string>precision</string>
<string>params</string>
<string>pref</string>
<string>r_</string> <string>r_</string>
<string>None</string> <string>preference</string>
<string>from_date</string>
<string>_write_</string>
<string>simulation_state</string> <string>simulation_state</string>
<string>section_category</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>MARKER</string>
<string>no_payment_uid</string> <string>no_payment_uid</string>
<string>no_mirror_section_uid</string>
<string>payment_uid</string> <string>payment_uid</string>
<string>no_mirror_section_uid</string>
<string>mirror_section_uid</string> <string>mirror_section_uid</string>
<string>node_uid</string>
<string>new_result</string> <string>new_result</string>
<string>net_balance</string> <string>net_balance</string>
<string>get_inventory_kw</string> <string>get_inventory_kw</string>
...@@ -277,9 +266,10 @@ return new_result\n ...@@ -277,9 +266,10 @@ return new_result\n
<string>_apply_</string> <string>_apply_</string>
<string>previous_total_debit</string> <string>previous_total_debit</string>
<string>previous_total_credit</string> <string>previous_total_credit</string>
<string>from_date_summary</string> <string>Products.ERP5Type.Document</string>
<string>at_date</string> <string>newTempAccountingTransaction</string>
<string>node_uid</string> <string>previous_balance</string>
<string>True</string>
<string>result</string> <string>result</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>l</string> <string>l</string>
...@@ -296,9 +286,7 @@ return new_result\n ...@@ -296,9 +286,7 @@ return new_result\n
<item> <item>
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<tuple> <none/>
<int>0</int>
</tuple>
</value> </value>
</item> </item>
<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