2017-07-13 23 views
3

我們正在獲取登錄用戶self.env.user,但我想訪問登錄用戶ir.action.act.window我們如何才能在odoo v10的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字段(自定義字段),我想在操作調用時過濾數據。

是否有任何替代解決方案可用於過濾消息而不創建記錄規則,或者有什麼辦法可以從我們可以訪問登錄用戶的ir.action.act.window

+0

* search_read()*方法怎麼樣?我們也可以從那裏過濾記錄。 –

+0

您是否嘗試過在域中使用'('user.company_id','=',user.company_id.id)'?我不確定域評估是否允許使用'用戶'。 – CZoellner

回答

1

,如果你只需要用戶的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)] 
     } 
+0

謝謝我會盡力回覆你.. –

+0

應該在CRM模塊中有一個示例:在odoo 10.0中檢查動作ID:'action_your_pipeline' – Cherif

+0

這是服務器動作,但我想在ir.action.act.window .. –

0

我處於類似的情況,我需要添加域以僅顯示樹中與登錄用戶相關的結果。這對我來說很有用。

XML

<field name="domain">[('cmp_id','=',uid)]</field> 

的Python:

cmp_id = fields.Many2one('module.company', related='user_id.company_id') 

這裏模塊是你爲公司做出的自定義模塊,CMP_ID是Many2one場是相關通過user_id發送給公司ID。

相關問題