How to get two _rec_names in odoo for two many2one fields in single class?

眉间皱痕 提交于 2019-12-30 14:52:11

问题


I have following code I want this two fields asset_catg_id and folio_num. These should be available for many2one two fields. How to write 2 _rec_name for a single class?

class asset_asset(osv.osv):
    _inherit = "asset.asset"
    #_name = "asset_asset"
    _rec_name= "folio_num"
    #_rec_name = "assetmodelid_add"
    _columns = {
        'name': fields.char('Asset Name', size=64),
        'company_id1': fields.many2one('res.company', 'Substation', required=True),
        #'place1': fields.many2one('asset.parentlocation', 'Location'),
        'asset_catg_id' : fields.many2one('asset.catg', 'Asset Catg Selection',select=True, required=True),
            'area_id' : fields.many2one('asset.name', 'Asset Name Selection', domain="[('asset_catg_id', '=', asset_catg_id)]", select=True, required=True),
        'assetmodelid_add' : fields.many2one('agile.portfolio1','Asset Model Code',domain="[('area_id', '=', area_id)]",),
        'folio_num' : fields.char('Folio No',),
        'asse_line':fields.one2many('asset.line','emp_id','Name Plate'),
        'asse_line2':fields.one2many('asset.part','emp_id1','Parts'),
               #'assed_modelid':fields.many2one('agile.portfolio1','Asset Model ID',select=True, required=True),
        'quantity': fields.char('Quantity',size=64),
        'uom': fields.char('Uinit of Measure',size=64),
        'model_no' : fields.char('Model', size=64),

        #'asset_id':fields.many2one('agile.portfolio','Asset ID'),

    }

回答1:


What do you have to do to manage that is to overwrite the method _name_get of the model asset.asset.

@api.multi
def name_get(self):
    res = []
    for asset in self:
        display_name = []
        res.append((asset.id,
                    asset.folionum + ' ' + asset.assetmodelid_add.name))
    return res


来源:https://stackoverflow.com/questions/33564792/how-to-get-two-rec-names-in-odoo-for-two-many2one-fields-in-single-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!