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

How to update selection field on wizard based on another fied value?

By
Franco A.
on 11/24/14, 9:39 AM 1,467 views

Hi, I have a wizard that must display files inside a directory and its subdirectories. I created a selection field with a custom selection method that displays the subdirectories and another selection field that should display files that are inside the subdirectory active on the first selection field.

So I need to update the file selection range when the user selects a value in the subdir selection but I cannot pass the value selected in the first field to the selection method of the second field.

Is there a way to do this?

I'm open to all suggestions, basically I need to let the user select a relative path inside a subdirectory in this wizard, if there's a quicker way I'm all ears :-)

Thanks
 

I think only possible way to do that is to make a many2one field instead of selection field, they get change at on_change()

Yogesh
on 11/24/14, 10:01 AM

Thanks for the answer Yogesh, I'll try that.

Franco A.
on 11/24/14, 11:48 AM

Unfortunately I wasn't able to find a solution, anyone?

Franco A.
on 11/25/14, 9:39 AM
0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 11/26/14, 6:11 AM

Franco, a selection field's list is pulled down when the HTML page is requested, so you cannot change the selections dynamically.  What I would suggest is to use a many2one field instead of selection field.  It will still be displayed similar to a selection (a dropdown), you can put a domain to restrict the list of items that can be selected, and you can change the domain dynamically using on_change.  But, user can create a new item if they have the appropriate ACL.

Thanks John, I'm trying this way, basically my problem is that I don't have a database table because I need to display a list of folders and files from the filesystem so that the user can pick one file name. I don't know how to create a model for this situation to be able to use the many2one field, do you have an idea? Thanks!

Franco A.
on 11/26/14, 7:18 AM

You can still create a model (preferably with parent_store = True) and then have a button/wizard to populate the model from file system folders. Some things that you need to consider: how would you handle the case where a folder is deleted but still referred to by the other model? Also, you need to pay special attention that you should not delete the old records when refreshing the records so that the relationships (Foreign Keys) are kept intact.

Ivan
on 11/28/14, 4:09 AM

Thanks John, I'll look into it. I'm actually using a wizard and I don't have the problem of foreign keys because I just need to display the filesystem files and folders so that the user can pick one that will populate a simple char field with the file path. It's a very simple functionality, normally in a desktop application I would use a simple 'open file' dialog, but here the task is quite complicate...

Franco A.
on 11/30/14, 10:00 AM

If it is a wizard, you can create the model to be orm.TransientModel as well and always pre-populate the model with the file system's structure.

Ivan
on 11/30/14, 11:29 PM

Sorry, I noticed that you mentioned Open File dialog, have you consider using a binary field? This way you can emulate the Open File dialog and still get the path selected.

Ivan
on 11/30/14, 11:39 PM
0
Franco A.
On 12/1/14, 1:52 PM

Sorry, this karma thing doesn't let me add another comment, only an answer, isn't  this supposed to be a discussion forum?

John can you please explain how can I populate a TransientModel when opening the wizard?

I had thought about the binary field but I need only the file path, not its content, is it possible to send to the server just the path?

Thanks!

Not commenting on the discussion forum bit. :D. To populate a TransientModel, you need to create the TransientModel FIRST before you called upon the action that display the wizard. So, your menuitem or button cannot call the action.window, but need to call this method first that will create the TransientModel, prepare the necessary entries for the many2one model, and then return action.window with domain set to [('id', '=', XXXX)] where XXXX is the return value when you create the TransientModel.

Ivan
on 12/1/14, 7:56 PM

As for the binary field, I think it would not be possible for your use case because user still need to select a file. You can still send the server just the path as the binary field will retain the path temporarily (just remove the file name portion), but not a good user experience. I usually resort to char field for paths and user need to somehow paste the path properly into it (the path is then validated first before use).

Ivan
on 12/1/14, 8:00 PM

Thanks a lot John! I'll try the first solution

Franco A.
on 12/3/14, 7:28 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

2 follower(s)

Stats

Asked: 11/24/14, 9:39 AM
Seen: 1467 times
Last updated: 3/16/15, 8:10 AM