我希望这个问题是有道理的。我的目标是显示name_get()中定义的字段。我在name_get类中重写了mrp_bom ()函数,并附加了代码。但是,我不知道哪个字段将从函数name_get()获得返回值。任何洞察力都是非常感谢的!
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发布于 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
希望这能帮到你。
https://stackoverflow.com/questions/28419629
复制相似问题