一、使用原因
由於odoo自帶頁面在項目開發過程中無法滿足使用,需要使用到動作ir.actions.client進行自定義視圖的開發,實現自定義的xml視圖開發。
二、實現目標
三、開發過程
1、項目目錄:這里主要運用到三個文件:web.js、web.xml、vehicle_police.xml、base_views.xml
2、vehicle_police.xml文件中使用ir.actions.client動作視圖定義了一個自定義動作。
<record id="vehicle_police_action_client" model="ir.actions.client"> <field name="name">自定義頁面</field> <field name="tag">web.main</field> </record> <menuitem id="menuitem_vehicle_police_client" name="自定義頁面" sequence="1" parent="menu_vehicle_monitoring" action="vehicle_police_action_client"/>
3、web.js
odoo.define('web', function (require) { "use strict"; var core = require('web.core'); var Widget = require('web.Widget'); var Model = require('web.Model'); var session = require('web.session'); var PlannerCommon = require('web.planner.common'); var framework = require('web.framework'); var webclient = require('web.web_client'); var PlannerDialog = PlannerCommon.PlannerDialog; var QWeb = core.qweb; var _t = core._t; var Dashboard = Widget.extend({ template: 'web', init: function(parent, data){ return this._super.apply(this, arguments); }, start: function(){ return true; }, }); core.action_registry.add('web.main', Dashboard); return { Dashboard: Dashboard, }; });
4、web.xml,這里使用一個iframe嵌套一個網頁。本來想使用html代碼,由於沒有使用過,需要研究如何使用html自定義頁面。
<?xml version="1.0" encoding="UTF-8"?> <templates xml:space="preserve"> <t t-name="web"> <iframe marginheight="0" marginwidth="0" width="100%" height="910" src="https://www.baidu.com" frameborder="0" allowfullscreen="True"></iframe> </t> </templates>
5、base_views.xml文件,用與引入js加載進odoo
<?xml version="1.0" encoding="utf-8"?> <odoo> <template id="assets_backend" inherit_id="web.assets_backend"> <script type="text/javascript" src="/urban/static/src/js/web.js"/> </xpath> </template> </odoo>
6、最后在__mainfest__.py中引入web.xml文件。
'qweb': ['static/src/xml/web.xml'],