Search Here

Show two different values in many2one field in Odoo

In this article you will learn how to display the value of two columns (fields) in many2one field in OpenErp. In Odoo many2one fields mean selection field and by default value of  "name" field shows in many2one field or selection field in another module.

Show two different values in many2one field in Odoo


Show two different values in many2one field in Odoo

For example we have a model "model.section" having field named "name" and stored value of "name" in database is (A,B,C,D). Here (A,B,C,D) shows section name, And we are using it as reference in other model, named "model.register", to provide registered section detail and it will show the section name (A,B,C,D) in selection list.



Here the problem is "name" field can't be used to differentiate the section. So in this case we will override name_get method in our desired model. Here our goal is to view the "section name + subject name".


name_get()

This method is used to display value of a record in a many2one field. Returns a textual representation for the record in self.


Return          ----->  (id , "text_represent") for each record
Return type  -----> list of tuple / list(tuple)

Now I will override name_get() method.

show_more_than_one_field_value_in_many2one.py




In line no 9 here I need to prepare a list of tuple as a return value to our method. 

Post a Comment

2 Comments

  1. if i want with same model Many2one in auther view interface display auther value what u do?

    ReplyDelete