Odoo Help

0

0
1 Answer
0
Avatar

Hilar AK

--Hilar AK--
--Hilar AK--
  Blog:-
        https://hilarlive.wordpress.com/
  StackOverflow:
        http://stackoverflow.com/users/7561347/burmese-pythis

Quora:
    

            https://www.quora.com/profile/Hilar-Ak-1

Experienced Odoo developer, Functional Consultant.



Hilar AK
2019/3/14 上午5:12

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):
""""""
6 Comments
saiharitha varada
2019/4/7 上午3:55

okay hilar how can we pass the return value into the field as a list

Hilar AK
2019/4/8 上午1:43

return as a dict{}. the answer is updated

saiharitha varada
2019/4/8 上午1:59

@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

Hilar AK
2019/4/8 上午2:50

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.

saiharitha varada
2019/4/8 上午2:55

yes exacty i want to add list of values to a single field (selection field)

Hilar AK
2019/4/8 上午3:48

try fields.Selection(selection=method_name_which_returns_list)

Ask a Question
Tag
Keep Informed
1 follower(s)
About This Community

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

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now