正文
Odoo14 ir.actions.act_window
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
xml声明
1 <record id="res_company_user_action" model="ir.actions.act_window">
2 <field name="name">Users</field>
3 <field name="res_model">res.users</field>
4 <field name="view_mode">tree,form,kanban</field>
5 <field name="context">
6 {
7 'form_view_ref':'ship_manage.res_company_user_view_form',
8 'tree_view_ref':'ship_manage.res_company_user_view_tree',
9 'kanban_view_ref':'ship_manage.res_company_user_view_kanban',
10 'search_view_ref':'ship_manage.res_company_user_view_search'
11 }
12 </field>
13 </record>
ir.actions.server 调用action。这样你就可以根据当前用户去过滤信息;当然你也可以选择ir.rule过滤域去实现。
1 <record model="ir.actions.server" id="res_company_user_server_action">
2 <field name="name">Company User Server Action</field>
3 <field name="model_id" ref="base.model_res_users"/>
4 <field name="state">code</field>
5 <field name="code">
6 action = env.ref('ship_manage.res_company_user_action').read()[0]
7 action['domain'] = [('company_id','=',env.user.company_id.id)]
8 </field>
9 </record>
ir.actions.server 手动配置action参数
1 <record model="ir.actions.server" id="res_company_action1">
2 <field name="name">Company Server Action</field>
3 <field name="model_id" ref="base.model_res_company"/>
4 <field name="state">code</field>
5 <field name="code">
6 action = {
7 'name':'Company Test',
8 'type': 'ir.actions.act_window',
9 'res_model': 'res.company',
10 'view_mode': 'form',
11 'view_type': 'form',
12 'target': 'main',
13 'res_id': env.user.company_id.id,
14 'context': {'form_view_ref':'ship_manage.res_company_view_form_test'}
15 }
16 </field>
17 </record>
button事件调用action
xml:
<button name="get_company_action" string="Company Action" type="object"/> python:
def get_company_action(self):
action = self.env.ref('ship_manage.ship_manage_res_company_action').read()[0] #这里你也可以自己去定义
action['res_id'] = self.env.user.company_id.id
return action
或者自定义:
def get_company_action(self):
return {
'name': _('Repair Bill'),
'type': 'ir.actions.act_window',
'res_model': 'bill.head',
'view_mode': 'form',
'target': 'main',
'res_id': rb.id,
'context': {
'form_view_ref': 'ship.bill_head_view_form',
}
}
js 事件调用action。这里和唯一区别是views。list指的是tree视图,第一个参数false指的是按优先级获取默认的视图。你也可以指定一个视图id,你需要ref去获取ir.actions.act_window的记录id。
1 _onBtnClicked: function (ev) {
2 this.do_action({
3 type: 'ir.actions.act_window',
4 name: this.title,
5 res_model: this.modelName,
6 views: [[false, 'list'], [false, 'form']],
7 domain: ev.data.domain,
8 });
9 },
actions 源码相对路径:odoo/odoo/addons/base/models/ir_actions.py