Account_Report:PDF Insertion Utility Developed for Indicators.

bzr revid: jvo@tinyerp.com-20081119091836-x9wnwxkfa8nzixls
This commit is contained in:
Jay Vora 2008-11-19 14:48:36 +05:30
parent 9c33c10144
commit 25020a42c3
5 changed files with 174 additions and 31 deletions

View File

@ -5,5 +5,12 @@
<report auto="False" id="report_print_indicators" model="account.report.history" name="print.indicators" rml="account_report/report/print_indicator.rml" string="Indicators"/>
<report
auto="False"
id="report_indicator_pdf"
menu="False"
model="account.report.report"
name="print.indicator.pdf"
string="Print Indicators in PDF"/>
</data>
</openerp>

View File

@ -3,5 +3,8 @@
<data>
<wizard id="wizard_print_indicators" name="print.indicators" string="Print Indicators"/>
<menuitem action="wizard_print_indicators" type="wizard" parent="account_report.menu_action_account_report_tree_view" id="menu_wizard_print_indicators"/>
<wizard id="wizard_indicators_with_pdf" model="account.report.report" name="print.indicators.pdf" string="Indicators in PDF" keyword="client_action_multi" />
<!--<menuitem action="wizard_indicators_with_pdf" type="wizard" parent="account_report.menu_action_account_report_tree_view" id="menu_wizard_print_indicators_with_pdf"/>-->
</data>
</openerp>

View File

@ -96,6 +96,7 @@ class accounting_report_indicator(report_sxw.rml_parse):
self.treecount=0
self.list=[]
self.header_name=self.header_val=[]
self.main_dict={}
def repeatIn(self, lst, name, nodes_parent=False,td=False,width=[],value=[],type=[]):
self._node.data = ''
@ -202,39 +203,61 @@ class accounting_report_indicator(report_sxw.rml_parse):
theme.default_font_size = 12
tb = text_box.T(loc=(0,700),line_style=line_style.darkblue,text=str(obj_history.code))
base_x=100
base_y=700
if obj_history.child_ids:
tb.add_arrow((100, 700))
can.line(line_style.black,base_x-30,base_y,base_x-30,base_y-(50*(len(obj_history.child_ids)-1)))
tb.draw()
self.child_dist=0
def draw_tree(obj_his,base_x,base_y,level=0):
self.child_dist=0
for i in range(len(obj_his.child_ids)):
can.line(line_style.black,base_x-30,base_y,base_x-30,base_y-(50*(i+len(obj_his.child_ids[i].child_ids))))
if i<>0:
a = arrow.T(head_style = 1)
if self.child_dist:
diff=self.child_dist
else:
diff=self.child_dist+i
a.draw([(base_x-(30),base_y-(50*diff)), (base_x,base_y-(50*diff))])
if obj_his.child_ids[i].child_ids:
tb12 = text_box.T(loc=(base_x,base_y-(50*(self.child_dist))), text=str(obj_his.child_ids[i].code))
tb12.add_arrow((base_x+(100*(level+1)),base_y-(50*(self.child_dist))))
tb12.draw()
draw_tree(obj_his.child_ids[i],base_x+(100*(level+1)),base_y-(50*(self.child_dist)),level+1)
level=0
self.level=0
self.child_dist=0
def draw_tree2(obj_history,base_x,base_y,level=0,i=0):
self.line_y=base_y
if obj_history.child_ids:
if self.child_dist:
diff=i*self.child_dist
self.child_dist=0
else:
tb12 = text_box.T(loc=(base_x,base_y-(50*(i+self.child_dist))), text=str(obj_his.child_ids[i].code))
tb12.draw()
self.child_dist=len(obj_his.child_ids[i].child_ids)
#
draw_tree(obj_history,base_x,base_y,0)
diff=i
if self.level>0 and (base_y-(50*diff)) >= self.level:
base_y=self.level-(50*i)
else:
base_y=base_y-(50*diff)
tb = text_box.T(loc=(base_x,base_y),line_style=line_style.darkblue,text="/hC"+str(obj_history.code)+":\n"+str(obj_history.amount))
tb.add_arrow((base_x+100,base_y))
tb.draw()
if level!=0:
a = arrow.T(head_style = 1)
a.draw([(base_x-30,base_y), (base_x,base_y)])
level+=1
if i>0:
can.line(line_style.black,base_x-30,base_y,base_x-30,self.line_y)
i=0
for child in obj_history.child_ids:
draw_tree2(child,base_x+(100),base_y,level,i)
i+=1
child_dist=len(obj_history.child_ids)
self.child_dist=max(self.child_dist,child_dist)
else:
if self.level>0 and (base_y-(50*i)) >= self.level:
base_y=self.level-(50)
else:
base_y=base_y-(50*(i))
tb12 = text_box.T(loc=(base_x,base_y), text=str(obj_history.code))
tb12.draw()
if i>0:
can.line(line_style.black,base_x-30,base_y,base_x-30,self.line_y)
a = arrow.T(head_style = 1)
a.draw([(base_x-30,base_y), (base_x,base_y)])
self.level=base_y
self.line_y=900
draw_tree2(obj_history,0,900,0)
can.close()
os.system('cp '+'tree_image'+str(self.treecount)+'.png ' +path+str(self.treecount)+'.png')

View File

@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
@ -21,5 +21,6 @@
##############################################################################
import wizard_print_indicators
import wizard_print_indicators_with_pdf
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,109 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard
import pooler
import time
import datetime
import sys
from mx.DateTime import *
import tools
from report.render import render
from report.interface import report_int
import os
import base64
import StringIO
form = '''<?xml version="1.0"?>
<form string="Print Indicators with PDF">
<label string="Select the PDF file on which Indicators will be printed."/>
<newline/>
<field name="file" colspan="4"/>
</form>'''
fields = {
'file': {'string':'Select a PDF File', 'type':'binary','required':True,'filters':['*.pdf']},
}
class external_pdf(render):
def __init__(self, pdf):
render.__init__(self)
self.pdf = pdf
self.output_type='pdf'
def _render(self):
return self.pdf
class report_custom(report_int):
def create(self, cr, uid, ids, data, context={}):
pool = pooler.get_pool(cr.dbname)
obj_indicator = pool.get('account.report.report')
code_ids = obj_indicator.browse(cr,uid,data['id'])
self.list={}
def find_child(obj):
self.list[obj.code]=str(obj.amount)
if obj.child_ids:
for child in obj.child_ids:
find_child(child)
return True
find_child(code_ids)
file_contents=base64.decodestring(data['form']['file'])
fp = StringIO.StringIO(file_contents)
infile = open(tools.config['addons_path']+"/test.pdf", 'wb')
infile.write(fp.read())
infile.close()
obj_user=pool.get('res.users').browse(cr,uid,uid)
self.list['printing_user']=obj_user.name
self.list['company_name']=obj_user.company_id.name
self.list['company_vat']=obj_user.company_id.partner_id.vat
self.list['printing_time']=time.strftime('%H:%M:%S')
self.list['printing_date']=time.strftime('%D')
tools.pdf_utils.fill_pdf(tools.config['addons_path']+"/test.pdf",'/tmp/output.pdf',self.list)
self.obj = external_pdf(file('/tmp/output.pdf').read())
self.obj.render()
return (self.obj.pdf, 'pdf')
report_custom('report.print.indicator.pdf')
class wizard_print_indicators_with_pdf(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':form, 'fields':fields, 'state':[('end','Cancel'),('print','Print')]}
},
'print': {
'actions':[],
'result' :{'type':'print','report':'print.indicator.pdf', 'state':'end'}
}
}
wizard_print_indicators_with_pdf('print.indicators.pdf')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: