Commit cd094956 authored by Kevin Deldycke's avatar Kevin Deldycke

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
parent 529276bf
...@@ -69,24 +69,24 @@ ...@@ -69,24 +69,24 @@
<value> <string>"""\n <value> <string>"""\n
This scripts add the balance of every gap account in the list \'accounts\'\n This scripts add the balance of every gap account in the list \'accounts\'\n
it use portal_simulation.getInventoryAssetPrice. \n it use portal_simulation.getInventoryAssetPrice. \n
The following REQUEST keys are mandatory : \n The following REQUEST keys are mandatory: \n
at_date\n at_date\n
\n \n
those are optional : \n those are optional: \n
gap_base\n gap_base\n
simulation_state\n simulation_state\n
section_category\n section_category\n
\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 from_date\n
\n \n
parameters keywords to this script overrides REQUEST keys\n parameters keywords to this script overrides REQUEST keys\n
\n
"""\n """\n
\n \n
def shortAccountNumberToFullGapCategory(accountNumber) :\n def shortAccountNumberToFullGapCategory(accountNumber):\n
""" translates a short account number (eg 280) to a full gap category url \n """\n
(eg gap/fr/gap/2/28/280) """\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 accountNumber = accountNumber.strip()\n
gap = request.get("gap_base", "gap/fr/pcg/")\n gap = request.get("gap_base", "gap/fr/pcg/")\n
for i in range(len(accountNumber)) :\n for i in range(len(accountNumber)) :\n
...@@ -94,24 +94,57 @@ def shortAccountNumberToFullGapCategory(accountNumber) :\n ...@@ -94,24 +94,57 @@ def shortAccountNumberToFullGapCategory(accountNumber) :\n
return gap[:-1]\n return gap[:-1]\n
\n \n
\n \n
precision = context.Base_getPreferredPrecision()\n
r_ = lambda x: context.Base_getRoundValue(x, precision)\n
\n
request = context.REQUEST\n request = context.REQUEST\n
kw = {}\n section = context.restrictedTraverse(request.get("organisation"))\n
kw[\'omit_simulation\'] = 1\n section_region = section.getRegion()\n
kw["simulation_state"] = request.get("simulation_state", [\'stopped\', \'delivered\'])\n params = {\n
kw["section_uid"] = context.restrictedTraverse(request.get("organisation")).getUid()\n \'omit_simulation\' : True\n
kw["at_date"] = request[\'at_date\']\n , \'simulation_state\': request.get("simulation_state", [\'stopped\', \'delivered\']) \n
kw.update(params_kw)\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 \n
sum = 0\n net_balance = 0.0\n
for account in accounts :\n for gap_id in gap_id_list:\n
kw["node_category"] = shortAccountNumberToFullGapCategory(account)\n gap_path = shortAccountNumberToFullGapCategory(gap_id)\n
\n
# checks the node category exists\n # checks the node category exists\n
if context.restrictedTraverse(\'portal_categories/%s\' % kw["node_category"], None) is not None :\n if context.restrictedTraverse(\'portal_categories/%s\' % gap_path, None) is not None:\n
val = (context.portal_simulation.getInventoryAssetPrice(**kw) or 0)\n params["node_category"] = gap_path\n
sum += val\n new_balance = 0.0\n
return float ("%.2f"%(sum))\n if not section_region_filtering:\n
# vim: syntax=python\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> </string> </value>
</item> </item>
<item> <item>
...@@ -128,11 +161,17 @@ return float ("%.2f"%(sum))\n ...@@ -128,11 +161,17 @@ return float ("%.2f"%(sum))\n
</item> </item>
<item> <item>
<key> <string>_filepath</string> </key> <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>
<item> <item>
<key> <string>_params</string> </key> <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>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -152,28 +191,40 @@ return float ("%.2f"%(sum))\n ...@@ -152,28 +191,40 @@ return float ("%.2f"%(sum))\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>1</int> </value> <value> <int>2</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>accounts</string> <string>gap_id_list</string>
<string>params_kw</string> <string>section_region_filtering</string>
<string>kw</string>
<string>request</string> <string>request</string>
<string>shortAccountNumberToFullGapCategory</string> <string>shortAccountNumberToFullGapCategory</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>kw</string> <string>precision</string>
<string>_write_</string> <string>r_</string>
<string>section</string>
<string>section_region</string>
<string>True</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>sum</string> <string>params</string>
<string>net_balance</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>account</string> <string>gap_id</string>
<string>gap_path</string>
<string>None</string> <string>None</string>
<string>_write_</string>
<string>new_balance</string>
<string>_apply_</string> <string>_apply_</string>
<string>val</string> <string>transaction_list</string>
<string>float</string> <string>transaction</string>
<string>transaction_line_path</string>
<string>line</string>
<string>third_party</string>
<string>region</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -185,7 +236,9 @@ return float ("%.2f"%(sum))\n ...@@ -185,7 +236,9 @@ return float ("%.2f"%(sum))\n
<item> <item>
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<none/> <tuple>
<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