Odoo 中文社区

    • 注册
    • 登录
    • 搜索
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组

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

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

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

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

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

    从OpenOffice Report的换页问题到OE Report Tags的实现原理.

    Odoo 开发与实施交流
    8
    9
    10743
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 左
      左奕 最后由 编辑

      在使用OpenOffice sxw文件实现一个类似于Invoice报表的简单工资单报表时,遇见一个不能让每个工资单占据单独的一页的问题.就是需要每打印完一个工资单,如果页面还留有空白,需要产生新页,而不是在原页上继续产生内容.
      我想要的内容(两条横线之间代表一页):
      这是第一页
      -------------------------
      Payslip1
                      xxxxxxxx
                      xxxxxxxx

      (预留的空白)

      -------------------------

      这是第二页
      -------------------------
      Payslip2
                    xxxxxxxxx
                    xxxxxxxxx

      (预留的空白)
      -------------------------

      但实际的效果是挤到了一起.
      -------------------------
      Payslip1
                    xxxxxxxxxx
                    xxxxxxxxxx

      PaySlip2
                    xxxxxxxxxx
                    xxxxxxxxxx
      -------------------------
      google了一下,搜到一些老外的解决方案,但都很模糊.不能解决我的问题.
      最后找到的原因是 因为我把循环工资单对象的tag: "[[ repeatIn(objects, 'p') ]]" 放在了section(即openoffice中对应的区域,对应生成rml中的<section>标签)中间,导致所有对象都在section中[color=red]连续[/color]绘制,无法自动跳页.
      而如果把 "[[ repeatIn(objects, 'p') ]]"放在sxw文件的第一行,生成的rml中"[[ repeatIn(objects, 'p') ]]"会在<story>标签中间,OE会为每个对象自动跳页.

      OK,到这里问题解决了.但是没明白report tag这东东到底是怎样实现的,黑盒对于程序员来说太可怕了.%>_<%. 研究下怎样它怎样实现的.
      (注明: 以下内容并不一定完全正确,如果看官有兴趣一定要自己debug下代码,看看究竟.)

      OpenERP 涉及到rml使用的report tag的实现主要有两个类:

      1. ${OPENERP_PATH}/bin/report/preprocess.py::report类. 望文生义,它的主要功能是在对tag实际内容处理之前,进行预处理. 主要是 repeatIn,removeParentNode,setTag这三个tag.本质上是通过lxml对xml文件内容的更改.
      比如:
      <para>This is a test[[ setTag('para','xpre') ]]</para>
      处理之后会变成
      <para rml_tag="setTag('para','xpre')">This is a test[[ '' ]]</para>
         
      <tr>
          <td>Row 1 [[repeatIn(o.order_line,'o')]] </td>
          <td>Row 2</td>
      </tr>
      处理之后变成
      <tr rml_loop="repeatIn(o.order_line,'o')">
              <td>Row 1 [['']] </td>
              <td>Row 2</td>
      </tr>
      这里就说明了repeatIn放在<section>,<story>中会产生的效果.

      2.  ${OPENERP_PATH}/bin/report/report_sxw.py::rml_parse类. 每一个标签都对应着rml_parse类中的一个方法,使用的是模板语言的通用方法:把它们放到一个context中,在解析模板的时候去查找调用.

      self.localcontext = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;user&#039;: user,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;company&#039;: user.company_id,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;repeatIn&#039;: self.repeatIn,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;setLang&#039;: self.setLang,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;setTag&#039;: self.setTag,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;removeParentNode&#039;: self.removeParentNode,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;format&#039;: self.format,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;formatLang&#039;: self.formatLang,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;logo&#039; : user.company_id.logo,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;lang&#039; : user.company_id.partner_id.lang,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;translate&#039; : self._translate,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;setHtmlImage&#039; : self.set_html_image<br />&nbsp; &nbsp; &nbsp; &nbsp; }
      



      举个例子 format标签的作用就是 去除字符串空格

      def format(self, text, oldtag=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; return text.strip()
      



      了解了这个实现方式,甚至可以在模板中间添加自己需要的新标签.

      写的不是特别清楚明白,不对的地方请大家指正.^_^

      1 条回复 最后回复 回复 引用 0
      • wjfonhand
        wjfonhand 最后由 编辑

        好帖,已置顶

        GoodERP -- Odoo China fork

        1 条回复 最后回复 回复 引用 0
        • C
          ccdos 最后由 编辑

          收藏,

          1 条回复 最后回复 回复 引用 0
          • mrshelly
            mrshelly 最后由 编辑

            应该是加精, 而不是置顶了....
            不知道 BBS是否有这个功能...

            1 条回复 最后回复 回复 引用 0
            • Q
              qfy815668377 最后由 编辑

              借地盘求助:

              用mako做OPENERP报告时, 打印出来PDF文件的底端出现文字切半现象,要不就是文字出现一半,还有一半看不到了。 怎么样设置才能解决?

              1 条回复 最后回复 回复 引用 0
              • ieitzyb
                ieitzyb 最后由 编辑

                留个脚印,稍后学习、试试。

                http://www.OuduPLM.com/ 苏州欧度软件,专注服装行业(鳴謝:37signals,Trello,ProcessON,重庆慧积,上海开阖)

                1 条回复 最后回复 回复 引用 0
                • M
                  mf1389004071 最后由 编辑

                  mark

                  1 条回复 最后回复 回复 引用 0
                  • Z
                    zxq1207 最后由 编辑

                    标记一下,我现在的单据做分页也是相当头疼

                    1 条回复 最后回复 回复 引用 0
                    • First post
                      Last post