首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenERP -哪个字段从重写的name_get()函数中获取值?

问OpenERP -哪个字段从重写的name_get()函数中获取值?
EN

Stack Overflow用户
提问于 2015-02-09 21:22:15
回答 1查看 1.7K关注 0票数 1

我希望这个问题是有道理的。我的目标是显示name_get()中定义的字段。我在name_get类中重写了mrp_bom ()函数,并附加了代码。但是,我不知道哪个字段将从函数name_get()获得返回值。任何洞察力都是非常感谢的!

代码语言:javascript
复制
class mrp_bom(osv.osv):
    _inherit = 'mrp.bom'
    _name = 'mrp.bom'
    _columns = {
        'x_nk_default_code': fields.related('product_id', 'default_code', 
            type='char', relation='product.product', 
            string='Part Number', store=True, 
            readonly=True),
        'x_nk_class_desc': fields.related('product_id', 'categ_id', 'name', 
            type='char', string='Class Description', 
            store=True, readonly=True),
        'x_nk_item_desc': fields.related('product_tmpl_id', 'name', 
            type='char', relation='product.template', 
            string='Item Description', store=True, 
            readonly=True),
        'categ_id': fields.related('product_id', 'categ_id', type='integer', 
            relation='product.product', string='Categ_ID', 
            store=True, readonly=True),
        'x_category_code': fields.related('product_id', 'categ_id', 
            'x_category_code', type='char', string='Class 
            Description', store=True, readonly=True),
    }


    def name_get(self, cr, user, ids, context=None):
        if context is None:
            context = {}
        if isinstance(ids, (int, long)):
            ids = [ids]
        if not len(ids):
            return []
        def _name_get(d):
            name = d.get('name','')
            code = context.get('display_default_code', True) and 
                d.get('x_category_code',False) or False
            if code:
                name = '[%s] %s' % (code,name)
            return (d['id'], name)
        result = []
        for product_category in self.browse(cr, user, ids, context=context):
            mydict = {
                'id': product_category.id,
                'name': product_category.name,
                'x_category_code': 
                product_category.x_category_code,
            }
        result.append(_name_get(mydict))
    return result
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-10 08:13:08

name_get方法用于在many2one字段中显示记录的值。例如,在销售订单行中,如果选择产品,字段“product_id”的销售订单行中显示的值必须是product.product对象上“name_get”的结果。

没有特殊的字段来显示name_get的结果。如果需要将name_get方法的结果放在记录的字段中,则应该使用属性“计算”:http://odoo-new-api-guide-line.readthedocs.org/en/latest/fields.html#computed-fields创建

您可以在这里找到更多信息: more get

希望这能帮到你。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28419629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档