Reputation: 431
I am trying to create a selection field in Odoo9. I can add an item but it does not save the name only the name of user who created it.
My model.py looks like
from openerp import models, api, fields
class ComputerItems(models.Model):
_name = "notebook"
items_computer = fields.Char("Items")
ds_items = fields.Char("Items")
class ds_repair(models.Model):
_name = "ds.repair"
x_partner_id = fields.Many2one('res.partner', 'Client', required=True)
other = fields.Char("Other", size=128)
items = fields.Many2many('notebook',
'ds_items', string='Items')
My model.xml
<record id="view_ds_repair_form" model="ir.ui.view">
<field name="name">ds.repair.form</field>
<field name="model">ds.repair</field>
<field name="arch" type="xml">
<form string="Repairs">
<sheet>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<group colspan="4" col="6">
<h1><field name="x_partner_id" placeholder="Customer Name"/></h1>
<field name="create_date"/>
<h2>Priority<field name="priority"/></h2>
</group>
<group colspan="4" col="6">
<field name="computer_make"/>
<field name="password" colspan="2"/>
<field name="items"/>
</group>
</div>
Upvotes: 1
Views: 3145
Reputation: 14721
When you don't create any tree for you model odoo will create a costum tree for it :
first he will check the value of attribute _rec_name
.rec_name contain the name of the field that represent the record by default the _rec_name = "name"
so odoo will look for a field named name
if it exists, odoo will create a tree with one field. but like in you case your Model don't have a field named name odoo will create a tree with create_uid
. in order to tell odoo to create a tree from another field you change the value of _rec_name
class ModelClass(models.Model):
_name ="model.name"
_rec_name = "field_name"
field_name = fields.....
this is good when your model have only one field but when your Model have more than one field you have two choices
if your Model needs only one tree for all kind of usage create a tree for it and odoo will always call it
if your Model can have multi tree for diffrent many2many or one2many field you can do this :
<field name="x2many_field_name" >
<tree>
<!-- your field here -->
</tree>
<form>
<!-- costum form here -->
</form>
</field>
if you want to use many2many_tags
widget you need to specify the_rec_name
_rec_name = "field_name"
<field name="x2many_field_name" widget="many2many_tags" />
Upvotes: 2
Reputation: 1841
Just change like the below for the field 'items'
<field name="items" widget="many2many_tags"/>
Upvotes: 1