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

dependent drop-down in odoo / open erp

By
Himanshu Mittal
on 10/28/14, 1:05 AM 1,650 views

I have made two drop-downs. Second dropdown's data is dependent on first drop-down's chosen value.

I have tried multiple methods, but didn't find any relevant solution.

Those are my three lists:

SELECTION_LIST = (('sela','Selected a'), ('selb','Selected b')) SELECTION_LIST_2 = (('selc','Selected c'), ('seld','Selected d')) SELECTION_LIST_3 = (('sele','Selected e'), ('self','Selected f'))

And I defined my fields this way:

'type_selection': fields.selection( [ ('selection1', 'Selection 1'), ('selection2', 'Selection 2'), ('selection3', 'Selection 3'), ], 'Category 1', required=False), 'type_selection_2': fields.selection( type_selection={ 'selection1': [{SELECTION_LIST}], 'selection2': [{SELECTION_LIST_2}], 'selection3': [{SELECTION_LIST_3}], }, "Category 2", required=False)

Unfortunately I get an error.

0

Med Said BARA

--Med Said BARA--
2664
| 5 5 7
Algeria
--Med Said BARA--
Med Said BARA
On 10/30/14, 9:04 AM

At first glance, there is a smell of (python) " Nested Lists".

But it will be helpful, if you give a concrete example, like for product's categories and subcategories, or Brand and Models of cars ...

Like We Say.. List 1 has Items -> Mobile,Laptop, Tablets List 2.1 (For Mobile) -> Samsung, Apple List 2.2 (For Laptop) -> Apple, Dell List 2.3 (For Tablet) -> Samsung, Dell, Apple How can I achieve the same

Himanshu Mittal
on 10/31/14, 2:48 AM

Any update on this??

Himanshu Mittal
on 11/4/14, 2:24 AM

Any update on this??

Himanshu Mittal
on 11/4/14, 2:24 AM
0
Himanshu Mittal
On 10/28/14, 3:10 AM

have also used onchange function like this

In xml file ->

<field name="type_selection" on_change="_set_list_data(type_selection)"/> -->

<field name="type_selection_2"/>

In python file ->

'type_selection': fields.selection([
                                  ('selection1','Selection 1'),
                                  ('selection2','Selection 2'),
                                  ('selection3','Selection 3')
                                  ],'Select Call Reason',required=False),
        'type_selection_2': fields.selection(
                                             _get_selection,
                                             'What do you want ?')

 

python function 

 def _set_list_data(self,cr,uid,selected,context=None):
        if selected == 'selection1':
            SELECTION_LIST = SELECTION_LIST_2
            vals = {'type_selection_2': SELECTION_LIST_2}        
            return {'type_selection_2': SELECTION_LIST_2}
        else:
            vals = {'type_selection_2': SELECTION_LIST_3}
            SELECTION_LIST = SELECTION_LIST_3        
            return {'type_selection_2': SELECTION_LIST_3}
        
    def _get_selection(self, cr, uid, context=None):
        return SELECTION_LIST

In your .py file move the function definition before the _columns (fields definitions)

Med Said BARA
on 10/29/14, 8:03 AM
which function?

Warm Regards,

Himanshu Mittal | Trainee,Technology |himanshu.mittal@nagarro.com| 09649417940


Nagarro Software (P) Ltd, Plot No-14, Sec-18, Electronic City, Gurgaon, Haryana-122015, India

Visit our facebook page : https://www.facebook.com/nagarrocampus

  

P Please consider the environment and do not print this email unless absolutely necessary



On Wed, Oct 29, 2014 at 5:33 PM, Med Said BARA <diassynthesis@mail.odoo.com> wrote:

In your .py file move the function definition before the _columns (fields definitions)

--
Med Said BARA
Sent by Odoo Inc. using Odoo about Forum Post False

Himanshu Mittal
on 10/29/14, 8:19 AM
Le 29/10/2014 13:19, HImanshu Mittal a écrit :
<blockquote cite="mid:CAEZJQWfuK8P-nK-KuYPyZbWEPign4bq0jONMfdB1=QiLpN_-AQ@mail.gmail.com" type="cite">
which function?

Warm Regards,

Himanshu Mittal | Trainee,Technology |himanshu.mittal@nagarro.com| 09649417940


Nagarro Software (P) Ltd, Plot No-14, Sec-18, Electronic City, Gurgaon, Haryana-122015, India

Visit our facebook page : https://www.facebook.com/nagarrocampus

  

P Please consider the environment and do not print this email unless absolutely necessary



On Wed, Oct 29, 2014 at 5:33 PM, Med Said BARA <diassynthesis@mail.odoo.com> wrote:

In your .py file move the function definition before the _columns (fields definitions)

--
Med Said BARA
Sent by Odoo Inc. using Odoo about Forum Post False

--
Himanshu Mittal
Sent by OpenERP S.A. using Odoo about Forum Post False Both: def _set_list_data and def _get_selection.

Can you post the error message you are getting?

Best regards.
Med Said BARA
on 10/29/14, 8:58 AM
Hi,
Can you please look into this

Regards,
Himanshu Mittal
Himanshu Mittal
on 10/30/14, 12:56 AM
0
Jacky
On 10/28/14, 3:05 AM

It is better to use an Onchange method in these cases.

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: 10/28/14, 1:05 AM
Seen: 1650 times
Last updated: 3/16/15, 8:10 AM