Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
6395 Zobrazení

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.

Avatar
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Autor Nejlepší odpověď

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

Avatar
Zrušit

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

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

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.
Nejlepší odpověď

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 ...

Avatar
Zrušit
Autor

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

Autor

Any update on this??

Autor

Any update on this??