0
votes

I have a many2one field like this

state = fields.Many2one ("ags.traffic.operation.state")

state has the following fields

name = fields.Char
sequence = fields.Integer
type = fields.Selection

in my view i have

<field name = "state" widget = "statusbar" clickable = "True" / >

how can i access those fields to set a default value?

1

1 Answers

0
votes

if you want to define the field that gets shown in the drop-down in your view in your model define _rec_name this tells odoo to display that field (in a drop down or in a many2many tag field) when a many2one or one2one relationship is created between that model and another model. for example if you want the sequence number to display in the drop down just set

_recname = 'sequence'

but by default odoo checks the model's field and if it finds a name field (just like you have defined in your model). it uses that as the default display name.

if you want to search records in odoo you can use the search method. please see the documentation for more information about the odoo ORM

https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.browse

search(args[, offset=0][, limit=None][, order=None][, count=False])

but a typical example is

search_records = self.env['your.model'].search([('id', 'in', ids)])