I have a small dout .I have a many2one field like "course"(btech,metch, btech have 8semesters and mtech have 4semsters) another field is also many2one like "semester" when i select btech in course to automatically change the value in semester field by using compute method how i can do please suggest me.
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
write an onchange function on the field course.
eg:
@api.onchange('course')
def onchnage_course(self):
""""""
if self.course.name == 'btech':
# x should be the current semester
self.semester = x #OR RETURN AS A DICT
return {'values': {'field_name': value}}
or you can make the semester field as compute field. simply by giving the attribute compute='function name' and return the result. don't forget to give the course field name in depends.
eg:
@api.depends('course')
def func(self):
""""""
okay hilar how can we pass the return value into the field as a list
return as a dict{}. the answer is updated
@api.depends('course_id')
def _compute_set_sem(self):
sem_list=[]
if self.course_id:
if self.course_id =='btech':
count = 0
for bsem in range(1,9):
count += 1
year = bsem
if bsem % 2 == 0:
sem = (str(year/2)+ "-2")
else:
if bsem > 2:
sem = (str(year/2 + 1)+ "-1")
sem = (str(year/2 + 1)+ "-1")
tuple_sem = (str(bsem),sem)
# print tuple_sem
sem_list.append(tuple_sem)
# print sem_list
return {'values': {'btech_sems': sem_list}}
btech_sems=fields.Selection(compute='_compute_set_sem',store = True, string = 'Semester')
i wrote like this hilar but displyed assertion error
AssertionError: Field regular.single.btech_sems without selection
here you are adding a list of values to a single field. What you need actually? Domaining with the result? Compute function compute a value for the field in the current view. If you need to give domain then return dict by replacing values as 'domain', but not in a compute method but in a onchange function.
yes exacty i want to add list of values to a single field (selection field)
try fields.Selection(selection=method_name_which_returns_list)
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 | |
---|---|---|---|---|
|
1
Nov 24
|
18012 | ||
|
1
Sep 23
|
1199 | ||
|
3
May 23
|
4085 | ||
|
7
Apr 23
|
47083 | ||
Barcode scanner from mobile
Solved
|
|
1
Dec 22
|
6431 |