[Erp5-report] r6726 - /erp5/trunk/bt5/erp5_accounting_l10n_fr/SkinTemplateItem/portal_skins...

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Apr 14 23:30:06 CEST 2006


Author: kevin
Date: Fri Apr 14 23:30:04 2006
New Revision: 6726

URL: http://svn.erp5.org?rev=6726&view=rev
Log:
Use where_expression.
Round value for good accounting.
Support per-region inventory.

Modified:
    erp5/trunk/bt5/erp5_accounting_l10n_fr/SkinTemplateItem/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory.xml

Modified: erp5/trunk/bt5/erp5_accounting_l10n_fr/SkinTemplateItem/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_accounting_l10n_fr/SkinTemplateItem/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory.xml?rev=6726&r1=6725&r2=6726&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_accounting_l10n_fr/SkinTemplateItem/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory.xml (original)
+++ erp5/trunk/bt5/erp5_accounting_l10n_fr/SkinTemplateItem/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory.xml Fri Apr 14 23:30:04 2006
@@ -69,24 +69,24 @@
             <value> <string>"""\n
   This scripts add the balance of every gap account in the list \'accounts\'\n
   it use portal_simulation.getInventoryAssetPrice. \n
-  The following REQUEST keys are mandatory : \n
+  The following REQUEST keys are mandatory: \n
       at_date\n
 \n
-  those are optional : \n
+  those are optional: \n
       gap_base\n
       simulation_state\n
       section_category\n
 \n
-  those are ignored from the request and should explicitely passed as keywords args to this script : \n
+  those are ignored from the request and should explicitely passed as keywords args to this script: \n
       from_date\n
   \n
   parameters keywords to this script overrides REQUEST keys\n
-\n
 """\n
 \n
-def shortAccountNumberToFullGapCategory(accountNumber) :\n
-  """ translates a short account number (eg 280) to a full gap category url \n
-    (eg gap/fr/gap/2/28/280) """\n
+def shortAccountNumberToFullGapCategory(accountNumber):\n
+  """\n
+    Translates a short account number (eg 280) to a full gap category url (eg gap/fr/gap/2/28/280).\n
+  """\n
   accountNumber = accountNumber.strip()\n
   gap = request.get("gap_base", "gap/fr/pcg/")\n
   for i in range(len(accountNumber)) :\n
@@ -94,24 +94,57 @@
   return gap[:-1]\n
 \n
 \n
+precision = context.Base_getPreferredPrecision()\n
+r_ = lambda x: context.Base_getRoundValue(x, precision)\n
+\n
 request = context.REQUEST\n
-kw = {}\n
-kw[\'omit_simulation\']   = 1\n
-kw["simulation_state"]  = request.get("simulation_state", [\'stopped\', \'delivered\'])\n
-kw["section_uid"]       = context.restrictedTraverse(request.get("organisation")).getUid()\n
-kw["at_date"]           = request[\'at_date\']\n
-kw.update(params_kw)\n
-\n
-sum = 0\n
-for account in accounts :\n
-  kw["node_category"] = shortAccountNumberToFullGapCategory(account)\n
-  \n
+section        = context.restrictedTraverse(request.get("organisation"))\n
+section_region = section.getRegion()\n
+params = {\n
+    \'omit_simulation\' : True\n
+  , \'simulation_state\': request.get("simulation_state", [\'stopped\', \'delivered\']) \n
+#  , \'simulation_state\': request.get("simulation_state", [\'delivered\']) \n
+  , \'section_uid\'     : section.getUid()\n
+  , \'at_date\'         : request[\'at_date\']\n
+  , \'where_expression\': " section.portal_type = \'Organisation\' "\n
+}\n
+params.update(kw)\n
+\n
+net_balance = 0.0\n
+for gap_id in gap_id_list:\n
+  gap_path = shortAccountNumberToFullGapCategory(gap_id)\n
   # checks the node category exists\n
-  if context.restrictedTraverse(\'portal_categories/%s\' % kw["node_category"], None) is not None :\n
-    val = (context.portal_simulation.getInventoryAssetPrice(**kw) or 0)\n
-    sum += val\n
-return float ("%.2f"%(sum))\n
-# vim: syntax=python\n
+  if context.restrictedTraverse(\'portal_categories/%s\' % gap_path, None) is not None:\n
+    params["node_category"] = gap_path\n
+    new_balance = 0.0\n
+    if not section_region_filtering:\n
+      new_balance = context.portal_simulation.getInventoryAssetPrice(**params) or 0.0\n
+    else:\n
+      transaction_list = context.portal_simulation.getInventoryList(**params) or []\n
+      # Sum transaction under region-related condition only\n
+      for transaction in transaction_list:\n
+        # get the line\n
+        transaction_line_path = transaction.path\n
+        line = context.restrictedTraverse(transaction_line_path)\n
+        # get the third party\n
+        third_party = line.getDestinationSectionValue()\n
+        if third_party in (None, \'\'):\n
+          # TODO: Should be a raise here with message translation.\n
+          context.log("Fiscal Report Error:", "\'%s\' need a third party." % (transaction_line_path))\n
+          continue\n
+        # get the third party region\n
+        region = third_party.getRegion()\n
+        if region in (None, \'\'):\n
+          # TODO: Should be a raise here with message translation.\n
+          context.log("Fiscal Report Error:", "\'%s\' third party (aka \'%s\') need a region." % (transaction_line_path, third_party.getPath()))\n
+          continue\n
+        # get the transaction line amount of money\n
+        if not region.startswith(section_region):\n
+          new_balance = r_(r_(new_balance) + r_(transaction.total_price)) or 0.0\n
+    # Update the general balance\n
+    net_balance = r_(r_(net_balance) + r_(new_balance))\n
+\n
+return r_(net_balance)\n
 </string> </value>
         </item>
         <item>
@@ -128,11 +161,17 @@
         </item>
         <item>
             <key> <string>_filepath</string> </key>
-            <value> <string>Script (Python):/erp5/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory</string> </value>
+            <value> <string>Script (Python):/nexedi/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory</string> </value>
+        </item>
+        <item>
+            <key> <string>_owner</string> </key>
+            <value>
+              <none/>
+            </value>
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>accounts, **params_kw</string> </value>
+            <value> <string>gap_id_list, section_region_filtering=False, **kw</string> </value>
         </item>
         <item>
             <key> <string>errors</string> </key>
@@ -152,28 +191,40 @@
                   <dictionary>
                     <item>
                         <key> <string>co_argcount</string> </key>
-                        <value> <int>1</int> </value>
+                        <value> <int>2</int> </value>
                     </item>
                     <item>
                         <key> <string>co_varnames</string> </key>
                         <value>
                           <tuple>
-                            <string>accounts</string>
-                            <string>params_kw</string>
+                            <string>gap_id_list</string>
+                            <string>section_region_filtering</string>
+                            <string>kw</string>
                             <string>request</string>
                             <string>shortAccountNumberToFullGapCategory</string>
                             <string>_getattr_</string>
                             <string>context</string>
-                            <string>kw</string>
+                            <string>precision</string>
+                            <string>r_</string>
+                            <string>section</string>
+                            <string>section_region</string>
+                            <string>True</string>
+                            <string>_getitem_</string>
+                            <string>params</string>
+                            <string>net_balance</string>
+                            <string>_getiter_</string>
+                            <string>gap_id</string>
+                            <string>gap_path</string>
+                            <string>None</string>
                             <string>_write_</string>
-                            <string>_getitem_</string>
-                            <string>sum</string>
-                            <string>_getiter_</string>
-                            <string>account</string>
-                            <string>None</string>
+                            <string>new_balance</string>
                             <string>_apply_</string>
-                            <string>val</string>
-                            <string>float</string>
+                            <string>transaction_list</string>
+                            <string>transaction</string>
+                            <string>transaction_line_path</string>
+                            <string>line</string>
+                            <string>third_party</string>
+                            <string>region</string>
                           </tuple>
                         </value>
                     </item>
@@ -185,7 +236,9 @@
         <item>
             <key> <string>func_defaults</string> </key>
             <value>
-              <none/>
+              <tuple>
+                <int>0</int>
+              </tuple>
             </value>
         </item>
         <item>




More information about the Erp5-report mailing list