Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
16716 Vizualizări

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? 

Imagine profil
Abandonează
Cel mai bun răspuns

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.


Imagine profil
Abandonează
Autor Cel mai bun răspuns

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>


Imagine profil
Abandonează

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

Autor

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 Răspunsuri Vizualizări Activitate
0
apr. 15
3828
1
mar. 15
9387
1
dec. 24
1418
0
iun. 19
3702
1
aug. 18
7942