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

Generate a string based on the input of other fields in a readonly field?

By
Yakito
on 2/11/15, 9:15 PM 468 views

Hi,

I am pretty new creating my custom modules. What I want to do is to create a 'custom_id' for each user based on the input of other of the fields. 

So I have a readonly field like this

'IdNumber': fields.char('Id Number', readonly=True),

And then I have

'CountryID': fields.char('Country ID', required=True),

'father_name': fields.char('Last Name', required=True),

What I want to do is to generate the IdNumber when the user inputs the data for CountryId and father_name. For example CountryID+father_name

I simply need a tip in the right direction and I will try to figure it out from there. I guess I have to use a fields.function for my IdNumber but I would like some clarification.

 

Thanks!

 

In v8 ,you can use compute method and v7 you can use fields.function

Vasanth
on 2/12/15, 12:13 AM
0
Jordan Vrtanoski
On 2/11/15, 11:05 PM

My suggetion is to create private method and decorate it with @api.onchange decorator. This will cause Odoo v8 to call this method whenever the fields specified in the decorator are changed (in your case the fields CountryID and father_name. Inside the method you can assign the new valude to the IdNumber field, and this value will be stored (check this example https://www.odoo.com/forum/help-1/question/odoo-8-api-onchange-example-how-to-copy-field-value-to-other-field-74838)

If you are trying this in V7, than the way the oncall is defined is different. In V7, you neet to place the "store" attribute on the filed and specify which model/fields to be monitored and which function/lambda to be called when the fields are modified. 

Thanks a lot Jordan. I am wondering, how did you learn about the existence of the @api.onchange? Is there any documentation (like wordpress codex for example) you suggest me to read? Thanks

Yakito
on 2/12/15, 8:01 AM

You can find more details on this page: https://www.odoo.com/documentation/8.0/reference/orm.html#module-openerp.api

Jordan Vrtanoski
on 2/12/15, 10:01 AM

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: 2/11/15, 9:15 PM
Seen: 468 times
Last updated: 3/16/15, 8:10 AM