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

Can I generate Fields on the Fly based on a field selection?

By
Yakito
on 7/10/13, 5:24 AM 1,356 views

Hello,

I been thinking over this one for the past few days with no luck. Maybe someone can help.

I am building a module where I have different Hotels (X number) and each Hotel has different amenities. For that I created a one2many field which inserts the amenities of each Hotel into the amenities table.

Now my problem starts when I need to create the Clients table. For that I have a form view were I am asking for the Client Name, x, x, and Hotel with a many2one field referencing the previous table. In that same form I need to list the amenities that hotel has from the amenities table created above and be able to set a price for each amenity on the list. Each client has a different price even for the same Hotel.

+---------+----------+
| Hotel A | Client A |
+---------+----------+
| Pool    | $34      |
| SPA     | $12      |
| Gym     | $23      |
+---------+----------+
+---------+----------+
| Hotel A | Client B |
+---------+----------+
| Pool    | $74      |
| SPA     | $62      |
| Gym     | $233     |
+---------+----------+

Is there any way I can generate the fields on the fly as soon as the user selects the Hotel? I was thinking if I can do that to save the data into a PricePerClient table where I would have, Client ID, Amenity ID, Price. The Client ID must be the current ID of the form I am seeing.

Any tip/idea will be much appreciated! Thanks! :)

1
nazarii
On 7/11/13, 7:01 PM

My suggestion is to use amenities field as many2one instead of selection. Next you need to put on_change event on you Hotel' field which will calculate ids of amenities for selected Hotel , so each time Hotel' has been changed it will update domain of amenities. You'r on_change must return smth like:

return {'domain': {'amenities': [('id', 'in', amenities_ids)]}}

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

0 follower(s)

Stats

Asked: 7/10/13, 5:24 AM
Seen: 1356 times
Last updated: 3/16/15, 8:10 AM