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

Displaying custom view on one2many popup depending on condition

By
Madura
on 12/1/14, 7:37 AM 642 views

I'm creating a custom module and I have a one2many field in it. Records can be added to the one2many field and in the popup that comes when creating a record, I have arranged the fields as a table. There are two such tables. There is a record description field in each record which is selectable through a drop down menu. Depending on the selection, I want to display the relevant table for the user to enter data. I achieved this by checking through javascript level and showing and hiding the relevant table through jquery. Is there a better way to do this?

After the record is saved, and when I click on the record in the one2many field to view it, it shows the default table that displays, even if the description says it should be the other table. Is it possible to fix this? Will an RPC in javascript level be able to address this issue?

Not sure why you implement it as two tables. But you can set the tables (one2many fields) to be invisible on certain condition using attrs in view.xml.

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

Think of it like this: the model on the "many" side has a field "choice" which contains choice1 and choice2. The same model has a number of other fields, but if the user selects choice1, then I should show only a subset of those fields, which I will call view1. If it is choice2, then I should hide the first set of fields and show the rest of the fields, which would be view2. On both occations, the fields are arranged in the UI in such a way that they appear in the form of a table in the popup that comes up when creating or editing a record in the one2many. By default, choice1 is selected and hence view1 is displayed. When no record is added yet, in the edit mode the show/hide of the view depending on the choice seems to work correctly. But when a record is added and saved, in view mode, even if the record is saved as choice2, it displays the view of choice1. Hence my question is whether it is possible to set the proper view, based on the choice saved in the record, in view mode?

Madura
on 12/1/14, 11:14 PM

Oh OK. I think you need to inherit / override the fields_view_get in order to get the proper view based on certain context. You can specify the context to be fed from a field's value. Examples of this can be found in odoo/odoo/addons/account_voucher/account_voucher.py.

Ivan
on 12/1/14, 11:41 PM

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: 12/1/14, 7:37 AM
Seen: 642 times
Last updated: 3/16/15, 8:10 AM