Commit ec9837b7 authored by Jérome Perrin's avatar Jérome Perrin

In ungrouping mode, checking one line is enough to remove the grouping...

In ungrouping mode, checking one line is enough to remove the grouping reference on this line and all lines that are grouped with it.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20117 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cfb1eec2
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
If the parameter keep_if_valid_group is true, then the grouping reference\n If the parameter keep_if_valid_group is true, then the grouping reference\n
will be kept as is if the group is still valid, ie. the total quantity\n will be kept as is if the group is still valid, ie. the total quantity\n
of all accounting lines in the group is 0.\n of all accounting lines in the group is 0.\n
Returns the list of ungroupped lines.\n
"""\n """\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
precision = context.getResourceValue(portal_type=\'Currency\').getQuantityPrecision()\n precision = context.getResourceValue(portal_type=\'Currency\').getQuantityPrecision()\n
...@@ -98,6 +99,8 @@ if round(sum([(l.total_price or 0) for l in line_list]), precision) == 0 and kee ...@@ -98,6 +99,8 @@ if round(sum([(l.total_price or 0) for l in line_list]), precision) == 0 and kee
\n \n
for line in line_list:\n for line in line_list:\n
line.setGroupingReference(None)\n line.setGroupingReference(None)\n
\n
return line_list\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
...@@ -74,7 +74,6 @@ portal = context.getPortalObject()\n ...@@ -74,7 +74,6 @@ portal = context.getPortalObject()\n
getobject = portal.portal_catalog.getobject\n getobject = portal.portal_catalog.getobject\n
N_ = portal.Base_translateString\n N_ = portal.Base_translateString\n
psm = N_(\'Nothing matches\')\n psm = N_(\'Nothing matches\')\n
reset = 0\n
request = container.REQUEST\n request = container.REQUEST\n
precision = request.get(\'precision\', 2)\n precision = request.get(\'precision\', 2)\n
\n \n
...@@ -124,7 +123,6 @@ if grouping == \'grouping\':\n ...@@ -124,7 +123,6 @@ if grouping == \'grouping\':\n
if grouped_line_list:\n if grouped_line_list:\n
psm = N_(\'${grouped_line_count} Lines Grouped\',\n psm = N_(\'${grouped_line_count} Lines Grouped\',\n
mapping=dict(grouped_line_count=len(grouped_line_list)))\n mapping=dict(grouped_line_count=len(grouped_line_list)))\n
reset = 1\n
\n \n
# we check if we can mark some transaction as payed.\n # we check if we can mark some transaction as payed.\n
transaction_list = {}\n transaction_list = {}\n
...@@ -162,43 +160,20 @@ if grouping == \'grouping\':\n ...@@ -162,43 +160,20 @@ if grouping == \'grouping\':\n
except:\n except:\n
# Workflow action not supported\n # Workflow action not supported\n
pass\n pass\n
\n
# or to ungroup based on how we are called.\n
else:\n else:\n
assert grouping == \'ungrouping\'\n assert grouping == \'ungrouping\'\n
# or to ungroup based on how we are called.\n
amount_per_node_mirror_section = dict()\n
# XXX is uids multi page safe here ?\n # XXX is uids multi page safe here ?\n
line_list = [getobject(line_uid) for line_uid in uids]\n line_list = [getobject(line_uid) for line_uid in uids]\n
ungrouped_line_list = []\n
\n
for line in line_list:\n for line in line_list:\n
if line.AccountingTransaction_isSourceView(): # XXX not optimal !\n if line.getGroupingReference():\n
key = (line.getSource(), line.getDestinationSection())\n ungrouped_line_list.extend(line.AccountingTransactionLine_resetGroupingReference())\n
amount = amount_per_node_mirror_section.get(key, 0)\n
amount_per_node_mirror_section[key] = amount +\\\n
(line.getSourceInventoriatedTotalAssetPrice() or 0)\n
else:\n
key = (line.getDestination(), line.getSourceSection())\n
amount = amount_per_node_mirror_section.get(key, 0)\n
amount_per_node_mirror_section[key] = amount +\\\n
(line.getDestinationInventoriatedTotalAssetPrice() or 0)\n
\n
valid = 1\n
for node_mirror_section, amount in amount_per_node_mirror_section.items():\n
if round(amount, precision) != 0:\n
valid = 0\n
\n \n
if line_list:\n
ref = line_list[0].getGroupingReference()\n
for line in line_list:\n
if line.getGroupingReference() != ref:\n
valid = 0\n
\n
if valid:\n
psm = N_(\'${ungrouped_line_count} Lines Ungrouped\',\n psm = N_(\'${ungrouped_line_count} Lines Ungrouped\',\n
mapping=dict(ungrouped_line_count=len(uids)))\n mapping=dict(ungrouped_line_count=len(ungrouped_line_list)))\n
reset = 1\n
for line in line_list:\n
line.setGroupingReference(None)\n
else:\n
psm = N_(\'Ungrouping refused. Check your selection\')\n
\n \n
request.set(\'portal_status_message\', psm)\n request.set(\'portal_status_message\', psm)\n
return context.AccountingTransactionModule_viewGroupingFastInputDialog(request)\n return context.AccountingTransactionModule_viewGroupingFastInputDialog(request)\n
...@@ -269,7 +244,6 @@ return context.AccountingTransactionModule_viewGroupingFastInputDialog(request)\ ...@@ -269,7 +244,6 @@ return context.AccountingTransactionModule_viewGroupingFastInputDialog(request)\
<string>getobject</string> <string>getobject</string>
<string>N_</string> <string>N_</string>
<string>psm</string> <string>psm</string>
<string>reset</string>
<string>container</string> <string>container</string>
<string>request</string> <string>request</string>
<string>precision</string> <string>precision</string>
...@@ -290,18 +264,11 @@ return context.AccountingTransactionModule_viewGroupingFastInputDialog(request)\ ...@@ -290,18 +264,11 @@ return context.AccountingTransactionModule_viewGroupingFastInputDialog(request)\
<string>account</string> <string>account</string>
<string>date</string> <string>date</string>
<string>AssertionError</string> <string>AssertionError</string>
<string>amount_per_node_mirror_section</string>
<string>append</string> <string>append</string>
<string>$append0</string> <string>$append0</string>
<string>line_uid</string> <string>line_uid</string>
<string>line_list</string> <string>line_list</string>
<string>key</string> <string>ungrouped_line_list</string>
<string>amount</string>
<string>valid</string>
<string>node_mirror_section</string>
<string>round</string>
<string>_getitem_</string>
<string>ref</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
655 656
\ No newline at end of file \ No newline at end of file
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