我正在尝试使用一种方法打印多张发票,到目前为止我已经尝试了两种方法,从在 openerp 中使用一个按钮和调用该方法的方法,以及通过外部定义一个从外部调用打印但脚本失败的 python 脚本内部服务器错误。这是两种方法,在按钮上调用了 1 个方法
def update_invoice_report(self,cr,uid,ids,context=None):
compare_date=datetime.now().date().strftime("%Y-%m-%d")
val=[]
count=0
# file_name='/home/chaitalikelsukar/Downloads/invoice_print (*).pdf'
# for j in self.browse(cr,uid,ids):
# if not j.model_name :
# raise osv.except_osv(('Alert'),('Select Model Invoice'))
# if not j.unique_number:
# raise osv.except_osv(('Alert'),('Enter Number'))
use_date=compare_date
# if j.model_name=='invoice':
query="select id from invoice_adhoc_master where invoice_date >= '2017-05-01' and invoice_date < '2017-06-01'"
cr.execute(query)
list1=cr.fetchall()
print list1
contract_search=[i[0] for i in list1 if i[0]]
if contract_search:
for i in contract_search:
data =self.pool.get('invoice.adhoc.master').read(cr,uid,contract_search,context)
datas={
'ids':ids,
'model':'invoice.adhoc.master',
'form':data
}
return {
'type':'ir.actions.report.xml',
'report_name':'invoice_print'
'datas':datas
}
上面的代码返回范围内的所有发票,但打印后我无法移动它
方法二:
def awesome():
f = open('config.txt', 'r')
lines = f.readlines()
# line_iter= iter(lines)
login_credentials = []
file_name = ''
dbname=''
line =lines[0]
string_pdf =''
# print line
# try:
if (True):
dbname=str(line.split('=')[1]).split('\n')[0]
# print dbname
if dbname:
# connect_string="dbname='"+dbname+"' user='"+'openerp'+"' host='"+localhost+"' password='"+'openerp'+"' "
# else:
connect_string="dbname='"+dbname+"' user='"+'openerp'+"' host='"+'localhost'+"' password='"+'openerp'+"' "
conn_pg = psycopg2.connect(connect_string)
pg_cursor = conn_pg.cursor()
# pg_cursor.execute("")
pg_cursor.execute("SELECT id from res_company where dbname='%s'"%dbname)
invoice_ids = pg_cursor.fetchall()
if tuple(invoice_ids):
pg_cursor.execute("SELECT company_id from account_account limit 1")
invoice_ids =pg_cursor.fetchone()
pg_cursor.execute("select vpn_ip_address,port,dbname,pwd,user_name from res_company where id =%s"%invoice_ids)
company_data=pg_cursor.fetchone()
# print invoice_ids,company_data
vpn_ip_addr = company_data[0]
port =company_data[1]
dbname = company_data[2]
pwd = company_data[3]
user_name = company_data[4]
pg_cursor.execute("select login from res_users where id='%s'"%user_name)
user_name=pg_cursor.fetchone()[0]
username = user_name
pwd = pwd
db=dbname = dbname
# print dbname
log = ('http://%s:%s/xmlrpc/common')%(vpn_ip_addr,port)
obj = ('http://%s:%s/xmlrpc/object')%(vpn_ip_addr,port)
print_sock = ('http://%s:%s/xmlrpc/report')%(vpn_ip_addr,port)
model='invoice.adhoc.master'
sock_common = xmlrpclib.ServerProxy (log)
uid = sock_common.login(dbname, username, pwd)
sock = xmlrpclib.ServerProxy(obj)
print_sock=xmlrpclib.ServerProxy(print_sock)
pg_cursor.execute("select id from invoice_adhoc_master where invoice_date >='2017-05-01' and invoice_date < '2017-05-31'")
invoice_ids=pg_cursor.fetchall()
for i in invoice_ids:
data= sock.execute(dbname, uid, pwd, 'invoice.adhoc.master', 'read',i)
print data
# id_report = print_sock.report(dbname, uid, pwd, model, i, {'model': 'invoice_print', 'id': i[0], 'report_type':'pdf'})
id_report = print_sock.report(dbname,uid,pwd,model,i,{'type':'ir.actions.report.xml','report_name':'invoice_print','datas':data})
# return {
# 'type': 'ir.actions.report.xml',
# 'report_name': 'invoice_print',
# 'datas': datas,
# }
partner_ids= sock.execute(dbname, uid, pwd, 'invoice.adhoc.master', 'print_invoice',i)
# id_report = print_sock.report(dbname,uid,pwd,model,i,partner_ids)
report = print_sock.report_get(db, uid, pwd, id_report)
# string_pdf = base64.decodestring(report)
file_pdf = open('/tmp/file1.pdf','w')
file_pdf.write(partner_ids)
file_pdf.close()
# print_sock.report_get(db, uid, pwd, id_report)
# print partner_ids,"\n\n\n\n",id_report
# m
# report_id = print_sock.report(db, uid, pwd, 'invoice.adhoc.master', partner_ids, {'model': 'invoice.adhoc.master', 'id': partner_ids, 'report_type': 'pdf'})
# time.sleep(3);
# state = False
# attempt = 0
# while not state:
# state = report['state']
# if not state:
# time.sleep(1)
# attempt += 1
# if attempt > 200:
# print 'Abort, too long delay'
return partner_ids
# return {
这失败了
report = print_sock.report_get(db, uid, pwd, id_report)
和
xmlrpclib.protocolerror:<protocolerror for localhost:8765/xmlrpc/report: 500 internal server error>