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

stock report: use high level inventory API and small cleanups

parent 649f31fc
......@@ -52,54 +52,34 @@
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
site = context.portal_categories.site.restrictedTraverse(site)\n
if group:\n
group = context.portal_categories.group.restrictedTraverse(group)\n
else:\n
group = None\n
\n
if group is not None:\n
kw[\'stock_section_category_uid\'] = group.getUid()\n
\n
def mycmp(line_a, line_b):\n
"""\n
Compare 2 lines and sort them according to\n
sort_on parameter.\n
"""\n
\n
result = cmp(line_a.getResourceReference(), line_b.getResourceReference())\n
if result == 0:\n
result = cmp(line_a.variation_text, line_b.variation_text)\n
if result == 0:\n
result = cmp(line_a.resource_title, line_b.resource_title)\n
return result\n
result_list = []\n
for x in context.portal_simulation.getCurrentInventoryList(\n
stock_node_category_uid=site.getUid(),\n
group_by_resource=1,\n
group_by_variation=1,\n
group_by_node=0,\n
at_date=at_date,\n
# resource_portal_type= does not work with cells (because resource is acquired from line)\n
resourceType=context.getPortalProductTypeList(), **kw):\n
if positive_stock and negative_stock and not zero_stock and x.inventory == 0:\n
result_list.append(x)\n
if positive_stock and not negative_stock and zero_stock and x.inventory <0:\n
result_list.append(x)\n
if negative_stock and zero_stock and not positive_stock and x.inventory >0:\n
result_list.append(x)\n
if positive_stock and not negative_stock and not zero_stock and x.inventory <=0:\n
result_list.append(x)\n
if negative_stock and not positive_stock and not zero_stock and x.inventory >=0:\n
result_list.append(x)\n
if zero_stock and not positive_stock and not negative_stock and x.inventory!=0:\n
result_list.append(x)\n
for brain in context.portal_simulation.getCurrentInventoryList(\n
node_category=site,\n
section_category=group,\n
group_by_resource=True,\n
group_by_variation=True,\n
group_by_node=False,\n
at_date=at_date,\n
# resource_portal_type= does not work with cells (because resource is acquired from line)\n
resourceType=context.getPortalProductTypeList(),\n
**kw):\n
\n
if positive_stock and negative_stock and not zero_stock and brain.inventory == 0:\n
result_list.append(brain)\n
if positive_stock and not negative_stock and zero_stock and brain.inventory <0:\n
result_list.append(brain)\n
if negative_stock and zero_stock and not positive_stock and brain.inventory >0:\n
result_list.append(brain)\n
if positive_stock and not negative_stock and not zero_stock and brain.inventory <=0:\n
result_list.append(brain)\n
if negative_stock and not positive_stock and not zero_stock and brain.inventory >=0:\n
result_list.append(brain)\n
if zero_stock and not positive_stock and not negative_stock and brain.inventory!=0:\n
result_list.append(brain)\n
if not positive_stock and not negative_stock and not zero_stock:\n
result_list.append(x)\n
result_list.append(brain)\n
\n
result_list = list(result_list)\n
result_list.sort(cmp=mycmp)\n
return result_list\n
return sorted(result_list, key=lambda brain: (brain.getResourceReference(), brain.getResourceTitle(), brain.variation_text))\n
]]></string> </value>
......
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