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

Hello i make selection field 

registered_by_police = fields.Selection(selection=BOOLEAN_SELECTOR, string='Registered by')
BOOLEAN_SELECTOR = (
(False, _('No')),
(True, _('Yes')),
)

and call in view

<field name="registered_by_police" widget="radio" string="Registered by Police?"/>

if i choose no all is ok, it show no in view and i am happy. But when i choose Yes it show free space and don't save my choose. How can i solve this problem. and maybe i can make boolean field and make similar display

 
Avatar
Discard
Author

I need to use boolean values ​​because before this field was boolean and now the client wanted a different type of visual and I tried to make the old records work too, maybe there are some other solutions to the problem

Best Answer

This is because you have not declared selection properly. It needs to be key and value.

Replace your selection code with the following syntax:

BOOLEAN_SELECTOR = (

('False', _('No')),

('True', _('Yes')),

)

Hope it helps you!

Thanks,

Mayank

Avatar
Discard
Author

I need to use boolean values ​​because before this field was boolean and now the client wanted a different type of visual and I tried to make the old records work too, maybe there are some other solutions to the problem

If you need boolean value then use the above syntax of key, value and you can try any of two methods:

1 - On write method you can check if selection field value is 'Yes' then your boolean should be True else False. You need to add a boolean field before that.

2 - Add a boolean field and add onchange method for it. On onchange if your selection Field has value is 'Yes' then your boolean should be True else False.

This additional step will allow you to manage within your existing workflow.

Note: Boolean field should be the original field that your system needs to have as boolean and this selection field will be a field for reference through which you can set your boolean field.

Thanks,

Mayank

Author

Thanks for help. but i wrote widget for boolean field and solve my problem

Best Answer

Check how you can make selection field

selection_field=fields.Selection([('True','Yes'),('False','No')],'Registered By Police')


Avatar
Discard
Author

i need to use boolean types not sring in my database