def create(self, cr, uid, ids, data, context=None):
temp = tempfile.NamedTemporaryFile(mode='w+t',suffix='.csv')
outfile = tempfile.NamedTemporaryFile(mode='w+b',suffix='.pdf')
glabels = tempfile.NamedTemporaryFile(mode='w+t',suffix='.glabels')
glabels.write(base64.b64decode(data.get('template')) if data.get('template') else None or self.template)
glabels.seek(0)
pool = registry(cr.dbname)
labelwriter = csv.DictWriter(temp,[h[self.col_name] for h in pool.get(self.model).read(cr,uid,pool.get(self.model).search(cr,uid,[]),[self.col_name])])
labelwriter.writeheader()
for c in range(self.count):
#~ labelwriter.writerow({p[self.col_name]:isinstance(p[self.col_value], (str, unicode)) and p[self.col_value].encode('utf8') or p[self.col_value] or '' for p in pool.get(self.model).read(cr,uid,pool.get(self.model).search(cr,uid,[]),[self.col_name,self.col_value])])})
labelwriter.writerow({p[self.col_name]: str(p[self.col_value]) if not str(p[self.col_value]) == '0.0' else '' for p in pool.get(self.model).read(cr,uid,pool.get(self.model).search(cr,uid,[]),[self.col_name,self.col_value], context=context)})
temp.seek(0)
res = os.system("glabels-3-batch -o %s -l -C -i %s %s" % (outfile.name,temp.name,glabels.name))
outfile.seek(0)
pdf = outfile.read()
outfile.close()
temp.close()
glabels.close()
return (pdf,'pdf')
评论列表
文章目录