gpt4 book ai didi

openerp-7 - OpenERP 自定义报告文件名

转载 作者:行者123 更新时间:2023-12-01 12:47:38 26 4
gpt4 key购买 nike

我想自定义报告文件名。

例如,当我下载一张发票时,我会有类似“Invoice.pdf”的文件名。我想要的是“invoice_number.pdf”之类的东西,但我不知道如何使用动态文件名?

最佳答案

我找到了 7.0 和当前主干的方法:

  1. 要快速修复,请查看以下中的 Reports 类:

    openerp-7.0\web\addons\web\controllers\main.py
  2. 报告名称设置在名为 file_name 的变量中:

    file_name = '%s.%s' % (file_name, report_struct['format'])
  3. 找到这一行并在它之前插入这部分:

    '''
    YP: Added proc. to create reports with real object names (the object must have a field named "name"):
    eg: "PO00006.pdf" instead of "Request For Quotation.pdf" for a single object report
    "PO00006-PO00002.pdf" instead of "Request For Quotation.pdf" for a multiple objects report
    '''

    # Try to get current object model and their ids from context
    if action.has_key('context'):
    action_context = action.get('context',{})
    if action_context.has_key('active_model') and action_context.has_key('active_id'):
    action_active_model = action_context.get('active_model','')
    action_active_ids = action_context.get('active_ids', [])
    if action_active_model and action_active_ids:
    # Use built-in ORM method to get data from DB
    m = req.session.model(action_active_model)
    r = m.read(action_active_ids, False, context)
    # Parse result to create a better filename
    for i, item in enumerate(r):
    if item.has_key('name'):
    if i == 0:
    file_name = ('%s') % (item['name'])
    else:
    file_name = ('%s-%s') % (file_name, item['name'])

关于openerp-7 - OpenERP 自定义报告文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14434846/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com