Ali khan
Ali khan

Reputation: 195

How to get name for a record and display it on form

I got a problem, after saving a record , for view displays model name plus record number . like in the screen shot . i want only record name appear there . thanks in advance

my form with model name and , record number

please help , except _rec_name , cause here i get multiples ids from multiple tables

Upvotes: 2

Views: 603

Answers (1)

Adrian Merrall
Adrian Merrall

Reputation: 2499

OpenERP/Odoo will call name_get on your model to display this. If you override name_get you can return whatever you want, otherwise it will use the name_get on the BaseModel class.

This will:

  1. Return the field specied by you as _rec_name on your model
  2. Look for a column called "name" and use that.
  3. Auto-generate one.

The easiest thing to do as Quentin said is have a column called "name" but sometimes it doesn't make sense. For example, in product.supplierinfo the name field is actually the supplier ID - seems like someone was too lazy to do it properly.

Failing that, define a _rec_name field or override name_get yourself but there are a couple of got-chas.

  1. Unlike functional fields, name_get returns a list of tuples where each tuple is (id, name).
  2. If you use a column other than name or you override name_get, you also need to think about overriding name_search to give the user a consistent behaviour. The product.product model has good examples of this.

Upvotes: 3

Related Questions