2015-09-07 118 views
1

當創建我想刪除product_nameproduct_id一個新的採購訂單所以,我沒有這樣的功能:顯示產品default_code

class snc_product(osv.osv): 
    _name='product.product' 
    _inherit='product.product' 

    def name_get(self, cr, uid, ids, context=None): 
     return_val = super(snc_product, self).name_get(cr, uid, ids, context=context) 
     res = [] 
     def _name_get(d): 
      code = d.get('code','') 
      if d.get('variants'): 
       code = code + ' - %s' % (d['variants'],) 
      return (d['id'], code) 
     for product in self.browse(cr, uid, ids, context=context): 
      res.append((product.id, (product.code))) 
     return res or return_val 

現在的問題是,即使在描述我獲取default_code而不是名稱。

http://imgur.com/afLNQMS

我該如何解決這個問題?

+1

請格式化你的代碼,使其在某種程度上readble –

+0

有誰如何解決呢??? –

回答

1

好像你重新定義了purchase.order.line模型的name_get()方法。名爲'描述'的第二列顯示模型的name字段。這就是爲什麼我想你重新定義了它。

您的解決方案正在爲我工​​作 - 第一列中有產品代碼,第二列中有產品代碼。只有一件事 - 你不需要這種內部方法,因爲你不使用它。

這裏是爲我工作的代碼:

from openerp.osv import osv, fields 


    class snc_product(osv.osv): 
     _name = 'product.product' 
     _inherit = 'product.product' 

     def name_get(self, cr, uid, ids, context=None): 
      return_val = super(snc_product, self).name_get(cr, uid, ids, 
                  context=context) 
      res = [] 
      for product in self.browse(cr, uid, ids, context=context): 
       res.append((product.id, (product.code))) 
      return res or return_val 

    snc_product() 
+0

你能告訴我你使用它的代碼嗎? –

+0

這是您的代碼沒有內部_name_get方法。請看我更新的答案。 –

+0

對不起,但我已經試過這段代碼,它沒有工作,你是否正在使用odoo 8.0 –