report_xml.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:odoo-report 作者: vertelab 项目源码 文件源码
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 = None
        for p in pool.get(self.model).read(cr,uid,ids):
            if not labelwriter:
                labelwriter = csv.DictWriter(temp,p.keys())
                labelwriter.writeheader()
            for c in range(self.count):
                labelwriter.writerow({k:isinstance(v, (str, unicode)) and v.encode('utf8') or str(v) for k,v in p.items()})
        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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号