Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Many2one field shows only id

By
Veslav
on 6/20/13, 7:13 AM 4,219 views

Hello, I am modifying Employee directory app, I am adding new menu items and forms for employee faults. Faults form has many2one field where you can choose fault type. When I am creating fault type everything is ok, it shows name and severity like it should, but when I am trying to choose it in many2one field it only shows module name and id e.g hr.fault,1. I want it to show fault types name. What I am missing? Here is my code:

class hr_faults(osv.osv):
_inherits = {'resource.resource': "e_name"}



_name = "hr.faults"
_description = "Faults"

def get_total(self, cr, uid, ids, context=None):

    address = self.pool.get('hr.fault').browse(cr, uid, ids, context=context)

    return address.s_name


_columns = {
    'e_name':fields.many2one('hr.employee', 'Name'),

    'fault_date': fields.date('Date', transale=True),
    'rec_name': fields.many2one('hr.employee', 'Recorded by'),
    'f_type': fields.many2one('hr.fault','Fault type',select=True,type='char'),
    'f_comment': fields.text('Comment'),
    'f_severity': fields.related('f_type','fs_severity',type='integer', string='Severity',readonly=True,),
    'resource_id':fields.related('e_name','resource_id',type='integer', string='Name', readonly=True, store=True),


}

hr_faults()

class hr_fault(osv.osv):

_name = "hr.fault"
_description = "Faults types"



_columns = {
    's_name':fields.char('Fault type',required=True,select=True,store=True,type='char',   priority=1),
    'e_desc':fields.char('Description',store=True),
    'fs_severity': fields.selection([('1', '1'),('2', '2'),('3', '3'),('4', '4'),('5', '5')], 'Severity',store=True),



}
_order='s_name'
3

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 6/20/13, 9:04 AM

just change the fields' name: change "s_name" to "name" and "e_name" to "name"

_columns : {
           'name': fields.char(....

Thanks a lot mate, now it's working properly

Veslav
on 6/20/13, 9:48 AM
1
sunil
On 9/13/13, 5:31 AM

add : _rec_name="Your Fields"

1

Atul Kumar jain

--Atul Kumar jain--
914
| 5 3 7
Indore, India
--Atul Kumar jain--

.

Atul Kumar jain
On 3/13/14, 6:29 AM

you can add this line after description so it will work for your existing field

_rec_name="s_name",

_rec_name="e_name",

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 6/20/13, 7:13 AM
Seen: 4219 times
Last updated: 3/16/15, 8:10 AM