|
[[ repeatIn(lines(p,data), 'line') ]][[ line['date'] ]]
diff --git a/addons/account_report/report/print_indicator.py b/addons/account_report/report/print_indicator.py
index 4b97289af07..83ac5eb22cc 100644
--- a/addons/account_report/report/print_indicator.py
+++ b/addons/account_report/report/print_indicator.py
@@ -1,3 +1,4 @@
+
# -*- encoding: utf-8 -*-
##############################################################################
#
@@ -35,50 +36,187 @@ from crm.report import report_businessopp
from report.interface import report_int
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.barcharts import VerticalBarChart
-import reportlab.lib.colors
+import reportlab.lib.colors as colors
+#from reportlab.graphics.widgetbase import Widget, TypedPropertyCollection
+#from reportlab.graphics.charts.textlabels import BarChartLabel
#from reportlab.graphics import renderPM
+import tools
-class accounting_report1(report_sxw.rml_parse):
+
+parents = {
+ 'tr':1,
+ 'li':1,
+ 'story': 0,
+ 'section': 0
+}
+
+class accounting_report_indicator(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
- super(accounting_report1, self).__init__(cr, uid, name, context)
+ super(accounting_report_indicator, self).__init__(cr, uid, name, context)
self.ret_list = []
self.localcontext.update({
'time': time,
'test': self.test1,
-# 'childs':self.process
+ 'lines':self.lines,
+ 'getarray':self.getarray,
})
+ self.count=0
+ self.list=[]
+ self.header_name=self.header_val=[]
- def test1(self):
- drawing = Drawing(400, 200)
+ def repeatIn(self, lst, name, nodes_parent=False,td=False,width=[],value=[],type=[]):
+ self._node.data = ''
+ node = self._find_parent(self._node, nodes_parent or parents)
+ ns = node.nextSibling
+#start
+ if not name=='array':
+ return super(accounting_report_indicator,self).repeatIn(lst, name, nodes_parent=False)
+
+ value=['X-Axis']
+ value.extend(self.header_name)
+ type=['string'].extend(['float']*len(self.header_name))
+ width=[40]*(len(self.header_name)+1)
+
+ if not lst:
+ lst.append(1)
+ for ns in node.childNodes :
+ if ns and ns.nodeName!='#text' and ns.tagName=='blockTable' and td :
+ width_str = ns._attrs['colWidths'].nodeValue
+ ns.removeAttribute('colWidths')
+ total_td = td * len(value)
+
+ if not width:
+ for v in value:
+ width.append(30)
+ for v in range(len(value)):
+ width_str +=',%d'%width[v]
+
+ ns.setAttribute('colWidths',width_str)
+
+ child_list = ns.childNodes
+ check=0
+ for child in child_list:
+ if child.nodeName=='tr':
+ lc = child.childNodes[1]
+# for t in range(td):
+ i=0
+ for v in value:
+ newnode = lc.cloneNode(1)
+ if check==1:
+ t1="[[ %s['%s'] ]]"%(name,v)
+ else:
+ t1="%s"%(v)
+ newnode.childNodes[1].lastChild.data = t1
+ child.appendChild(newnode)
+ newnode=False
+ i+=1
+ check=1
+
+ return super(accounting_report_indicator,self).repeatIn(lst, name, nodes_parent=False)
+
+ def lines(self,data):
+ res={}
+ result=[]
+ obj_inds=self.pool.get('account.report.report').browse(self.cr,self.uid,data['indicator_id'])
+
+ def find_child(obj):
+ self.list.append(obj)
+ if obj.child_ids:
+ for child in obj.child_ids:
+ find_child(child)
+ return True
+
+ find_child(obj_inds)
+
+ for obj_ind in self.list:
+ res = {
+ 'id':obj_ind.id,
+ 'name':obj_ind.name,
+ 'code':obj_ind.code,
+ 'expression':obj_ind.expression,
+ 'disp_graph':obj_ind.disp_graph,
+ 'note':obj_ind.note,
+ 'type':obj_ind.type
+ }
+ result.append(res)
+ return result
+
+ def getarray(self,data,object):
+ res={}
+ result=[]
+ self.test1(data,object,intercall=True)
+ self.header_val=[str(x) for x in self.header_val]
+ temp_dict=zip(self.header_name,self.header_val)
+ res=dict(temp_dict)
+ res['X-Axis']='Value'
+ result.append(res)
+ return result
+
+
+ def test1(self,data,object,intercall=False):
+ path=tools.config['root_path']+"/Temp_report/Image"
+ obj_history=self.pool.get('account.report.history')
+
+ if data['select_base']=='year':
+ tuple_search=('fiscalyear_id','in',data['base_selection'][0][2])
+ else:
+ tuple_search=('period_id','in',data['base_selection'][0][2])
+
+ history_ids=obj_history.search(self.cr,self.uid,[('name','=',object['id']),tuple_search])
+ obj_his=obj_history.browse(self.cr,self.uid,history_ids)
+
+ data_val=[]
+ data_period=[]
+ for item in obj_his:
+ data_val.append(item.val)
+ data_period.append(item.period_id.name)
+ self.header_name=data_period
+ self.header_val=data_val
+
+ if intercall:
+ return True
+ self.count +=1
+ drawing = Drawing(400, 300)
data = [
- (13, 5, 20, 22, 37, 45, 19, 4),
- (11, 3, 10, 22, 30, 25, 29, 6),
+ tuple(data_val),
]
+ value_min=0.0
+ vmin=min(data_val)
+ vmax=max(data_val)
+
+ val_min=((vmin < 0.00 and vmin-2.00) or 0.00)
+ # calculating maximum
+ val_max=(vmax/(pow(10,len(str(int(vmax)))-2))+1)*pow(10,len(str(int(vmax)))-2)
bc = VerticalBarChart()
bc.x = 50
bc.y = 50
- bc.height = 125
+ bc.height = 245
bc.width = 300
bc.data = data
- bc.strokeColor = reportlab.lib.colors.black
- bc.valueAxis.valueMin = 0
- bc.valueAxis.valueMax = 50
- bc.valueAxis.valueStep = 10
+ value_step=(abs(val_max)-abs(val_min))/5
+
+ bc.strokeColor = colors.black
+ bc.valueAxis.valueMin = val_min
+ bc.valueAxis.valueMax = val_max
+ bc.valueAxis.valueStep = value_step
+
bc.categoryAxis.labels.boxAnchor = 'ne'
bc.categoryAxis.labels.dx = 8
+
bc.categoryAxis.labels.dy = -2
bc.categoryAxis.labels.angle = 30
- bc.categoryAxis.categoryNames = ['Jan-99','Feb-99','Mar-99',
- 'Apr-99','May-99','Jun-99','Jul-99','Aug-99']
+ bc.categoryAxis.categoryNames = data_period
drawing.add(bc)
-# renderPM.drawToFile(drawing, 'example1.jpg','jpg')
- return True
+ drawing.save(formats=['png'],fnRoot=path+str(self.count),title="helo")
+# renderPM.drawToFile(drawing1, 'example1.jpg','jpg')
+ return path+str(self.count)+'.png'
report_sxw.report_sxw('report.print.indicators', 'account.report.history',
'addons/account_report/report/print_indicator.rml',
- parser=accounting_report1, header=False)
+ parser=accounting_report_indicator, header=False)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
diff --git a/addons/account_report/report/print_indicator.rml b/addons/account_report/report/print_indicator.rml
index 76107d82e52..305548844b5 100644
--- a/addons/account_report/report/print_indicator.rml
+++ b/addons/account_report/report/print_indicator.rml
@@ -10,6 +10,11 @@
+
+
+
+
+
@@ -49,7 +54,7 @@
-
+
@@ -127,7 +132,24 @@
|