Skip to Content
Menu
This question has been flagged
2 Replies
14896 Views

I have a one2many field in a model. This model form view shows the one2many field as a tree view , where there are inline fields. I want the one2many field to be a selection list like a many2one field. I want the user to select from a list instead of typing. How can I do this? 

Avatar
Discard
Best Answer

Hi,

If you want to select multiple records in a field, you can use the Many2many field in odoo.

Using the One2many field as a selection field is a false concept.


Thank you.


Avatar
Discard
Author Best Answer

Let me explain better. As you can see at the bottom of the image, the one2many field is shown as a tree view. However when user clicks on "Add item" a new row show up with text fields to add. But instead of text field I want it to be a list of all items from database so that user can only select from the list instead of a empty field. I tried adding widget="selection" but then I get an empty selection box.

<record id="iventiva_invoice_parameter_location_form" model="ir.ui.view">
<field name="model">account.invoice.parameter</field>
<field name="inherit_id" ref="iventiva_account_invoicing.account_invoice_parameter_form"/>
<field name="arch" type="xml">
<xpath expr="//sheet" position="inside">
<group string="Assigned Locationsssrrr">
<field name="stock_location_ids" nolabel="1">
<tree editable="bottom">
<field name="name" widget="selection"/>
</tree>
</field>
</group>
</xpath>
</field>
</record>


Avatar
Discard

Then name field should be a Many2one field. not a char field.

Author

Here is the basic class structure:

class A(models.Model):

_name = 'class.A'

associated_id = fields.Many2one('class.B')

name = fields.Char("Some name")

class B(models.Model)

_name = 'class.B'

a_ids = fields.One2many('class.A', 'associated_id')

in class B view, I have:

<field name="a_ids" nolabel="1">

<tree editable="bottom">

<field name="name"/>

</tree>

</field>

I want the name field to be a selection field containing all records of class A instead of a char field so that user does not have to type, just select from the list of A record names.

Related Posts Replies Views Activity
0
Apr 15
2729
1
Mar 15
8396
0
Jun 19
2854
1
Aug 18
6743
1
Jul 17
2969