Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

改变打印报表的文件名



  • 打印pdf的时候文件名都是单一的,不符合需求。
      找了一些资料说在setting里面的report修改  ,试了一些不行。

      后来看到一个从生成时候修改,
      很不错,分享下:

    找到web/controllers 下的main.py
      找到这句:
     

     file_name = '%s.%s' % (name_flag ,file_name, report_struct['format'])
    



      在前面添加

    &nbsp; if action.has_key(&#039;context&#039;):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action_context = action.get(&#039;context&#039;,{})<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if action_context.has_key(&#039;active_model&#039;) and action_context.has_key(&#039;active_id&#039;):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action_active_model = action_context.get(&#039;active_model&#039;,&#039;&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action_active_ids = action_context.get(&#039;active_ids&#039;, &#91;])<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if action_active_model and action_active_ids:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Use built-in ORM method to get data from DB<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m = req.session.model(action_active_model)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r = m.read(action_active_ids, False, context)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Parse result to create a better filename<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for i, item in enumerate(r):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if item.has_key(&#039;name&#039;):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if i == 0: <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file_name = (&#039;%s&#039;) % (item&#91;&#039;name&#039;])<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file_name = (&#039;%s-%s&#039;) % (file_name, item&#91;&#039;name&#039;])&nbsp; 
    



    ok, 后面生成的文件名你可以自己再设计...
     


Log in to reply