Odoo Help

Welcome!

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

0

How to create a checkbox field in odoo 8?

By
bhanukiran
on 3/1/16, 1:56 AM 1,395 views

Here is my declared field in account_voucher.py file,

'type':fields.selection([('dr','Debit'),('cr','Credit')], 'Dr/Cr')

In the view(xml file),

 <field name="type" widget="radio" options='{"horizontal": 1}' />

Right now it is radio button I want to change it to checkbox  

1
amina
On 3/1/16, 4:43 AM

To explain this and make it clearer,this type of checkbox that you want to add works only with the manytomany fields,and this field will display one checkbox for each record existing in the model targeted by the relation, according to the given domain if one is specified.Checked records will be added to the relation 

and There’s no way to use this widget to create new items

<field name="field_name" widget="many2many_checkboxes"/>

and as it seems you declared that field as selection filed so you have two options the first is to follow the first method of boolean type or to do like Ankit H had said

you could create boolean fields for each selection and put them in your view definition like this in the .py file:

_columns = {

'dr': fields.boolean('Debit'),
'cr': fields.boolean('Credit'),
}

and in the xml:

<field name="arch" type="xml">

<form>

<group>

<field name="dr" attrs="{'invisible': [('cr','=',True)]}"/>

<field name="cr" attrs="{'invisible': [('dr','=',True)]}"/>

</group>

</form>

</field>

hope it helps you

I dont want to alter python code, I just to want to acheive it just by using xml file, So is their any widget for checkbox?

bhanukiran
on 3/1/16, 4:55 AM

hope it helps, modified my answer

amina
on 3/1/16, 5:46 AM
1
Arunkumar
On 8/24/16, 2:46 AM

hai,

Just create given below in .py file

          'blue' : fields.boolean('Blue'),

         'pink' : fields.boolean('Pink'),

then xml file do this,

         <field name="blue" type="checkbox" />

       <field name="pink" type="checkbox" />

Try this it's worked for me


1

Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--
996
| 5 3 6
Rajkot, India
--Ankit H Gandhi(AHG)--

Learning Python..

Ankit H Gandhi(AHG)
On 3/1/16, 4:47 AM

Hello Bhanukiran,

You could use widget like many2many_checkboxes.

But your field type must be many2many

For example

in .py file.

class type_type(osv.Model):

_name = 'type.type'

_columns = {

'name': fields.char('Name')

}

class your_class_name(osv.Model):

_name = 'your.class.name'

_columns = {

'type_checkbox': fields.many2many('type.type', 'type_help_rel', 'type_id', 'help_id', 'Type')

}

in xml file.

<field name="type_checkbox" widget="many2many_checkboxes"/>

Hope this help for you.

Cheers,

Ankit H Gandhi.

0
Maruthamuthu
On 8/24/16, 5:43 AM

hai arun,

  It  works thank you.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/1/16, 1:56 AM
Seen: 1395 times
Last updated: 8/24/16, 5:43 AM