Bugfix and modified account_report for printing indicators
authorJay Vora <jvo@tinyerp.com>
Tue, 14 Oct 2008 10:59:41 +0000 (16:29 +0530)
committerJay Vora <jvo@tinyerp.com>
Tue, 14 Oct 2008 10:59:41 +0000 (16:29 +0530)
bzr revid: jvo@tinyerp.com-20081014105941-yddpoupphfqkap8k

addons/account_report/report/print_indicator.py
addons/account_report/report/print_indicator.rml

index 8eb2d98..4649443 100644 (file)
@@ -36,6 +36,8 @@ from report.interface import report_int
 from reportlab.graphics.shapes import Drawing
 from reportlab.graphics.charts.barcharts import VerticalBarChart
 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
 
@@ -50,50 +52,85 @@ class accounting_report1(report_sxw.rml_parse):
             'lines':self.lines,
         })
         self.count=0
+        self.list=[]
 
     def lines(self,data):
         res={}
         result=[]
-        obj_ind=self.pool.get('account.report.report').browse(self.cr,self.uid,data['indicator_id'])
-        res = {
-            '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)
+        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 test1(self):
+    def test1(self,data,object):
+        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.count +=1
-        drawing = Drawing(400, 200)
+        drawing = Drawing(400, 300)
         data = [
-                 (13, 5, 20, 22, 37, 45, 19, 4,11,-5),
+                 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 = 155
+        bc.height = 245
         bc.width = 300
         bc.data = data
+        value_step=(abs(val_max)-abs(val_min))/5
+
         bc.strokeColor = colors.black
-        bc.valueAxis.valueMin = 0
-        bc.valueAxis.valueMax = 50
-        bc.valueAxis.valueStep = 10
+        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.barWidth=5
+
         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','kkk','fff']
+        bc.categoryAxis.categoryNames = data_period
         drawing.add(bc)
-        drawing.save(formats=['png'],fnRoot=tools.config['root_path']+"/Temp_report/Image"+str(self.count),title="helo")
+        drawing.save(formats=['png'],fnRoot=path+str(self.count),title="helo")
 #        renderPM.drawToFile(drawing1, 'example1.jpg','jpg')
-        return tools.config['root_path']+"/Temp_report/Image"+str(self.count)+'.png'
+        return path+str(self.count)+'.png'
 
 
 report_sxw.report_sxw('report.print.indicators', 'account.report.history',
index b8501bb..76107d8 100644 (file)
 </para>
 <section>
 <para style="P1">[[ repeatIn(lines(data['form']),'o')]]</para>
+<para>[['-'* 155]]</para>
 <blockTable colWidths="362.0,166.0" style="Table3">
 <tr>
 <td>
 </td>
 </tr>
 </blockTable>
-<para style="P1">[[ o['disp_graph'] and setTag('para','image',{'file':test()}) or removeParentNode('para') ]]</para>
+<para style="P1">[[ o['disp_graph'] and setTag('para','image',{'file':test(data['form'],o)}) or removeParentNode('para') ]]</para>
 
 <para style="P11"><b>Expression :</b> [[ o['expression'] ]]</para>
 <para style="P11"><b>Notes :</b> [[ o['note'] ]]</para>
+<para style="P3">
+<font color="white"> </font>
+</para>
 </section>
 </story>
 </document>