Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
16840 Lượt xem

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? 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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>


Ảnh đại diện
Huỷ bỏ

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

Tác giả

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.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 15
3889
1
thg 3 15
9435
1
thg 12 24
1524
0
thg 6 19
3771
1
thg 8 18
8010