Skip to Content
Menu
This question has been flagged
4 Replies
2074 Views

Hey! i have quizz_score field in "survey.user_input" model . i want to put a check that if any value in it is negative then it must change to zero. It is already a computed field with this method

@api.depends('user_input_line_ids.quizz_mark')
def _compute_quizz_score(self):
for user_input in self:
user_input.quizz_score = sum(user_input.user_input_line_ids.mapped('quizz_mark'))

I have added the following lines under the same method but this ain't working
if user_input.quizz_score <= 0:
user_input.quizz_score = 0.00

Kindly help. Thanks in advance
Avatar
Discard
Best Answer

Hi Abdullah,

Please try to use following code:

@api.depends('user_input_line_ids.quizz_mark')
def _compute_quizz_score(self):
        for user_input in self:
            score = sum(user_input.user_input_line_ids.mapped('quizz_mark'))
            if score <= 0:
                user_input.quizz_score = 0
            else:
                user_input.quizz_score = score

    

 Thanks.

Avatar
Discard
Author

Hey Thanks for replying. What about the loop ?

Hi,

Sorry forgot to add loop.Here is the latest code:

@api.depends('user_input_line_ids.quizz_mark')

def _compute_quizz_score(self):

for user_input in self:

score = sum(user_input.user_input_line_ids.mapped('quizz_mark'))

if score <= 0:

user_input.quizz_score = 0

else:

user_input.quizz_score = score

Thanks.

Author

I have used this but still not working. Something wrong with this chunk?

@api.depends('user_input_line_ids.quizz_mark')

def _compute_quizz_score(self):

for user_input in self:

score = sum(user_input.user_input_line_ids.mapped('quizz_mark'))

if score <= 0:

user_input.quizz_score = 0

else:

user_input.quizz_score = score

Author

Man sorry for bothering u again but i tried your updated chunk again , but not working and i dont think we are missing anything :D