From cd09495680b664b565e2081da37258fd2dcf1b3c Mon Sep 17 00:00:00 2001 From: Kevin Deldycke <kevin@nexedi.com> Date: Fri, 14 Apr 2006 21:30:04 +0000 Subject: [PATCH] Use where_expression. Round value for good accounting. Support per-region inventory. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6726 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../FiscalReportCell_doGetInventory.xml | 121 +++++++++++++----- 1 file changed, 87 insertions(+), 34 deletions(-) diff --git a/bt5/erp5_accounting_l10n_fr/SkinTemplateItem/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory.xml b/bt5/erp5_accounting_l10n_fr/SkinTemplateItem/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory.xml index 0d3e51c4ba..4ab520e424 100644 --- a/bt5/erp5_accounting_l10n_fr/SkinTemplateItem/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory.xml +++ b/bt5/erp5_accounting_l10n_fr/SkinTemplateItem/portal_skins/erp5_accounting_l10n_fr/FiscalReportCell_doGetInventory.xml @@ -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 @@ def shortAccountNumberToFullGapCategory(accountNumber) :\n 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 +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 -sum = 0\n -for account in accounts :\n - kw["node_category"] = shortAccountNumberToFullGapCategory(account)\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 @@ return float ("%.2f"%(sum))\n </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 @@ return float ("%.2f"%(sum))\n <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>_write_</string> + <string>precision</string> + <string>r_</string> + <string>section</string> + <string>section_region</string> + <string>True</string> <string>_getitem_</string> - <string>sum</string> + <string>params</string> + <string>net_balance</string> <string>_getiter_</string> - <string>account</string> + <string>gap_id</string> + <string>gap_path</string> <string>None</string> + <string>_write_</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 @@ return float ("%.2f"%(sum))\n <item> <key> <string>func_defaults</string> </key> <value> - <none/> + <tuple> + <int>0</int> + </tuple> </value> </item> <item> -- 2.30.9