问题
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