2015-09-07 113 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 –