Se rendre au contenu
Menu
Cette question a été signalée
3 Réponses
13940 Vues

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'
Avatar
Ignorer

Either define rec name for the model or define the name get function for the model.

To add rec name: https://www.youtube.com/watch?v=d_cyPsVc7vg&t=2s

To define name get function: https://www.youtube.com/watch?v=-1r3WSwtqxQ

Meilleure réponse

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

_columns : {
           'name': fields.char(....
Avatar
Ignorer
Auteur

Thanks a lot mate, now it's working properly

Meilleure réponse

add : _rec_name="Your Fields"

Avatar
Ignorer
Meilleure réponse

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

_rec_name="s_name",

_rec_name="e_name",
Avatar
Ignorer
Publications associées Réponses Vues Activité
2
févr. 25
13223
1
mai 16
5407
1
mars 15
5340
3
oct. 23
4528
1
mars 24
2769