Hi guys i am using odoo 14, i have created a custom module that inherit into odoo, i want to create a selection field which i related to another field for eg: i have a selection field: A it has 3 options 1,2,3 if i select option 1 , it should show another selection field which should come only if i select 1 , if i select 2 it should show another selection field , is there any way i can achieve this using python or xml in odoo
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
Hi, @jo
In Python, Define all the SELECTION FIELDS that is required feature, that is the selection field with value 1 2 3 and selection field that will show for option 1 and selection field to show for option 2.
selection = fields.Selection([('1', '1'), ('2', '2'), ('3', '3')])
slection_for_opt_1 = fields.Selection([('5', '5'), ('6', '6')])
slection_for_opt_2 = fields.Selection([('7', '7'), ('8', '8')])
In XML, Add attrs attribute for the field defination on view as mentioned below
field name="selection"
field name="slection_for_opt_1" attrs="{'invisible': [('selection', '!=', '1')]}"
field name="slection_for_opt_2" attrs="{'invisible': [('selection', '!=', '2')]}"
Hi @Sujata Bhuyan, i tried the code you shared but i am getting this error ValueError: dictionary update sequence element #0 has length 3; 2 is required
Hi @jo, Can you share your code here. So that I can help.
python side
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class FieldsCustomDropDown(models.Model):
_inherit = 'sale.order'
selection = fields.Selection([('1', '1'), ('2', '2'), ('3', '3')])
slection_for_opt_1 = fields.Selection([('5', '6', '7')])
slection_for_opt_2 = fields.Selection([('8', '9', '10')])
slection_for_opt_3 = fields.Selection([('11', '12', '13')])
xml side
<record id="new_test_add_custom_purchase_fields_parameters_inherit" model="ir.ui.view">
<field name="name">purchase.test.add..new.custom.fields.inherited</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='category']"
position="after">
<field name="item"/>
</xpath>
</field>
</record>
actual selection will be around 10 options this for testing purpose i did but its not working
Hi Jo,
Please find code in comment.
I hope this will help you.
Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari
Code :-
XML:
<field name="selection"/>
<field name="slection_for_opt_1" attrs="{'invisible': [('selection', '!=', '1')]}"/>
<field name="slection_for_opt_2" attrs="{'invisible': [('selection', '!=', '2')]}"/>
PY:
selection = fields.Selection([('1', '1'), ('2', '2'), ('3', '3')], string="Selection")
slection_for_opt_1 = fields.Selection([('5', '5'), ('6', '6'), ('7', '7')], string="Selection_1")
slection_for_opt_2 = fields.Selection([('8', '8'), ('9', '9'), ('10', '10')], string="Selection_2")
this worked perfectly, i made an error in python side that's why it was not reflecting, thank you sir
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
0
Mar 15
|
3676 | ||
|
2
Mar 15
|
28865 | ||
|
0
Mar 15
|
5601 | ||
|
2
Dec 23
|
11088 | ||
|
3
Jul 22
|
20959 |