Commit a58807ef authored by Kevin Deldycke's avatar Kevin Deldycke

* Use generic script Base_getPreferredPrecision and Base_getRoundValue to...

  * Use generic script Base_getPreferredPrecision and Base_getRoundValue to get the right amount of money.
  * Calculate and show the previous balance.
  * Remove suffix "transaction_" of query parameters to prepare the full migration of accouting stuff to getInventory API.
  * 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 Organisation.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6386 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3b811f61
......@@ -66,76 +66,116 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>kwd = {}\n
if kw.has_key(\'hide_grouping\'):\n
kwd[\'hide_grouping\'] = kw[\'hide_grouping\']\n
\n
LOG = lambda msg : context.log(\'Entity_getAccountingTransactionList\', msg)\n
<value> <string encoding="cdata"><![CDATA[
precision = context.Base_getPreferredPrecision()\n
r_ = lambda x: context.Base_getRoundValue(x, precision)\n
\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
if kw.get(\'no_from_date\', 0) :\n
from_date = None \n
else :\n
from_date = preference.getPreferredAccountingTransactionFromDate()\n
if from_date :\n
kwd[\'from_date\'] = from_date\n
# Build the common inventory dict\n
params = {}\n
\n
at_date = preference.getPreferredAccountingTransactionAtDate()\n
if at_date :\n
kwd[\'at_date\'] = at_date\n
if kw.get(\'no_from_date\', 0): from_date = None\n
\n
simulation_state = preference\\\n
.getPreferredAccountingTransactionSimulationStateList()\n
if simulation_state :\n
kwd[\'transaction_simulation_state\'] = simulation_state\n
if simulation_state: params[\'simulation_state\'] = simulation_state\n
if section_category: params[\'section_category\'] = section_category\n
\n
section_category = preference\\\n
.getPreferredAccountingTransactionSectionCategory()\n
if section_category :\n
kwd[\'transaction_section_category\'] = section_category\n
if kw.has_key(\'node_uid\') : params[\'node_uid\'] = kw[\'node_uid\']\n
if kw.has_key(\'portal_type\'): params[\'portal_type\'] = kw[\'portal_type\']\n
\n
if kw.has_key(\'node_uid\'):\n
kwd[\'node_uid\'] = transaction_selection[\'node_uid\']\n
if kw.has_key(\'transaction_portal_type\'):\n
kwd[\'transaction_portal_type\'] = kw[\'transaction_portal_type\']\n
# Create the related accouting line list\n
new_result = []\n
net_balance = 0.0\n
\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
\n
# Get previous debit and credit\n
previous_total_debit = context.Entity_zGetAccountingTransactionList(omit_output=1, **get_inventory_kw)\n
previous_total_credit = context.Entity_zGetAccountingTransactionList(omit_input =1, **get_inventory_kw)\n
previous_total_debit = r_(previous_total_debit[0].total_price)\n
previous_total_credit = r_(previous_total_credit[0].total_price)\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
# FIXME: same problem as in BankAccount_getAccountingTransactionList\n
# LOG("SQL used: %s" % context.Entity_zGetAccountingTransactionList(src__=1, **kwd))\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
new_result = []\n
result = context.Entity_zGetAccountingTransactionList(**kwd)\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
previous_balance.edit( \\\n
parent_title = context.Base_translateString("Previous Balance")\n
, section_title = ""\n
, date = from_date - 1\n
, portal_type = ""\n
, account_uid = None\n
, parent_reference = None\n
, parent_specific_reference = None\n
, translated_simulation_state_title = None\n
, debit = previous_total_debit\n
, credit = previous_total_credit\n
, grouping_reference = None\n
, balance = net_balance\n
, net_balance = net_balance\n
, is_previous_balance = True\n
)\n
new_result.append(previous_balance)\n
\n
\n
# Show / Hide grouping if needed\n
if kw.has_key(\'hide_grouping\'): params[\'hide_grouping\'] = kw[\'hide_grouping\']\n
\n
# FIXME: same problem as in BankAccount_getAccountingTransactionList\n
result = context.Entity_zGetAccountingTransactionList( from_date = from_date\n
, at_date = at_date\n
, src__ = src__\n
, **params\n
)\n
if src__:\n
return result\n
net_balance = 0.0\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 += l.balance or 0.0\n
if o is not None:\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
section_title=l.section_title,\n
parent_reference=l.parent_reference,\n
parent_specific_reference=l.parent_specific_reference,\n
translated_simulation_state_title =\n
o.getTranslatedSimulationStateTitle(),\n
\n
# FIXME: overriding \'portal_type\' in asContext is clearly a bad idea, as many methods are storred on the portal type \n
# (hence the translated_simulation_state_title hack) -j\xc3\xa9rome\n
portal_type=l.portal_type,\n
\n
account_uid=l.account_uid, )\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
, section_title = l.section_title\n
, parent_reference = l.parent_reference\n
, parent_specific_reference = l.parent_specific_reference\n
, translated_simulation_state_title = o.getTranslatedSimulationStateTitle()\n
# FIXME: overriding \'portal_type\' in asContext is clearly a bad idea, as many methods are storred on the portal type \n
# (hence the translated_simulation_state_title hack) -j\xc3\xa9rome\n
, portal_type = l.portal_type\n
, account_uid = l.account_uid\n
)\n
new_result.append(c)\n
\n
return new_result\n
# vim: syntax=python\n
</string> </value>
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
......@@ -184,23 +224,30 @@ return new_result\n
<string>selection</string>
<string>src__</string>
<string>kw</string>
<string>kwd</string>
<string>_getattr_</string>
<string>_getitem_</string>
<string>_write_</string>
<string>LOG</string>
<string>context</string>
<string>precision</string>
<string>r_</string>
<string>preference</string>
<string>None</string>
<string>from_date</string>
<string>at_date</string>
<string>simulation_state</string>
<string>section_category</string>
<string>transaction_selection</string>
<string>from_date</string>
<string>at_date</string>
<string>params</string>
<string>None</string>
<string>_write_</string>
<string>_getitem_</string>
<string>new_result</string>
<string>net_balance</string>
<string>get_inventory_kw</string>
<string>_apply_</string>
<string>previous_total_debit</string>
<string>previous_total_credit</string>
<string>Products.ERP5Type.Document</string>
<string>newTempAccountingTransaction</string>
<string>previous_balance</string>
<string>True</string>
<string>result</string>
<string>net_balance</string>
<string>_getiter_</string>
<string>l</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