2017-08-02 55 views
1

爲了顯示這個窗體視圖:顯示Res_partner形成對應於當前用戶的合作伙伴信息

<record model="ir.ui.view" id="program_viewform"> 
      <field name="name">My Program</field> 
      <field name="model">res.partner</field> 
      <field name="arch" type="xml"> 
       <form> 
        <separator string="My Program " /> 
       <field name="projects_ids" nolabel="True"/> 
        <separator string="submitted Tasks" /> 
        <field name="submission_task_ids" nolabel="True"/> 
       </form> 
      </field> 
     </record> 

我創造了這個動作:

<record model="ir.actions.act_window" id="myprogram_action"> 
     <field name="name">My Program</field> 
     <field name="res_model">res.partner</field> 
      <field name="form_view_id" ref="training_program_management.program_viewform"/> 
      <field name="domain">[('id','=',user.id.partner_id)]</field> 
      <field name="view_mode">form</field> 
     </record> 

和菜單:

我需要的是顯示res_partner對應於當前用戶的記錄,知道res.users包含Many2one字段「Partner_id」。 我需要做什麼?

回答

2

這是測試odoo 8,但大概可以適用於odoo 10或至少幫助你:

變化<record model="ir.actions.act_window" id="myprogram_action"><record model="ir.actions.server" id="myprogram_action">

然後加入(是的,舊的API是有目的的,它不「t用新的API合作,爲odoo 8即是)

<field name='model_id' ref='base.model_res_partner'/> 
<field name="code"> 
    action = self._action_open_user_res_partner(cr, uid) 
</field> 

創建模塊擴展res.partner模型,添加(更舊的API ......我也沒有找到一種方法,使用ref()

@api.model 
def _action_open_user_res_partner(self, cr, uid): 
    return { 
     'view_type': 'form', 
     'view_mode': 'form', 
     # Since this is a constant, you can use a global to hold the value for 'view_id' 
     'view_id': int(self.pool['ir.ui.view'].search(cr, uid, 
                [('name', '=', 'My Program')])[0]), 
     'res_model': 'res.partner', 
     'res_id': int(self.pool['res.users'].browse(cr, uid, [uid])[0].partner_id), 
     'type': 'ir.actions.act_window', 
     'context': {} 
    } 

將它適配到odoo 10可能涉及到使用新的API而不是舊的API。這意味着self.pool應該是self.envenv,並且您不再需要cruid了。你可以在返回的函數中使用user變量而不是uid(實際上它也可以用於odoo 8,不過由於uid是需要的)。

另一方面,the documentation for odoo 10 about actions強烈建議您仍然需要使用舊API,除了model替代self

所以,你應該首先嚐試這樣的odoo 10:

<field name='model_id' ref='base.model_res_partner'/> 
<field name="code"> 
    action = model._action_open_user_res_partner(cr, uid) 
</field> 

該模型中的功能仍然是相同的,因爲我們仍然使用舊的API。

如果它不工作,你應該使用新的API(擺脫鉻,UID)

0

代碼波紋管,完全爲我工作的嘗試,謝謝你很多的幫助:

<record model="ir.actions.server" id="myprogram_action"> 
     <field name="name">My Program</field> 
      <field name='model_id' ref='base.model_res_partner'/> 
      <field name="state">code</field> 
      <field name="code"> 
       action = { 
        'type': 'ir.actions.act_window', 
        'name': 'My Program', 
        'view_mode': 'form', 
        'view_type': 'form', 
        'res_model': 'res.partner', 
        'nodestroy': 'true', 
        'res_id': int(env['res.users'].browse(env.user.partner_id.id)), 
        'views': [(False, 'form')], 
        'view_id': 'ref="training_program_management.program_viewform"', 
       } 
      </field> 
     </record> 

還有一個小問題你,我有兩個FormViews爲res.partner,此行似乎並沒有顯示出需要的視圖:

'view_id': 'ref="training_program_management.program_viewform"', 

它爲我首先FormView控件,我已經繼承。 我training_program_management.program_viewform:

<record model="ir.ui.view" id="program_viewform"> 
      <field name="name">My Program</field> 
      <field name="model">res.partner</field> 
      <field name="arch" type="xml"> 
       <form> 
        <separator string="My Program " /> 
       <field name="projects_ids" nolabel="True"/> 
        <separator string="submitted Tasks" /> 
        <field name="submission_task_ids" nolabel="True"/> 



       </form> 
      </field> 
     </record> 

我能做些什麼來顯示這個視圖取而代之的是繼承一個嗎?