Надеюсь, этот вопрос имеет смысл. Моя цель - отобразить поле, как определено в name_get(). У меня есть переопределенная функция name_get() в классе mrp_bom, код прилагается. Однако я не знаю, какое поле получит возвращаемое значение из функции name_get(). Любое понимание очень ценится!OpenERP - какое поле получает значение из переопределенной функции 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
Спасибо, Квентин, за ваш ответ. Я намерен отобразить отформатированный результат «[class_id] class_description» из name_get(), как вы можете видеть из моей функции name_get(). Конкретно, как я могу отобразить этот результат в многопользовательском поле, как я знаю, какое поле его поднимет? Если вы можете предоставить код для этого, мы будем очень благодарны. – Nash
Чтобы отобразить имя_мазы() mrp.bom, вам необходимо создать новый объект с полем many2one, указывающим на запись mrp.bom. Вы можете найти пример в объекте production.order. –
Спасибо, Квентин. – Nash