How to keep selected boolean fields based on computed result in odoo 10?

Multi tool use
Multi tool use


How to keep selected boolean fields based on computed result in odoo 10?



I have a scenario, where need to keep selected boolean fields based on computed result before saving record, so how can i do this?



Here is my code :


option = fields.Boolean(string='option')
selected_option = fields.Boolean(compute='check_value', string='Selected')



@api.multi
def check_value(self):
for result in self:
if result.option == True:
result.selected_option = True
result.selected_option = False





Correct the indentation to understand what check_value do, because it seems that your code always sets the selected_option to False.
– WaKo
Jul 2 at 8:24



check_value


selected_option


False




3 Answers
3



Please try this Code :


option = fields.Boolean(string='option')
selected_option = fields.Boolean(compute='check_value', string='Selected')

@api.depends('option')
def check_value(self):
for result in self:
if result.option:
result.selected_option = True
else:
result.selected_option = False





@Mani In python, it is better to use if result.option instead of if result.option == True: as you can find at python.org/dev/peps/pep-0008 Don't compare boolean values to True or False using ==
– WaKo
Jul 2 at 12:17



if result.option


if result.option == True:


Don't compare boolean values to True or False using ==


selected_option = fields.Boolean(compute='check_value', string='Selected', store=True)



Write the onchange function for Boolean field (Option)


option = fields.Boolean(string='option')
selected_option = fields.Boolean(string='Selected')

@api.onchange('option')
def check_value(self):
for result in self:
if result.option == True:
result.selected_option = True
else:
result.selected_option = False






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

tFfsrv,zgj T7usgU2Ge4YNBEhC
0R C dGtC4OKpvwHR8fXhu0rEH3 syzOdhG3rOgYDZJEVynqHLr6 eS4PsT,x,25Y9 V1e,DkBlQ3Q,XxlsGJj,6YT12 FcQBZzzCW3D9G

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications