默认情况下,合作伙伴分类帐报告名称为“account.report_partnerledger.pdf”。我想将其更改为客户名称(例如:如果客户名称为john,则为john.pdf)。怎么做?
答案 0 :(得分:1)
答案 1 :(得分:1)
转到Settings > Actions > Reports
并搜索Partner Ledger
。
填写
Download filename
字段。此字段被评估为jinja2模板,objects
是要打印的记录的浏览记录列表,o
是第一条记录。如果您的模型包含名称字段,您可以编写类似${o.name}_report.pdf
的文件名。
答案 2 :(得分:0)
安装'report_custom_filename'模块并在report_routes方法中进行以下更改
def report_routes(self, reportname, docids=None, converter=None, **data):
cr, uid, context,registry = request.cr, request.uid, request.context,request.registry
response = super(ReportController, self).report_routes(
reportname, docids=docids, converter=converter, **data)
if docids:
docids = [int(i) for i in docids.split(',')]
report_xml = http.request.session.model('ir.actions.report.xml')
report_ids = report_xml.search(
[('report_name', '=', reportname)])
options_data = simplejson.loads(data['options'])
partner_id = options_data.get('ids')
for report in report_xml.browse(report_ids):
if not report.download_filename:
continue
#objects = http.request.session.model(report.model).browse(docids or [])
objects = request.registry[report.model].browse(cr, uid, partner_id, context=context)
customer_name = str(objects.name)
generated_filename = email_template.mako_template_env\
.from_string(report.download_filename)\
.render({
'objects': objects,
'o': customer_name,
'object': objects[:1],
'ext': report.report_type.replace('qweb-', ''),
})
response.headers['Content-Disposition'] = content_disposition(
generated_filename)
return response