Skip to Content
Menu
This question has been flagged
6 Replies
26827 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  

Avatar
Discard
Best Answer

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

Avatar
Discard
Author

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?

hope it helps, modified my answer

Best Answer

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


Avatar
Discard
Best Answer

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.

Avatar
Discard

Hello Ankit I have used checkbox of many2many fields for stock location. It works fine for me but how to divide checkbox there is lots of number of record in stock location its showing me right side only there is any type to divide into row and column to the checkbox

Best Answer

hai arun,

  It  works thank you.

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 16
3825
1
Jul 16
3948
4
Apr 16
5804
6
Nov 15
4411
1
Mar 15
2293