Python 2.7 在odoo中创建记录时如何将xls报告添加为附件
我已经使用report_xls模块创建了xls报告。现在我想在创建新记录时将其添加为xls报告的附件。我用的是奥多v8Python 2.7 在odoo中创建记录时如何将xls报告添加为附件,python-2.7,odoo-8,Python 2.7,Odoo 8,我已经使用report_xls模块创建了xls报告。现在我想在创建新记录时将其添加为xls报告的附件。我用的是奥多v8 attachment_obj = self.pool.get('ir.attachment') ir_actions_report = self.pool.get('ir.actions.report.xml') matching_reports = ir_actions_report.search(cr, uid, [('report_name','=','timeshee
attachment_obj = self.pool.get('ir.attachment')
ir_actions_report = self.pool.get('ir.actions.report.xml')
matching_reports = ir_actions_report.search(cr, uid, [('report_name','=','timesheet.auto.invoice.xls')])
if matching_reports:
report = ir_actions_report.browse(cr, uid, matching_reports[0])
report_service = report.report_name
if report.report_type in ['qweb-html', 'qweb-pdf', 'xls']:
result, format = self.pool['report'].get_pdf(cr, uid, [x.id], report_service, context=context), 'xls'
else:
result, format = openerp.report.render_report(cr, uid, report_service, {'model': account_obj}, context)
result = base64.b64encode(report)
file_name = re.sub(r'[^a-zA-Z0-9_-]', '_', 'Timesheet Report')
file_name += ".xls"
attachment_id = attachment_obj.create(cr, uid,
{
'name': report.report_name,
'datas': base64.b64encode(report.report_name),
'report_name': 'timesheet.auto.invoice.xls',
'res_model': 'account.invoice',
'res_id': x.id,
'type': 'binary'
}, context)
你的问题是什么还不清楚。问题中的代码已经创建了一个与您的
帐户.invoice
方法关联的附件。您的问题是什么还不清楚。问题中的代码已经创建了一个与您的帐户关联的附件。invoice
方法。