[Erp5-report] r6379 - /erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_ac...

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Mar 31 01:47:05 CEST 2006


Author: kevin
Date: Fri Mar 31 01:47:03 2006
New Revision: 6379

URL: http://svn.erp5.org?rev=6379&view=rev
Log:
* Use generic script Base_getPreferredPrecision and Base_getRoundValue to get the right amount of money.
  * Add support for query parameters with or without "transaction_" prefix for easy transition to getInventory API.
  * Fix conflicts if to_date, from_date and at_date are set together.

Modified:
    erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Account_statSourceBalance.xml

Modified: erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Account_statSourceBalance.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Account_statSourceBalance.xml?rev=6379&r1=6378&r2=6379&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Account_statSourceBalance.xml (original)
+++ erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Account_statSourceBalance.xml Fri Mar 31 01:47:03 2006
@@ -66,70 +66,132 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>kw.update(selection.getParams())\n
-params = {}\n
+            <value> <string>params = {}\n
+pref = context.getPortalObject().portal_preferences\n
+precision = context.Base_getPreferredPrecision()\n
+\n
+###\n
+# Merge selection parameters in kw\n
+selection_params = None\n
+if selection is not None:\n
+  selection_params = selection.getParams()\n
+  kw.update(selection_params)\n
+\n
+###\n
+# Get the node UID\n
+params[\'node_uid\'] = kw.get(\'node_uid\', context.getUid())\n
+\n
+###\n
+# Get the \'where_expression\' parameter\n
 if kw.has_key(\'where_expression\'):\n
   params[\'where_expression\'] = kw[\'where_expression\']\n
+\n
+###\n
+# Get the \'resource_uid\' parameter\n
 if kw.get(\'resource\'):\n
-  try: params[\'resource_uid\'] = context.restritedTraverse(\n
-                                    selection_params[\'resource\']).getUid()\n
-  except (KeyError, AttributeError): pass\n
-\n
-# read settings from user preference\n
-preference = context.getPortalObject().portal_preferences\n
-if kw.get(\'no_from_date\', 0) :\n
-  from_date = None \n
-else :\n
-  from_date = kw.get(\'from_date\',\n
-                preference.getPreferredAccountingTransactionFromDate())\n
-if from_date :\n
+  try:\n
+    params[\'resource_uid\'] = context.restrictedTraverse(selection_params[\'resource\']).getUid()\n
+  except (KeyError, AttributeError):\n
+    pass\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
 \n
-at_date =  kw.get(\'at_date\',\n
-              preference.getPreferredAccountingTransactionAtDate())\n
-if at_date :\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
-simulation_state = preference\\\n
-                  .getPreferredAccountingTransactionSimulationStateList()\n
-if simulation_state :\n
+###\n
+# Get the \'to_date\' parameter\n
+to_date = kw.get( \'to_date\'\n
+                , None\n
+                )\n
+if to_date:\n
+  params[\'to_date\'] = to_date\n
+\n
+###\n
+# Get the \'simulation_state\' parameter\n
+# Sometimes \'simulation_state\' is now as \'transaction_simulation_state\'\n
+simulation_state = kw.get( \'transaction_simulation_state\'\n
+                         , None\n
+                         )\n
+if not simulation_state:\n
+  simulation_state = kw.get( \'simulation_state\'\n
+                           , pref.getPreferredAccountingTransactionSimulationStateList()\n
+                           )\n
+if simulation_state:\n
   params[\'transaction_simulation_state\'] = simulation_state\n
 \n
-section_category = preference.getPreferredAccountingTransactionSectionCategory()\n
-if section_category :\n
+###\n
+# Get the \'section_category\' parameter\n
+# Sometimes \'section_category\' is now as \'transaction_section_category\'\n
+section_category = kw.get( \'transaction_section_category\'\n
+                         , None\n
+                         )\n
+if not section_category:\n
+  section_category = kw.get( \'section_category\'\n
+                           , pref.getPreferredAccountingTransactionSectionCategory()\n
+                           )\n
+if section_category:\n
   params[\'transaction_section_category\'] = section_category\n
 \n
-if kw.get(\'omit_input\') :\n
-  params[\'omit_input\'] = 1\n
-if kw.get(\'omit_output\') :\n
-  params[\'omit_output\'] = 1\n
-\n
+###\n
+# Get omit parameters\n
+if kw.get(\'omit_input\') : params[\'omit_input\']  = 1\n
+if kw.get(\'omit_output\'): params[\'omit_output\'] = 1\n
+\n
+###\n
+# Get payment and mirror related parameters\n
 MARKER = []\n
-kw = selection.getParams()\n
-payment_uid = kw.get(\'payment_uid\', MARKER)\n
-if payment_uid is not MARKER:\n
-  params[\'payment_uid\'] = payment_uid\n
-no_payment = kw.get(\'no_payment_uid\', MARKER)\n
-if no_payment is not MARKER:\n
-  params[\'no_payment_uid\'] = 1\n
-\n
-mirror_section_uid = kw.get(\'mirror_section_uid\', MARKER)\n
-if mirror_section_uid is not MARKER:\n
-  params[\'mirror_section_uid\'] = mirror_section_uid\n
-no_mirror_section = kw.get(\'no_mirror_section\', MARKER)\n
-if no_mirror_section is not MARKER:\n
-  params[\'no_mirror_section\'] = 1\n
-\n
-params[\'node_uid\'] = kw.get(\'node_uid\', context.getUid())\n
-\n
-if kw.get(\'from_date_summary\', 0) :\n
-  if params.has_key(\'from_date\'):\n
-    del params[\'from_date\']\n
-\n
-#context.log("SQL with %s \\n" % params, context.Account_zGetTotalQuantity(src__=1, **params))\n
+no_payment_uid        = MARKER\n
+no_mirror_section_uid = MARKER\n
+payment_uid           = MARKER\n
+mirror_section_uid    = MARKER\n
+if selection_params != None:\n
+  no_payment_uid        = selection_params.get(\'no_payment_uid\',        MARKER)\n
+  no_mirror_section_uid = selection_params.get(\'no_mirror_section_uid\', MARKER)\n
+  payment_uid           = selection_params.get(\'payment_uid\',           MARKER)\n
+  mirror_section_uid    = selection_params.get(\'mirror_section_uid\',    MARKER)\n
+if no_payment_uid        is not MARKER: params[\'no_payment_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
+\n
+###\n
+# Clean up date params.\n
+\n
+# Don\'t use the from_date parameter if from_date_summary is present\n
+if kw.get(\'from_date_summary\', 0) and params.has_key(\'from_date\'):\n
+  del params[\'from_date\']\n
+\n
+# \'to_date\' exclude the use of \'from_date\' and \'at_date\'\n
+# In fact, \'to_date\' is handle by the SQL query as "at_date minus one day"\n
+if params.has_key(\'to_date\'):\n
+  if params.has_key(\'at_date\'):   del params[\'at_date\']\n
+  if params.has_key(\'from_date\'): del params[\'from_date\']\n
+\n
+###\n
+# Call the query with selected parameters\n
+# context.log("SQL with %s \\n" % params, context.Account_zGetTotalQuantity(src__=1, **params))\n
 result = context.Account_zGetTotalQuantity(**params)\n
 row = result[0]\n
-return float(\'%.02f\' % (row.total_price or 0.0) )\n
+\n
+###\n
+# Round the result to avoid float bad precision\n
+# TODO: use currency precision\n
+return context.Base_getRoundValue(row.total_price or 0.0, precision)\n
 </string> </value>
         </item>
         <item>
@@ -186,29 +248,30 @@
                           <tuple>
                             <string>selection</string>
                             <string>kw</string>
+                            <string>params</string>
                             <string>_getattr_</string>
-                            <string>params</string>
+                            <string>context</string>
+                            <string>pref</string>
+                            <string>precision</string>
+                            <string>None</string>
+                            <string>selection_params</string>
+                            <string>_write_</string>
                             <string>_getitem_</string>
-                            <string>_write_</string>
-                            <string>context</string>
-                            <string>selection_params</string>
                             <string>KeyError</string>
                             <string>AttributeError</string>
-                            <string>preference</string>
-                            <string>None</string>
                             <string>from_date</string>
                             <string>at_date</string>
+                            <string>to_date</string>
                             <string>simulation_state</string>
                             <string>section_category</string>
                             <string>MARKER</string>
+                            <string>no_payment_uid</string>
+                            <string>no_mirror_section_uid</string>
                             <string>payment_uid</string>
-                            <string>no_payment</string>
                             <string>mirror_section_uid</string>
-                            <string>no_mirror_section</string>
                             <string>_apply_</string>
                             <string>result</string>
                             <string>row</string>
-                            <string>float</string>
                           </tuple>
                         </value>
                     </item>




More information about the Erp5-report mailing list