在采购订单行中显示产品default_code

时间:2015-09-07 07:52:10

标签: openerp openerp-7 odoo-8

创建新的采购订单时,我想删除product_name下的product_id,以便我执行此功能:

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 个答案:

答案 0 :(得分:1)

似乎您重新定义了name_get()模型的purchase.order.line方法。第二列名为“描述”,显示name字段或purchase.order.line模型。这就是我想你重新定义它的原因。

您的解决方案对我有用 - 我在第一列中有产品代码,在第二列中有说明。只有一件事 - 您不需要使用此内部_name_get()方法,因为您不使用它。

以下代码对我有用:

 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()
相关问题