【分享-oe嵌入qweb】用js读取数据库数据,用类似html语言重写web报表
- 
分享的很完整,谢谢! 
- 
结合 上面几篇文章 掉坑了,然后 找老刘 要了 样例 bzr branch lp:~niv-openerp/+junk/oepetstore -r 1 
 然后从坑里 爬了出来
 安装 这个 教程 [检测到链接无效,已移除] br />
 看 楼主的 顺序 ,没理解前都会copy 看看 能不能运行。。 js ,xml 写了,然后掉坑里了
 1、出菜单 ,贴代码<?xml version="1.0" encoding="utf-8"?><br /><openerp><br />    <data><br />      <!-- Top menu item --><br />        <menuitem name="Test"<br />            id="menu_test_root"<br />        <br />            sequence="30"/><br />    <record model="ir.actions.client" id="action_client_example"><br />            <field name="name">Example Client Action</field><br />  <!-- 此处 name  修改了 浏览器 title    --><br />          <field name="tag">petstore.homepage</field><br />        <!-- 此处 tag 内容 要对应  js    <br />        instance.web.client_actions.add('petstore.homepage', 'instance.oepetstore.HomePage');<br /><br />这个 阿狸木有 解释,或者不解释 。<br /><br />济南-stone  提示 过 , “找action.tag是否写对”  结果不得要领<br />看了样例才知道<br />        --><br />            <br />        </record><br /> <!-- 此处 tag 内容 要对应  js    这个 阿狸木有 解释,或者不解释 。<br />  --><br />        <menuitem id="test_qweb_menu" name="test qweb" sequence="20" parent="menu_test_root"/><br />        <menuitem action="action_client_example" id="menu_client_example" parent="test_qweb_menu" name="test report qweb"/><br />    </data><br /></openerp>
 2 、js 代码<br />openerp.oepetstore = function(instance) {<br />    var _t = instance.web._t,<br />        _lt = instance.web._lt;<br />    var QWeb = instance.web.qweb;<br /><br />    instance.oepetstore = {};<br /><br /> /*  instance.oepetstore.HomePage = instance.web.Widget.extend({<br />        start: function() {<br />            console.log("pet store home page loaded");<br />        },<br />    });<br />    */<br />    instance.oepetstore.HomePage = instance.web.Widget.extend({<br />        start: function() {<br />            var self = this;<br />            var model = new instance.web.Model("message_of_the_day");<br />//message_of_the_day  是py 定义了一个 类  <br />//下面的 my_method  在py 类message_of_the_day    里有定义<br />            model.call("my_method", [], {context: new instance.web.CompoundContext()}).then(function(result) {<br />                self.$el.append("<div>Hello " + result["hello"] + "</div>");<br />                // will show "Hello world" to the user<br />            });<br />        },<br />    });<br />// instance.oepetstore.btn_start  是 copy 梦菇的 代码 ,木有 调用<br />    instance.oepetstore.btn_start = function() {<br />        var self = this;<br />        alert('test');<br />        return false;<br />    };<br />    <br />  <br />    function aaa(){<br />        alert(123);<br />    }<br />    // 这里 定义了 ,然后  xml 里 才能调用      <field name="tag">petstore.homepage</field><br />    instance.web.client_actions.add('petstore.homepage', 'instance.oepetstore.HomePage');<br />    <br />    instance.web.client_actions.add('bt_start', 'instance.oepetstore.btn_start');<br /><br /><br />}<br />
 3、贴下 py 代码<br />from openerp.osv import osv, fields<br /># 通过 js  <br /># var model = new instance.web.Model("message_of_the_day");<br /># 调用 该类 <br />class message_of_the_day(osv.osv):<br />    _name = "message_of_the_day"<br /><br />#通过  js <br />#  model.call("my_method", [], {context: new instance.web.CompoundContext()}).then(function(result) {<br />#                self.$el.append("<div>Hello " + result["hello"] + "</div>");<br /># 调用  下面 方法  通过 model.call ("my_method", ....<br />    def my_method(self, cr, uid, context=None):<br />        return {"hello": "world"}<br /><br />    _columns = {<br />        'message': fields.text(string="Message"),<br />        'color': fields.char(string="Color", size=20),<br />    }<br />
 这样 界面可以出 hello world
- 
[quote author=行云流水 link=topic=16554.msg28741#msg28741 date=1408090429] 
 结合 上面几篇文章 掉坑了,然后 找老刘 要了 样例 bzr branch lp:~niv-openerp/+junk/oepetstore -r 1
 然后从坑里 爬了出来
 安装 这个 教程 [检测到链接无效,已移除] br />
 看 楼主的 顺序 ,没理解前都会copy 看看 能不能运行。。 js ,xml 写了,然后掉坑里了
 1、出菜单 ,贴代码<?xml version="1.0" encoding="utf-8"?><br /><openerp><br />    <data><br />      <!-- Top menu item --><br />        <menuitem name="Test"<br />            id="menu_test_root"<br />        <br />            sequence="30"/><br />    <record model="ir.actions.client" id="action_client_example"><br />            <field name="name">Example Client Action</field><br />  <!-- 此处 name  修改了 浏览器 title    --><br />          <field name="tag">petstore.homepage</field><br />        <!-- 此处 tag 内容 要对应  js    <br />        instance.web.client_actions.add('petstore.homepage', 'instance.oepetstore.HomePage');<br /><br />这个 阿狸木有 解释,或者不解释 。<br /><br />济南-stone  提示 过 , “找action.tag是否写对”  结果不得要领<br />看了样例才知道<br />        --><br />            <br />        </record><br /> <!-- 此处 tag 内容 要对应  js    这个 阿狸木有 解释,或者不解释 。<br />  --><br />        <menuitem id="test_qweb_menu" name="test qweb" sequence="20" parent="menu_test_root"/><br />        <menuitem action="action_client_example" id="menu_client_example" parent="test_qweb_menu" name="test report qweb"/><br />    </data><br /></openerp>
 这样 界面可以出 hello world
 [/quote]
 我上面说了, 注意qweb的name字段等与js中的关联,就不一一说了,仔细看就看出来了。
 。。。
 PS: 你这坑掉的可真深啊 ;D
