因爲odoo自帶頁面在項目開發過程當中沒法知足使用,須要使用到動做ir.actions.client進行自定義視圖的開發,實現自定義的xml視圖開發。javascript
一、項目目錄:這裏主要運用到三個文件:web.js、web.xml、vehicle_police.xml、base_views.xmlhtml
二、vehicle_police.xml文件中使用ir.actions.client動做視圖定義了一個自定義動做。java
<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"/>
三、web.jspython
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, }; });
四、web.xml,這裏使用一個iframe嵌套一個網頁。原本想使用html代碼,因爲沒有使用過,須要研究如何使用html自定義頁面。web
<?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>
五、base_views.xml文件,用與引入js加載進odoosession
<?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>
六、最後在__mainfest__.py中引入web.xml文件。app
'qweb': ['static/src/xml/web.xml'],