gpt4 book ai didi

odoo-8 - 我们如何在 odoo v10 的 ir.action.act.window 中获取登录用户?

转载 作者:行者123 更新时间:2023-12-01 04:47:56 26 4
gpt4 key购买 nike

我们正在获取登录用户 self.env.user ,但我想访问 中的登录用户ir.action.act.window .

    <record id="act_mail_messages_form_ept_closed" model="ir.actions.act_window">
<field name="name">Closed</field>
<field name="res_model">mail.message</field>
<field name="domain">[('model','=','res.partner'),('res_id','!=',False),('user.company_id','=',company_id)]</field>
<field name="context">{'readonly_by_pass': True,'check_domain':True}</field>
<field name="view_type">form</field>
<field name="search_view_id" ref="view_message_search"/>
<field name="view_mode">tree,form</field>
</record>

我的要求是我想在不创建记录规则的情况下过滤数据,因为如果我们创建 mail.message 的记录规则,那么系统会非常慢,因为对于每个记录系统都会检查记录规则。

我想使用mail.message中的域过滤公司明智的消息。

在 mail.message 我有 company_id 字段(自定义字段),我想在调用 action 时过滤数据。

是否有任何替代解决方案可用于在不创建记录规则的情况下过滤消息,或者有什么方法可以让我们访问 中的登录用户? ir.action.act.window ?

最佳答案

如果您只需要域的用户 ID:使用 uid
如果您想过滤具有复杂域且无法通过操作执行的记录,则应使用 ir.actions.server :

XML:

<record id="action_mail_closed" model="ir.actions.server">
<field name="name">Closed</field>
<!-- here the name of the module containing mail_message model-->
<field name="model_id" ref="module_name.mail_message"/>
<field name="state">code</field>
<field name="code">action = model.open_closed()</field>
<field eval="True" name="condition"/>
</record>

Python:

@api.model
def open_closed(self):
# here you can filter you records as you want
records = self.env... search(...)
search_view_id = self.env.ref('module_name.view_message_search')
return {
'name': _('Closed'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'mail.message',
'search_view_id': search_view_id.id,
'target': 'current',
'context': {'readonly_by_pass': True,'check_domain':True},
# and here show only your records make sure it's not empty
'domain' : [('id', 'in', records.ids)]
}

关于odoo-8 - 我们如何在 odoo v10 的 ir.action.act.window 中获取登录用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45079803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com