[IMP]:printscreen Reports for Single/Multi level Groupby
bzr revid: nch@tinyerp.com-20100409101846-j0v63e7teo3j6brz
This commit is contained in:
parent
02b5b44049
commit
b882309f71
|
@ -114,14 +114,14 @@
|
||||||
</para>
|
</para>
|
||||||
</xsl:when>
|
</xsl:when>
|
||||||
<xsl:when test="@tree='float'">
|
<xsl:when test="@tree='float'">
|
||||||
<para style="float_right"><font fontName="Helvetica-bold" fontSize="9">
|
<para style="float_right"><font fontName="Helvetica-bold" fontSize="9" color="blue">
|
||||||
<xsl:value-of select="."/>
|
<xsl:value-of select="."/>
|
||||||
</font></para>
|
</font></para>
|
||||||
</xsl:when>
|
</xsl:when>
|
||||||
|
|
||||||
<xsl:otherwise>
|
<xsl:otherwise>
|
||||||
<para>
|
<para>
|
||||||
<font fontName="Helvetica-bold" fontSize="9">
|
<font fontName="Helvetica-bold" fontSize="9" color="blue">
|
||||||
<xsl:value-of select="."/>
|
<xsl:value-of select="."/>
|
||||||
</font>
|
</font>
|
||||||
</para>
|
</para>
|
||||||
|
|
|
@ -27,19 +27,25 @@ from report import render
|
||||||
import locale
|
import locale
|
||||||
|
|
||||||
import time, os
|
import time, os
|
||||||
|
from operator import itemgetter
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
class report_printscreen_list(report_int):
|
class report_printscreen_list(report_int):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
report_int.__init__(self, name)
|
report_int.__init__(self, name)
|
||||||
self.context = {}
|
self.context = {}
|
||||||
|
self.groupby = []
|
||||||
|
|
||||||
def _parse_node(self, root_node):
|
def _parse_node(self, root_node):
|
||||||
result = []
|
result = []
|
||||||
|
groupby = self.context.get('group_by',[])
|
||||||
for node in root_node:
|
for node in root_node:
|
||||||
|
field_name = node.get('name')
|
||||||
if not eval(str(node.attrib.get('invisible',False)),{'context':self.context}):
|
if not eval(str(node.attrib.get('invisible',False)),{'context':self.context}):
|
||||||
if node.tag == 'field':
|
if node.tag == 'field':
|
||||||
result.append(node.get('name'))
|
if field_name in groupby:
|
||||||
|
continue
|
||||||
|
result.append(field_name)
|
||||||
else:
|
else:
|
||||||
result.extend(self._parse_node(node))
|
result.extend(self._parse_node(node))
|
||||||
return result
|
return result
|
||||||
|
@ -55,6 +61,7 @@ class report_printscreen_list(report_int):
|
||||||
if not context:
|
if not context:
|
||||||
context={}
|
context={}
|
||||||
self.context = context
|
self.context = context
|
||||||
|
self.groupby = context.get('group_by',[])
|
||||||
pool = pooler.get_pool(cr.dbname)
|
pool = pooler.get_pool(cr.dbname)
|
||||||
model = pool.get(datas['model'])
|
model = pool.get(datas['model'])
|
||||||
model_id = pool.get('ir.model').search(cr, uid, [('model','=',model._name)])
|
model_id = pool.get('ir.model').search(cr, uid, [('model','=',model._name)])
|
||||||
|
@ -64,35 +71,37 @@ class report_printscreen_list(report_int):
|
||||||
else:
|
else:
|
||||||
model_desc = model._description
|
model_desc = model._description
|
||||||
self.title = model_desc
|
self.title = model_desc
|
||||||
|
|
||||||
datas['ids'] = ids
|
datas['ids'] = ids
|
||||||
model = pooler.get_pool(cr.dbname).get(datas['model'])
|
model = pooler.get_pool(cr.dbname).get(datas['model'])
|
||||||
result = model.fields_view_get(cr, uid, view_type='tree', context=context)
|
result = model.fields_view_get(cr, uid, view_type='tree', context=context)
|
||||||
fields_order = self._parse_string(result['arch'])
|
fields_order = self.groupby + self._parse_string(result['arch'])
|
||||||
rows = model.read(cr, uid, datas['ids'], result['fields'].keys(), context)
|
if self.groupby:
|
||||||
ids2 = [x['id'] for x in rows] # getting the ids from read result
|
rows = []
|
||||||
if datas['ids'] != ids2: # sorted ids were not taken into consideration for print screen
|
def get_groupby_data(groupby = [], domain = []):
|
||||||
rows_new = []
|
records = model.read_group(cr, uid, domain, fields_order, groupby , 0, None, context)
|
||||||
for id in datas['ids']:
|
for rec in records:
|
||||||
element = [elem for elem in rows if elem['id']==id]
|
rec['__group'] = True
|
||||||
rows_new.append(element[0])
|
for f in fields_order:
|
||||||
rows = rows_new
|
if f not in rec:
|
||||||
if context.get('group_by',False):
|
rec.update({f:False})
|
||||||
if context['group_by'] in fields_order:
|
rows.append(rec)
|
||||||
fields_order.remove(context['group_by'])
|
groupby = (rec.get('__context', {})).get('group_by',[])
|
||||||
fields_order.insert(0, context['group_by'])
|
domain = rec.get('__domain', [])
|
||||||
re = model.read_group(cr, uid, [('id','in',ids)], fields_order, context.get('group_by',False),0,None,context)
|
if groupby:
|
||||||
rows=[]
|
get_groupby_data(groupby, domain)
|
||||||
for r in re:
|
else:
|
||||||
for f in fields_order:
|
child_ids = model.search(cr, uid, domain)
|
||||||
if f not in r:
|
res = model.read(cr, uid, child_ids, result['fields'].keys(), context)
|
||||||
r.update({f:False})
|
rows.extend(res)
|
||||||
r['__group']=True
|
get_groupby_data(self.groupby, [('id','in',ids)])
|
||||||
rows.append(r)
|
else:
|
||||||
_ids = model.search(cr, uid, r['__domain'])
|
rows = model.read(cr, uid, datas['ids'], result['fields'].keys(), context)
|
||||||
res=model.read(cr, uid, _ids, result['fields'].keys(), context)
|
ids2 = map(itemgetter('id'), rows) # getting the ids from read result
|
||||||
for r in res:
|
if datas['ids'] != ids2: # sorted ids were not taken into consideration for print screen
|
||||||
rows.append(r)
|
rows_new = []
|
||||||
|
for id in datas['ids']:
|
||||||
|
rows_new += [elem for elem in rows if elem['id'] == id]
|
||||||
|
rows = rows_new
|
||||||
res = self._create_table(uid, datas['ids'], result['fields'], fields_order, rows, context, model_desc)
|
res = self._create_table(uid, datas['ids'], result['fields'], fields_order, rows, context, model_desc)
|
||||||
return (self.obj.get(), 'pdf')
|
return (self.obj.get(), 'pdf')
|
||||||
|
|
||||||
|
@ -116,13 +125,14 @@ class report_printscreen_list(report_int):
|
||||||
|
|
||||||
l = []
|
l = []
|
||||||
t = 0
|
t = 0
|
||||||
rowcount=0;
|
rowcount = 0;
|
||||||
strmax = (pageSize[0]-40) * 2.8346
|
strmax = (pageSize[0]-40) * 2.8346
|
||||||
temp = []
|
temp = []
|
||||||
|
tsum = []
|
||||||
count = len(fields_order)
|
count = len(fields_order)
|
||||||
for i in range(0, count):
|
for i in range(0, count):
|
||||||
temp.append(0)
|
temp.append(0)
|
||||||
|
tsum.append(0)
|
||||||
ince = -1;
|
ince = -1;
|
||||||
for f in fields_order:
|
for f in fields_order:
|
||||||
s = 0
|
s = 0
|
||||||
|
@ -131,7 +141,7 @@ class report_printscreen_list(report_int):
|
||||||
s = 60
|
s = 60
|
||||||
strmax -= s
|
strmax -= s
|
||||||
if fields[f]['type'] in ('float','integer'):
|
if fields[f]['type'] in ('float','integer'):
|
||||||
temp[ince]=1;
|
temp[ince] = 1
|
||||||
else:
|
else:
|
||||||
t += fields[f].get('size', 80) / 28 + 1
|
t += fields[f].get('size', 80) / 28 + 1
|
||||||
|
|
||||||
|
@ -149,10 +159,6 @@ class report_printscreen_list(report_int):
|
||||||
field.text = tools.ustr(fields[f]['string'] or '')
|
field.text = tools.ustr(fields[f]['string'] or '')
|
||||||
|
|
||||||
lines = etree.SubElement(new_doc, 'lines')
|
lines = etree.SubElement(new_doc, 'lines')
|
||||||
tsum = []
|
|
||||||
count = len(fields_order)
|
|
||||||
for i in range(0,count):
|
|
||||||
tsum.append(0)
|
|
||||||
for line in results:
|
for line in results:
|
||||||
node_line = etree.SubElement(lines, 'row')
|
node_line = etree.SubElement(lines, 'row')
|
||||||
count = -1
|
count = -1
|
||||||
|
@ -212,9 +218,8 @@ class report_printscreen_list(report_int):
|
||||||
tsum[count] = float(tsum[count]) + float(line[f]);
|
tsum[count] = float(tsum[count]) + float(line[f]);
|
||||||
else:
|
else:
|
||||||
col.text = '/'
|
col.text = '/'
|
||||||
|
|
||||||
node_line = etree.SubElement(lines, 'row')
|
node_line = etree.SubElement(lines, 'row')
|
||||||
for f in range(0,count+1):
|
for f in range(0, count+1):
|
||||||
col = etree.SubElement(node_line, 'col', para='group', tree='no')
|
col = etree.SubElement(node_line, 'col', para='group', tree='no')
|
||||||
if tsum[f] != None:
|
if tsum[f] != None:
|
||||||
if tsum[f] >= 0.01 :
|
if tsum[f] >= 0.01 :
|
||||||
|
|
Loading…
Reference in New Issue