【问题标题】:Show product default_code in purchase order line在采购订单行中显示产品 default_code
【发布时间】:2015-09-07 07:52:09
【问题描述】:

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

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

我该如何解决这个问题?

【问题讨论】:

  • 请格式化您的代码以使其可读
  • 有没有人怎么解决???

标签: openerp openerp-7 odoo-8


【解决方案1】:

似乎您还重新定义了purchase.order.line 模型的name_get() 方法。第二列名为“描述”,显示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()

【讨论】:

  • 这是没有内部 _name_get 方法的代码。请查看我的更新答案。
  • 很抱歉打扰您,但我已经尝试过此代码,但它不起作用您是否正在使用 odoo 8.0
  • 是的,我正在开发 Odoo 8。“它没有用”是什么意思?它给了你和你的代码一样的结果还是什么?
  • 当我尝试了这段代码后,我仍然在第一列和第二列得到产品代码
  • 这就是我从一开始就告诉你的 :) 你的问题不在这段代码中。请再次阅读我的答案并检查我是否正确 - 我想您还重新定义了 purchase.order.line 模型的 name_get() 方法,而不仅仅是 product.product 模型。
猜你喜欢
  • 2013-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多