Here is some information on Odoo – How to override ORM Method: name_get
In the HR module of Odoo ERP, when we open Employee form view, we can see there is only one field available in order to enter Employee Name. enter employee name over here, to use it across different modules. where a reference is made to it as a many2one field of hr.employee class. Generally name field of a class appears in many2one reference of that class in another classes. Entered name field in Employee Form displayes in many2one reference.
In one of our project we had to put three different fields namely first name, middle name and last name(first name was required field) and apart from that it was also required that the combination of provided inputs needs to be shown in many2one reference. So in this case,we had to override the existing name_get method in hr.employee class as follow.
def name_get(self,cr,uid,ids,context=None): res =  if not ids: return res if isinstance(ids, list): services = self.read(cr, uid, ids, ['name','middle_name','last_name'], context=context) for service in services: fn = service['name'] mn = service['middle_name'] ln = service['last_name'] if fn and not mn and not ln: cid = fn elif fn and mn and ln: cid = fn+" "+mn+" "+ln elif fn and mn and not ln: cid = fn+" "+mn elif fn and ln and not mn: cid = fn+" "+ln else: cid = "" res.append((service['id'], cid)) return res else: return res or ids
|Here is another module where it shows separate fields for First Name, Middle Name and Last Name.||Here it shows the combined fields|
Odoo ERP is the best ERP software for manufacturing and therefore the best ERP solutions for small business. We offer customization and implementation of ERP system. Nevpro business solutions is one of the top ERP Development companies worldwide.
For More Information on Odoo, check related Articles