欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > odoo17 tree视图添加按钮

odoo17 tree视图添加按钮

2024/10/24 16:26:49 来源:https://blog.csdn.net/weixin_42464956/article/details/139953788  浏览:    关键词:odoo17 tree视图添加按钮

需求描述

点击下图中tree视图上的同步退货单按钮,弹出相应的form视图进行退货单同步,然后点击同步按钮调用后端python代码处理。

在这里插入图片描述

实现步骤

主要文件目录结构

在这里插入图片描述

js文件的创建
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { listView } from "@web/views/list/list_view";
import { ListController } from "@web/views/list/list_controller";
import { useService } from "@web/core/utils/hooks";
export class OwlDemoTest extends ListController {setup() {super.setup();this.orm = useService("orm");}message_button() {this.orm.call('temporary.receipt', 'update_message', []).then(function(result) {self.model.root.notifyChanges();}).catch(function(error) {console.error("Error calling update_message:", error);});
}registry.category("views").add("owl_demo_test", {...listView,Controller: OwlDemoTest,buttonTemplate: "OwlDemoButtons",
});
}

define方法的第一个参数为名称,自行定义,require方法表示所用到的依赖,然后对按钮的点击事件绑定相应的方法,这个方法返回一个动作视图(就是所定义的瞬态模型的向导)

创建按钮模板

也就是定义在/static/xml 文件夹下面的xml文件,用来定义所加的按钮

<?xml version="1.0" encoding="utf-8"?>
<templates id="template" xml:space="preserve"><t t-name="OwlDemoButtons" t-inherit="web.ListView.Buttons" t-inherit-mode="primary" owl="1"><xpath expr="(//div/*)[last()]" position="after"><button class="btn btn-primary" type="button" t-on-click="message_button">测试按钮</button></xpath>
</t></templates>
xml、js文件引入到__manifest__.py
    "assets": {"web.assets_backend":["erp_app/static/src/js/test.js","erp_app/static/src/xml/test.xml",]}
对应模型添加方法
    @api.modeldef update_message(self):print('执行的代码')
tree视图添加 js_class
<tree js_class="owl_demo_test">...
</tree>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com