跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. 【分享-oe嵌入qweb】用js读取数据库数据,用类似html语言重写web报表

【分享-oe嵌入qweb】用js读取数据库数据,用类似html语言重写web报表

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
11 帖子 8 发布者 10.1k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • C 离线
    C 离线
    ccdos
    写于 最后由 编辑
    #2

    先贊一下,

    暂时看不懂

    1 条回复 最后回复
    0
    • W 离线
      W 离线
      winson97
      写于 最后由 编辑
      #3

      历害哦。

      1 条回复 最后回复
      0
      • digitalsatoriD 离线
        digitalsatoriD 离线
        digitalsatori 管理员
        写于 最后由 编辑
        #4

        分享的很完整,谢谢!

        【上海先安科技】(tony AT openerp.cn)

        1 条回复 最后回复
        0
        • Z 离线
          Z 离线
          zhong_163
          写于 最后由 编辑
          #5

          结合 上面几篇文章  掉坑了,然后 找老刘 要了 样例  bzr branch lp:~niv-openerp/+junk/oepetstore -r 1

          然后从坑里 爬了出来

          安装 这个  教程 [检测到链接无效,已移除] br />
          看 楼主的 顺序 ,没理解前都会copy  看看 能不能运行。。  js  ,xml 写了,然后掉坑里了

          1、出菜单 ,贴代码

          &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;openerp&gt;<br />&nbsp; &nbsp; &lt;data&gt;<br />&nbsp; &nbsp; &nbsp; &lt;!-- Top menu item --&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;menuitem name=&quot;Test&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id=&quot;menu_test_root&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sequence=&quot;30&quot;/&gt;<br />&nbsp; &nbsp;  &lt;record model=&quot;ir.actions.client&quot; id=&quot;action_client_example&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;Example Client Action&lt;/field&gt;<br />&nbsp;  &lt;!-- 此处 name&nbsp; 修改了 浏览器 title&nbsp; &nbsp; --&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;tag&quot;&gt;petstore.homepage&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp;  &lt;!-- 此处 tag 内容 要对应&nbsp; js&nbsp; &nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp;  instance.web.client_actions.add(&#039;petstore.homepage&#039;, &#039;instance.oepetstore.HomePage&#039;);<br /><br />这个 阿狸木有 解释,或者不解释 。<br /><br />济南-stone&nbsp; 提示 过 , “找action.tag是否写对”&nbsp; 结果不得要领<br />看了样例才知道<br />&nbsp; &nbsp; &nbsp; &nbsp;  --&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br /> &lt;!-- 此处 tag 内容 要对应&nbsp; js&nbsp; &nbsp;  这个 阿狸木有 解释,或者不解释 。<br />&nbsp; --&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;menuitem id=&quot;test_qweb_menu&quot; name=&quot;test qweb&quot; sequence=&quot;20&quot; parent=&quot;menu_test_root&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;menuitem action=&quot;action_client_example&quot; id=&quot;menu_client_example&quot; parent=&quot;test_qweb_menu&quot; name=&quot;test report qweb&quot;/&gt;<br />&nbsp; &nbsp; &lt;/data&gt;<br />&lt;/openerp&gt;
          






          2 、js 代码


          <br />openerp.oepetstore = function(instance) {<br />&nbsp; &nbsp; var _t = instance.web._t,<br />&nbsp; &nbsp; &nbsp; &nbsp; _lt = instance.web._lt;<br />&nbsp; &nbsp; var QWeb = instance.web.qweb;<br /><br />&nbsp; &nbsp; instance.oepetstore = {};<br /><br /> /*&nbsp;  instance.oepetstore.HomePage = instance.web.Widget.extend({<br />&nbsp; &nbsp; &nbsp; &nbsp; start: function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(&quot;pet store home page loaded&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; },<br />&nbsp; &nbsp; });<br />&nbsp; &nbsp; */<br />&nbsp; &nbsp; instance.oepetstore.HomePage = instance.web.Widget.extend({<br />&nbsp; &nbsp; &nbsp; &nbsp; start: function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var self = this;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var model = new instance.web.Model(&quot;message_of_the_day&quot;);<br />//message_of_the_day&nbsp;  是py 定义了一个 类&nbsp; <br />//下面的 my_method&nbsp; 在py 类message_of_the_day&nbsp; &nbsp; 里有定义<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model.call(&quot;my_method&quot;, &#91;], {context: new instance.web.CompoundContext()}).then(function(result) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.$el.append(&quot;&lt;div&gt;Hello &quot; + result[&quot;hello&quot;] + &quot;&lt;/div&gt;&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // will show &quot;Hello world&quot; to the user<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br />&nbsp; &nbsp; &nbsp; &nbsp; },<br />&nbsp; &nbsp; });<br />// instance.oepetstore.btn_start&nbsp; 是 copy 梦菇的 代码 ,木有 调用<br />&nbsp; &nbsp; instance.oepetstore.btn_start = function() {<br />&nbsp; &nbsp; &nbsp; &nbsp; var self = this;<br />&nbsp; &nbsp; &nbsp; &nbsp; alert(&#039;test&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; };<br />&nbsp; &nbsp; <br />&nbsp;  <br />&nbsp; &nbsp; function aaa(){<br />&nbsp; &nbsp; &nbsp; &nbsp; alert(123);<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; // 这里 定义了 ,然后&nbsp; xml 里 才能调用&nbsp; &nbsp; &nbsp;  &lt;field name=&quot;tag&quot;&gt;petstore.homepage&lt;/field&gt;<br />&nbsp; &nbsp; instance.web.client_actions.add(&#039;petstore.homepage&#039;, &#039;instance.oepetstore.HomePage&#039;);<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; instance.web.client_actions.add(&#039;bt_start&#039;, &#039;instance.oepetstore.btn_start&#039;);<br /><br /><br />}<br />
          




          3、贴下 py 代码

          <br />from openerp.osv import osv, fields<br /># 通过 js&nbsp; <br /># var model = new instance.web.Model(&quot;message_of_the_day&quot;);<br /># 调用 该类 <br />class message_of_the_day(osv.osv):<br />&nbsp; &nbsp; _name = &quot;message_of_the_day&quot;<br /><br />#通过&nbsp; js <br />#&nbsp; model.call(&quot;my_method&quot;, &#91;], {context: new instance.web.CompoundContext()}).then(function(result) {<br />#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.$el.append(&quot;&lt;div&gt;Hello &quot; + result[&quot;hello&quot;] + &quot;&lt;/div&gt;&quot;);<br /># 调用&nbsp; 下面 方法&nbsp; 通过 model.call (&quot;my_method&quot;, ....<br />&nbsp; &nbsp; def my_method(self, cr, uid, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; return {&quot;hello&quot;: &quot;world&quot;}<br /><br />&nbsp; &nbsp; _columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;message&#039;: fields.text(string=&quot;Message&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;color&#039;: fields.char(string=&quot;Color&quot;, size=20),<br />&nbsp; &nbsp; }<br />
          



          这样 界面可以出  hello  world

          1 条回复 最后回复
          0
          • 阿 离线
            阿 离线
            阿狸
            写于 最后由 编辑
            #6

            [quote author=行云流水 link=topic=16554.msg28741#msg28741 date=1408090429]
            结合 上面几篇文章  掉坑了,然后 找老刘 要了 样例  bzr branch lp:~niv-openerp/+junk/oepetstore -r 1

            然后从坑里 爬了出来

            安装 这个  教程 [检测到链接无效,已移除] br />
            看 楼主的 顺序 ,没理解前都会copy  看看 能不能运行。。  js  ,xml 写了,然后掉坑里了

            1、出菜单 ,贴代码

            &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;openerp&gt;<br />&nbsp; &nbsp; &lt;data&gt;<br />&nbsp; &nbsp; &nbsp; &lt;!-- Top menu item --&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;menuitem name=&quot;Test&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id=&quot;menu_test_root&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sequence=&quot;30&quot;/&gt;<br />&nbsp; &nbsp;  &lt;record model=&quot;ir.actions.client&quot; id=&quot;action_client_example&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;Example Client Action&lt;/field&gt;<br />&nbsp;  &lt;!-- 此处 name&nbsp; 修改了 浏览器 title&nbsp; &nbsp; --&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;tag&quot;&gt;petstore.homepage&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp;  &lt;!-- 此处 tag 内容 要对应&nbsp; js&nbsp; &nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp;  instance.web.client_actions.add(&#039;petstore.homepage&#039;, &#039;instance.oepetstore.HomePage&#039;);<br /><br />这个 阿狸木有 解释,或者不解释 。<br /><br />济南-stone&nbsp; 提示 过 , “找action.tag是否写对”&nbsp; 结果不得要领<br />看了样例才知道<br />&nbsp; &nbsp; &nbsp; &nbsp;  --&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br /> &lt;!-- 此处 tag 内容 要对应&nbsp; js&nbsp; &nbsp;  这个 阿狸木有 解释,或者不解释 。<br />&nbsp; --&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;menuitem id=&quot;test_qweb_menu&quot; name=&quot;test qweb&quot; sequence=&quot;20&quot; parent=&quot;menu_test_root&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;menuitem action=&quot;action_client_example&quot; id=&quot;menu_client_example&quot; parent=&quot;test_qweb_menu&quot; name=&quot;test report qweb&quot;/&gt;<br />&nbsp; &nbsp; &lt;/data&gt;<br />&lt;/openerp&gt;
            





            这样 界面可以出  hello  world

            [/quote]

            我上面说了, 注意qweb的name字段等与js中的关联,就不一一说了,仔细看就看出来了。

            。。。

            PS: 你这坑掉的可真深啊 ;D

            1 条回复 最后回复
            0
            • 神 离线
              神 离线
              神仙采葡萄
              写于 最后由 编辑
              #7

              具体怎么把读取数据后的表格导出成一个excel文件呢?谢谢!

              1 条回复 最后回复
              0
              • Z 离线
                Z 离线
                zxq1207
                写于 最后由 编辑
                #8

                学习一下,用这种方式做报表似乎还是很方便的。。。

                1 条回复 最后回复
                0
                • 阿 离线
                  阿 离线
                  阿狸
                  写于 最后由 编辑
                  #9

                  [quote author=神仙采葡萄 link=topic=16554.msg28959#msg28959 date=1410492180]
                  具体怎么把读取数据后的表格导出成一个excel文件呢?谢谢!
                  [/quote]
                  开发导出模块,大概就是用python读取数据库然后导出成excel。
                  一般用xlrd等

                  1 条回复 最后回复
                  0
                  • A 离线
                    A 离线
                    aornor
                    写于 最后由 编辑
                    #10

                    多谢分享

                    1 条回复 最后回复
                    0

                    • 登录

                    • 没有帐号? 注册

                    • 登录或注册以进行搜索。
                    • 第一个帖子
                      最后一个帖子
                    0
                    • 版块
                    • 标签
                    • 热门
                    • 用户
                    • 群组