Odoo 动作Action

Odoo 动作Action

动作Action

# 字段:
	type 操作的类型
	
	name 动作简短的名称
	
	binding_model_id 给动作绑定模型
	
	binding_type 指定绑定类型 , 动作即将出现在哪个上下文种
		# action 指定动作将出现在 绑定模型的“动作”上下文菜单中。
		# report  指定操作将出现在 绑定模型的“ 打印”上下文菜单中
		
	binding_view_types 以逗号分隔的视图类型列表,针对该视图类型的操作将在上下文中显示. 默认是'list,form'(列表和表格)
	

一.窗口动作

# ir.actions..act_window

# 字段
	res_model 绑定模型
	
	views( view_id,view_type) (可选的数据库ID,视图的类别(树,窗体,图形等)
		# 如果没有提供ID ,则客户端对应请求的模型获取指定类型的默认视图是由
		 fields_view_get() 方法获得. 
		# 列表 tree 是默认的视图类型
		
	res_id  可选参数,默认是视图form
	search_view_id 可选参数  则指定要加载的记录(否则应创建一个新记录)
	target 可选参数  , current 主区域, fullscreen 全屏 , new 新视图, main 代替current 清除面包屑导航
	context 可选参数 上下文数据传递给视图
	domain 可选参数  过滤域 以隐式添加到搜索视图种
	limit 可选参数 web客户端 默认是80
# 事例代码
{
    "type": "ir.actions.act_window",
    "res_model": "res.partner",
    "views": [[False, "tree"], [False, "form"]],
    "domain": [["customer", "=", true]],
}

# 打开新的对话窗口 
{
    "type": "ir.actions.act_window",
    "res_model": "product.product",
    "views": [[False, "form"]],
    "res_id": a_product_id,
    "target": "new",
}

# view_mode (default= tree,form )
	# 注意:如果使用 view_ids时,请使用 ir.actions.act_window.view
<record model="ir.actions.act_window.view" id="test_action_tree">
   <field name="sequence" eval="1"/>
   <field name="view_mode">tree</field>
   <field name="view_id" ref="view_test_tree"/>
   <field name="act_window_id" ref="test_action"/>
</record>	

# view_id 
	绑定即将要展示的视图id
<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>

二.URL操作

# 允许odoo操作打开URL
# ir.actions.act_url
# 字段:
	url 激活动作时打开的地址
	target new 是新窗口, self是当前页面

{
    "type": "ir.actions.act_url",
    "url": "https://odoo.com",
    "target": "self",
}

三.服务动作

#  ir.actions.server
# 服务器动作模型.  服务器动作基于基本模型,提供各种类型的动作. 这些动作可自动执行.

# 服务器动作可执行的动作
	# 1. 执行python代码
	# 2. 创建新的记录
	# 3. 更新记录的值
	# 4. 执行多个操作
	# 5. 允许从任何有效的操作位置触发复杂的服务器代码,至于两个字段相关
		# id 运行服务器动作的数据库内标识符
		# context 可选参数,运行服务器操作时,使用的上下文数据
		# model_id Odoo模型链接到的动作
		# state 
			# code 执行code参数指定的python代码
			# object_create :crud_model_id 根据fields_lines 规格创建新的模型记录
			# object_write : 按照一下fields_lines 规范更新当前记录
			# multi : 执行通过child_ids 参数给出的服务器操作


# State  状态栏 (5种模式)
	# code  
        ### 指定调用该动作时要执行的一段Python代码
        <record model="ir.actions.server" id="print_instance">
            <field name="name">Res Partner Server Action</field>
            <field name="model_id" ref="model_res_partner"/>
            <field name="state">code</field>
            <field name="code">
                raise Warning(record.name)
            </field>
        </record>
        
        ### 该代码段可以定义一个名为的变量action,该变量将作为下一个要执行的操作返回给客户端:
        <record model="ir.actions.server" id="print_instance">
            <field name="name">Res Partner Server Action</field>
            <field name="model_id" ref="model_res_partner"/>
            <field name="state">code</field>
            <field name="code">
                if record.some_condition():
                    action = {
                        "type": "ir.actions.act_window",
                        "view_mode": "form",
                        "res_model": record._name,
                        "res_id": record.id,
                    }
            </field>
        </record>


	# crud_model_id 
		创建新记录的模型 必填
		
	# link_field_id
		创造
		many2one ir.model.fields  , 指定应在其上设置新创建记录的m2o字段
	# fields_lines 
		创建/写入 , 创建或复制记录字段时覆盖的字段. one2many字段
		# cool  ir.model.fields在相关模型中设置(crud_model_id用于创建,model_id用于更新)
		# value 字段的值,通过 type
		# type type (值|参考|等式)
如果为value,则将该value字段解释为文字值(可能会转换),如果equation将该value字段解释为Python表达式并求值
	
	# child_ids
    指定ir.actions.server要在状态multi中执行的多个子操作()。如果子操作本身返回操作,则最后一个操作将作为多重操作自身的下一个操作返回给客户端

四.报告动作

# 触发报告的打印
# ir.actions.report
	
# 字段 
	name  必填参数 
	model 必填参数  报告使用到的模型
	report_type  默认是qweb-pdf , qweb-html
	report_name 必填 报告名称
	
    groups_id  Many2many 字段允许查看/使用当前报告的组
    multi  设置为True,则将不会显示在表单视图上
    paperformat_id  Many2one 纸张格式的字段
    attachment_use  设置True时,第一次请求时才生成报告,从存储的报告中重新打印,不是每次都生成新的报告
    attachment 定义报告的名称
<!-- used from POS UI, no need to be in print menu -->
<record id="pos_invoice_report" model="ir.actions.report">
        <field name="name">Invoice</field>
        <field name="model">pos.order</field>
        <field name="report_type">qweb-pdf</field>
        <field name="report_name">point_of_sale.report_invoice</field>
        <field name="print_report_name">'Invoice - %s' % (object.name)</field>
</record>

五.客户动作

# ir.actions.client
# 在客户端种触发的操作

# 字段 
	tag 操作客户端的标识符,客户端知道之后做出反应的字符串
	params 可选字段, Python字典,包含要发送到客户端的其他数据以及客户端操作标签
	target 可选参数 current 主要内容区域, fullscreen 全屏, new 弹窗,对话框,   main 代替current 清楚面包屑. 默认是current
	
{
    "type": "ir.actions.client",
    "tag": "pos.ui"
}

六.自动动作

# ir.cron 
# 以预定频率自动触发的动作

# 字段
	name  自动操作的名称
	interval_number 两次执行动作之间的 interval_type uom (次数)
	numbercall  必须执行此操作的次数,如果希望无限运行,设置为-1
	doall 布尔值, 在服务器重新启动时,是否必须执行错过的操作
	model_id  调用此动作的模型
	code 动作的代码内容 , 如:
		model.<method_name>()
	nextcall 该操作的下一个计划执行日期
posted @ 2021-03-26 14:36  染指未来  阅读(991)  评论(0编辑  收藏  举报