Odoo 页面-‘action’-官方文档解释
1、图示总概览-动作分类
窗口动作(Window Actions) ------(ir.actions.act_window)
网址URL动作(URL Actions) ------(ir.actions.act_url)
服务器动作(Server Actions)------ (ir.actions.server)
报告动作(Report Actions)------ (ir.actions.report.xml)
客户动作(Client Actions)------ (ir.actions.client)
2、官方文档
动作可以存储在数据库中,也可以直接作为字典返回,例如按钮方法。所有操作都有两个强制性属性:
type
当前动作的类别,确定可以使用哪些字段以及如何解释动作
name
操作的简短用户可读描述,可以显示在客户端的界面中
客户端可以通过 4 种形式获取操作:
False
如果当前打开了任何操作对话框,请将其关闭
一个字符串
如果客户端操作匹配,则解释为客户端操作的标记,否则视为数字
一个号码
从数据库中读取对应的动作记录,可以是数据库标识符,也可以是外部id
一本字典
视为客户端操作描述符并执行
窗口动作Window Actions (ir.actions.act_window)
最常见的动作类型,用于通过 视图呈现模型的可视化:窗口动作为模型(可能还有模型的特定记录)定义一组视图类型(可能还有特定视图)。
它的字段是:
res_model
模型来呈现视图
views
(view_id, view_type) 对的列表。每对的第二个元素是视图的类别(树、表单、图形…),第一个元素是可选的数据库 ID(或 False)。如果没有提供 id,客户端应该为请求的模型获取指定类型的默认视图(这由 fields_view_get()自动完成)。列表的第一种类型是默认视图类型,在执行操作时默认打开。每种视图类型在列表中最多应出现一次
res_id(可选的)
如果默认视图是form,则指定要加载的记录(否则应创建新记录)
search_view_id(可选的)
(id, name)pair,id是要为操作加载的特定搜索视图的数据库标识符。默认获取模型的默认搜索视图
target(可选的)
视图是否应在主要内容区域 ( current)、全屏模式 ( fullscreen) 或对话框/弹出窗口 ( new) 中打开。使用main而不是current清除breadcrumbs。默认为 current.
context(可选的)
要传递给视图的附加上下文数据
domain(可选的)
过滤域以隐式添加到所有视图搜索查询
limit(可选的)
默认情况下要在列表中显示的记录数。在 Web 客户端中默认为 80
auto_search(可选的)
是否应在加载默认视图后立即执行搜索。默认为True
例如,使用列表和表单视图打开客户(设置了客户标志的合作伙伴):
1 2 3 4 5 6 | { "type" : "ir.actions.act_window" , "res_model" : "res.partner" , "views" : [[ False , "tree" ], [ False , "form" ]], "domain" : [[ "customer" , "=" , true]], } |
或在新对话框中打开特定产品(单独获得)的表单视图:
1 2 3 4 5 6 7 | { “ type ” : “ir.actions.act_window” , “res_model” : “product.product” , “views” : [[ False , “form” ]], “res_id” : a_product_id , “target” : “new” , } |
数据库内窗口操作有几个不同的字段,客户端应该忽略这些字段,主要用于组成views列表:
view_mode
以逗号分隔的视图类型列表作为字符串。所有这些类型都将出现在生成的views列表中(至少有一个Falseview_id)
view_ids
M2 M1查看对象,定义views初始内容
view_id
添加到视图列表中的特定视图,以防其类型是 view_mode 列表的一部分并且尚未被 view_ids 中的视图之一填充
这些通常在从数据文件定义操作时使用:
1 2 3 4 5 6 | <record model = "ir.actions.act_window" id = "test_action" > <field name = "name" >A Test Action< / field> <field name = "res_model" >some.model< / field> <field name = "view_mode" >graph< / field> <field name = "view_id" ref = "my_specific_view" / > < / record> |
将使用“my_specific_view”视图,即使这不是模型的默认视图。
views序列的服务器端组成如下:
从 view_ids 中获取每个 (id, type) (按顺序sequence)
如果 view_id 已定义且其类型尚未填充,则附加其 (id, type)
对于 view_mode 中的每个未填充类型,追加 (False, type)
需求实例:
方法1:弹窗然后确认方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <record id = "wizard_batch_handle_record_so_form_view" model = "ir.ui.view" > <field name = "name" >Batch Handle Record Wizard For S.O. Form View< / field> <field name = "model" >wizard.batch.handle.so< / field> <field name = "type" >form< / field> <field name = "arch" type = "xml" > <form string = "Batch Handle Sale Order" > <div> <h4>Test one< / h4> <h5 style = "color:red" >Please make sure your approve flow is all auto approve and check your sale order correct< / h5> < / div> <footer> <button name = "**此处为想要执行的方法**" string = "Confirm" type = "object" class = "btn-primary" / > <button string = "Cancel" class = "btn-default" special = "cancel" / > < / footer> < / form> < / field> < / record> <act_window id = "act_wizard_batch_handle_so_record" name = "Batch Handle Sale Order" res_model = "wizard.batch.handle.so" = = = = = = = = = = = = >跳转的wizard瞬态模型 src_model = "sale.order" = = = = = = = = = = = = = >动作所在的模型 multi = "True" key2 = "client_action_multi" target = "new" view_type = "form" view_mode = "form" groups = "rh_sale.group_batch_handle_sale_order" / > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <record id = "view_badge_wizard_reward" model = "ir.ui.view" > <field name = "name" >gamification.badge.user.wizard.form< / field> <field name = "model" >gamification.badge.user.wizard< / field> <field name = "arch" type = "xml" > <form string = "Reward Employee with" > What are you thankful for ? <group> <field name = "employee_id" invisible = "1" / > <field name = "user_id" invisible = "1" / > <field name = "badge_id" nolabel = "1" colspan = "4" / > <field name = "comment" nolabel = "1" placeholder = "Describe what they did and why it matters (will be public)" / > < / group> <footer> <button string = "Reward Employee" type = "object" name = "action_grant_badge" class = "btn-primary" / > <button string = "Cancel" special = "cancel" class = "btn-default" / > < / footer> < / form> < / field> < / record> <act_window id = "action_reward_wizard" domain = "[]" name = "Reward Employee" target = "new" res_model = "gamification.badge.user.wizard" = = = = = = = = = = = = >跳转的wizard瞬态模型(需要在view里显示数据的model) context = "{'default_employee_id': active_id, 'employee_id': active_id}" view_type = "form" view_mode = "form" view_id = "view_badge_wizard_reward" / > = = = = = = > # 数据库视图记录id或False,如果没有指定id,客户端会自动用fields_view_get()获取相应类型的默认视图。(也有指定view_id的) |
方法2:直接执行方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <record id = "***ID***" model = "ir.actions.server" > <field name = "name" >Terminate Routine Inspection Tasks In Batches< / field> <field name = "type" >ir.actions.server< / field> <field name = "model_id" ref = "模块名称.model_模型名称" / > <field name = "state" >code< / field> <field name = "code" > if records: action = records.方法名() < / field> < / record> <record id = "action_terminate_routine_inspection_tasks_in_batches" model = "ir.values" > <field name = "name" >Terminate Routine Inspection Tasks In Batches< / field> <field name = "model_id" ref = "模块名称.model_模型名称" / > <field name = "model" >页面动作所属模型< / field> <field name = "key2" >client_action_multi< / field> <field eval = "'ir.actions.server,%d'%***ID***" name = "value" / > < / record> |
网址URL动作 URL Actions (ir.actions.act_url)
允许通过 Odoo 操作打开 URL(网站/网页)。可以通过两个字段进行自定义:
url
激活动作时打开的地址
target
在新窗口/页面中打开地址 if new,将当前内容替换为页面 if self。默认为new。如果是new的,则在新窗口/页面中打开地址,如果是 self,则用页面替换当前内容。默认为new
1 2 3 4 5 | { "type" : "ir.actions.act_url" , "url" : "http://odoo.com" , "target" : "self" , } |
将用 Odoo 主页替换当前内容部分。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
2018-10-02 linux操作文件和文件夹
2018-10-02 Selenium+Headless Firefox