Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
6 Odpovědi
28497 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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

Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit

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

Nejlepší odpověď

hai arun,

  It  works thank you.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
pro 16
4909
1
čvc 16
5129
4
dub 16
6996
6
lis 15
5392
1
bře 15
3425