OpenERP Spreedsheet(ods,xls) report
Sample code:
"""
Wizard xml file:
================
<field name="name"/>
<field name="data"/>
<button icon="gtk-print" name="produce_xls" string="Xls" type="object" colspan="2" default_focus="1" />
wizard python file:
==================
Add fields:
----------
"data":fields.binary("File",readonly=True),
"name":fields.char("Filename",16,readonly=True),
Add function;
------------
# above button action """
def produce_xls(self, cr, uid, ids, context={}):
""" function to create xls """
import StringIO
import base64
try:
import xlwt
except:
raise osv.except_osv('Warning !','Please download python xlwt module from\nhttp://pypi.python.org/packages/source/x/xlwt/xlwt-0.7.2.tar.gz\nand install it')
wiz=self.browse(cr,uid,ids[0])
where_sql = []
""" getting form data for filteration"""
if where_sql:
where_sql = ' or '+' and '.join(where_sql)
else:
where_sql=''
cr.execute('''
select * from sale_order '''+ where_sql + '''
''')
data = cr.dictfetchall()
record={}
sno=0
wbk = xlwt.Workbook()
style1 = xlwt.easyxf('font: bold on,height 240,color_index 0X36;' 'align: horiz center;''borders: left thin, right thin, top thin')
s1=0
"""adding a worksheet along with name"""
sheet1 = wbk.add_sheet('Work Orders')
s2=1
sheet1.col(0).width = 2000
sheet1.col(1).width = 6000
sheet1.col(2).width = 4000
sheet1.col(3).width = 4000
sheet1.col(4).width = 4000
sheet1.col(5).width = 4000
sheet1.col(6).width = 4000
""" writing field headings """
sheet1.write(s1,0,"Id.",style1)
sheet1.write(s1,1,"Name",style1)
sheet1.write(s1,2,"Label-3",style1)
sheet1.write(s1,3,"Label-4",style1)
sheet1.write(s1,4,"Label-5",style1)
sheet1.write(s1,5,"Label-6",style1)
sheet1.write(s1,6,"Label-7",style1)
"""writing data according to query and filteration in worksheet"""
serial_no=1
for ele in data:
sheet1.write(s2,0,serial_no)
sheet1.write(s2,1,ele['id'])
sheet1.write(s2,2,ele['date_order'])
sheet1.write(s2,3,ele['name'])
sheet1.write(s2,4,ele['create_date'])
sheet1.write(s2,5,ele['requested_date'])
sheet1.write(s2,6,ele['id'])
serial_no+=1
s2+=1
tot_buf=0
tot_req=0
tot_req_tot=0
tot_tentative_1=0
tot_tentative_2=0
"""Parsing data as string """
file_data=StringIO.StringIO()
o=wbk.save(file_data)
"""string encode of data in wksheet"""
out=base64.encodestring(file_data.getvalue())
"""returning the output xls as binary"""
return self.write(cr, uid, ids, {'data':out, 'name':'Test'+'.xls'}, context=context)
OpenERP Terminal log Info
OpenERP Report Flow
Creating a Pdf or Xls Report
Types of Report
1.Normal Report
2.Wizard Report
Wizard
1.Interface
2.Osv Memory
Report creation using Osv Memory
1.wizard.py file for field and function
2.view.xml file for view
3.report.rml file for report (for pdf report)
wizard.py
1.In .py file add the required fields.
2.model name may be like sample.wiz.
3.define function to do action with required queries.
4.make sure rml file has been parsed with reference to it’s name and rml path(For Pdf report).
5.create a binary field to return xls generated(For Xls report).
6.need python-xlwt module installed(For Xls report).
7.write value in worksheet by write value enter row,column and style etc…(For Xls report).
8.Parse writen value as String by using StringIO(For Xls report).
9.encode the string use base64.Encodestring()(For Xls report)..
10.Then return the binary(For Xls report).
view.xml
1.Create a form with required fields.
2.Create a action window to call the form with res.model and view type referring above view.
3.Create a Menu to call the above act window referring above act window.
4.Create a Menu for report make sure the correct rml path and resource model(For Pdf report).
report.rml(For Pdf report)
1.create a rml file.
2.make design changes such as styles,tables,layout etc…..
3.print field by calling objects and regular expression.
Add OpenERP client Shortcut in ubuntu 12.04 Unity Launcher
You are installed the openerp client in your home folder
just navigate the path : /home/user/openerp-client-6.1/
and create a file named: openerp.desktop
and append the following lines:
[Desktop Entry] Version=1.0 Name=openerp_client_6_1 GenericName=openerp_client_6_1 X-GNOME-FullName=Openerp_Client_6_1 Comment=OpenERP Client Type=Application Categories=Application;Development Exec=/home/user/workspace/openerp-client-6.1/bin/openerp-client.py TryExec=/home/user/workspace/openerp-client-6.1/bin/openerp-client.py Terminal=false StartupNotify=true Icon=/home/user/workspace/openerp-client-6.1/debian/pixmaps/openerp-client.xpm
Then Drag the newly created file to the Launcher.
That’s all
It’s permanently here..
Indian Rupee ₹ Symbol in Ubuntu 9.10 & 10.04
PPA for Ubuntu 9.10 Karmic Koala and 10.04 Lucid Lynx users
Easily install the Ubuntu Font Family and also receive updates
Open Terminal and type:
sudo add-apt-repository ppa:webupd8team/ubuntu-font-family
sudo apt-get update
sudo apt-get install ttf-ubuntu-font-family
Use <Ctrl-Shift-U> 2 0 b 9, then <Enter>
Desktop Notification – using python
#!/usr/bin/python
import sys
import pynotify
if __name__ == "__main__":
if not pynotify.init("icon-summary-body"):
sys.exit(1)
n = pynotify.Notification(
"Mr. Rajkumar",
"Cron Running Successfully",
"notification-message-im")
n.show()
we are using dump and restore commands for DB backup and restoring
below code is used to backup db from one server to restore another server
import os
import pxssh
import pexpect
#DB backup local in local folder
#below line excute dump command syntax(pg_dump -U {user-name} {source_db} -f {dumpfilename.sql})
#change ur appropiate names
os.system('pg_dump -U openerp test_001 -f dump_test.backup')
print "backup_successfull"
######################################################################
#backup file send to server
#scp(secured copy) syntax "scp 'source-path' 'destination-path'"---change source-path and destination-path
child = pexpect.spawn('scp /home/usr_name/Desktop/dump_test.backup usr_name@123.123.123.123:///home/usr_name')
child.expect('.*password:*')
#change password in below line
child.sendline('secret_passwd')
child.expect(pexpect.EOF)
#####################################################################
#Create a server login and restore DB
s = pxssh.pxssh()
#change ur hostID, username, password
if not s.login ('123.123.123.111', 'username', 'secret_passwd'):
print "SSH session failed on login."
print str(s)
else:
print "SSH session login successful in 123.123.123.111"
#below line excute restore command syntax(psql -U {user-name} -d {desintation_db}-f {dumpfilename.sql}})
s.sendline('psql -U db_user -d dump_ssh -f dump_test.backup')
s.prompt()
print s.before # print everything before the prompt.
s.logout()
#end of code


