2016-09-22 18 views
0

我已經寫了一些Python代碼在我的.py文件中顯示的嚮導選擇所有記錄ID從Odoo聯繫人列表視圖的

class DisplayWindow(models.Model): 
_inherit = 'res.partner' 
wizard_id = fields.Many2one('sale.example_wizard') 

def result_to_search(self, cr, uid, active_ids): 
    wizard = self.pool['sale.example_wizard'].create(cr, uid, vals={ 
     'partner_ids': [(6, 0, active_ids)] 
    }) 
    return { 
     'name': _('Account Search'), 
     'type': 'ir.actions.act_window', 
     'res_model': 'sale.example_wizard', 
     'res_id': wizard, 
     'view_type': 'form', 
     'view_mode': 'form', 
     'target': 'new', 
    } 

,這裏是我的.xml文件

<openerp> 
    <data> 
     <!--This xml file is responsible for the server action of displaying the wizard--> 
     <record model="ir.actions.server" id="action_search_for_result"> 
      <field name="name">Account Search</field> 
      <field name="model_id" ref="sale.model_res_partner"/> 
      <field name="code"> 
       if context.get('active_model') == 'res.partner' and context.get('active_ids'): 
        action = self.pool['res.partner'].result_to_search(cr, uid, context.get('active_ids')) 
      </field> 
     </record> 
     <record model="ir.values" id="search_result"> 
      <field name="model_id" ref="sale.model_res_partner"/> 
      <field name="name">Account Search</field> 
      <field name="key2">client_action_multi</field> 
      <!--automatically attach action to the dropdown button--> 
      <field name="value" eval="'ir.actions.server,' +str(ref('action_search_for_result'))"/> 
      <field name="key">action</field> 
      <field name="model">res.partner</field> 
     </record> 
    </data> 
</openerp> 

我的問題是當我從顧客的列表視圖中選擇所有客戶時,只選擇第一頁聯繫人以及我爲嚮導的按鈕編寫的任何代碼,但它僅適用於第一頁的客戶。但是,我期望的結果假定適用於我擁有的所有客戶數據庫。 也許我做錯了什麼用這段代碼

wizard = self.pool['sale.example_wizard'].create(cr, uid, vals={ 
      'partner_ids': [(6, 0, active_ids)] 
     }) 

請幫助我。如果需要,我可以解釋更多。謝謝

回答

1

您可以通過使用下面的代碼得到選定的記錄。

wizard = self.pool['sale.example_wizard'].create(cr, uid, vals={ 
     'partner_ids': [(6, 0, self._context.get('active_ids',[]))] 
    }) 

由於

+0

'ValueError異常: 「 'res.partner' 對象沒有屬性 'ENV'」 而評估 U「如果context.get( 'active_model')== 'res.partner' 和distance.to_search(cr,uid,context.get('active_ids'))「'從xml.Any中獲取這個錯誤。理念? – Paramita

+0

是的,您已經使用過舊的語法。 –

+0

在xml的代碼字段中使用此代碼:if context.get('active_model')=='res.partner'和context.get('active_ids'): action = self.pool.get('res.partner' ).result_to_search(cr,uid,context.get('active_ids')) –

相關問題