odoo通过actions.client进行自定义页面

本文介绍在Odoo中使用ir.actions.client开发自定义视图的过程,包括使用vehicle_police.xml定义自定义动作,通过web.js创建自定义Widget,以及在web.xml中使用iframe嵌套外部网页。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 一、使用原因

  由于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'],

 

转载于:https://www.cnblogs.com/xiaozhuxing/p/11023725.html

Odoo中,ir.actions.data是一个特殊的数据结构,用于存储各种类型的动态数据,比如模板、报表、菜单项等。如果你想通过ir.actions.data创建一个新的UI动作,如导航栏链接或菜单项,你可以按照以下步骤操作: 1. **新建ir.actions.server**模型记录**:** - 打开Odoo的开发者模式。 - 导航到"Settings" -> "Technical" -> "Developers" -> "Actions"。 - 点击"Create" -> "ir.actions.server"。 2. **填写字段**: - 在新打开的记录编辑界面,填写必要的字段: - `name`:给动作起一个描述性的名称,例如"my_new_menu_item"。 - `type`:通常选择`ir.actions.act_window`表示窗口动作,`ir.actions.client`表示前端操作。 - `res_model`:你要链接的模型名,比如"website"。 - `view_mode`:指定视图模式,如"form"。 - `target`:确定打开方式,如`new`或`current`。 3. **添加额外数据**: - 在`data`字段下,创建一个Python字典,包含其他需要的参数,如URL pattern (`url`),如果需要的话,还可以有`context`,`domain`等。例如: ```python { 'type': 'ir.actions.act_window', 'url': '/path/to/your/url?some=query&params', 'res_model': 'your_res_model_name', 'views': [(False, 'form')], 'target': 'new' } ``` 4. **保存并关联到菜单**: - 确保保存了这个服务器动作,然后在需要的地方(如菜单配置或模块的`menu.xml`文件)引用它。通过`ir.actions.xml_id`形式,例如: ```xml <record id="my_new_menu_id" model="ir.ui.menu"> <field name="name">My New Menu</field> <field name="action">my_new_menu_item</field> </record> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值