Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Showing many2one fields in other modules

By
Dominic
on 5/23/16, 2:04 PM 521 views

Hello, 

I created a new many2one field in res.partner (inherited): 

Py file:

city = fields.Many2one('res.country.state.city', "Department") 


XML View:

<field name="city" options="{'no_open': True}" placeholder="Cuidad" attrs="{'readonly':[('change_country', '=', False)], 'invisible':[('state_id', '=', False)]}" />


As you see I am trying to modify / extend the address in res.partner.
In my module res.partner it looks very good, so the city is shown correctly (e.g. "New York")


When I open another module where the address is used, e.g. state.order, the variable city is not shown correctly as the type of the field changed from Char to many2one. Instead of showing the city, I get this value in sale.order:

res.country.state.city(820,) 63


Obviously I want to see the city and not some numbers :-). I assume that any other module is trying to read the variable as a Char, but the type changed to many2one. 


Any ideas on how to solve this issue? Is there a way to transform values of many2one filed to simple text / char?

1

Prakash Sharma

--Prakash Sharma--
815
| 2 1 4
Delhi, India
--Prakash Sharma--

I like to surround myself with brave, creative people.

My motivation for learning different technologies and algos drive me. I love challenges of a steep learning curve which I believe makes me a better learner. I have a strong desire to learn different technologies, which would enable me to become a full stack developer.

Prakash Sharma
On 5/23/16, 2:15 PM
# create a related field with city_id as below: 
city_id = fields.Many2one('res.country.state.city', "CityID") 
city = fields.Char(related='city_id.name', "City") 

0

Jusab Sida (jsi)

--Jusab Sida (jsi)--
Tiny ERP Pvt Ltd
http://www.odoo.com
874
| 2 1 5
Gandhinagar, India
--Jusab Sida (jsi)--


Jusab Sida (jsi)
On 5/24/16, 6:53 AM

Hi  Dominic,

   Its because of 'name' field or "_rec_name" is not defined in your model "res.country.state.city".

Add _rec_name after model name like...

_name = "res.country.state.city"
_rec_name = "city"

You will get some detailed answer from here:

https://www.odoo.com/forum/help-1/question/many2one-field-shows-only-id-21912
https://www.odoo.com/forum/help-1/question/many2one-field-not-showing-field-values-50268

 Kind Regards,

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/23/16, 2:04 PM
Seen: 521 times
Last updated: 5/25/16, 10:25 AM