Odoo Help


problem in my module with field many2one.

on 8/31/13, 10:31 AM 2,312 views


i just created a table/model named "logistic.charge" for storing three values with field say: from ,to, fare. Then from the form i succesfully saved the three values.

then i created a table/model named "logistic.logistic" with same field mentioned above here many2one is used for picking the value from logistic.charge . this will installed succesfully. Here is the py file

from openerp.osv import fields, osv

class logistic_detail(osv.osv):
     _name = "logistic.logistic"
     _description = "Logistic charges"
     _columns = {
         'from': fields.many2one('logistic.charge','from','from'),
         'to': fields.many2one('logistic.charge','to','to'), 
         'fare': fields.many2one('logistic.charge','fare','fare'),          


But in the form view there have three fields. from , to , inorder to click the arrow in the field . it will not display the content of the corresponding coloum in the table logistic.charge this will display the name of the table and an id here is the image

image description

is there any error in programming. in place i put res.partner this will gives output by listing the partners in the table.

I think in object "logistic.charge" does not have field "name". You try to add field "name" for this object or use _rec_name = "field_a" ("field_a" is a field which you want to view value in many2one field).

OpenERP Vietnam
on 8/31/13, 11:31 AM

I've already told you. You have to add _rec_name in 'logistic.charge' class. res.partner displays the name because that class has a 'name' field. If you don't have a name field you have to add _rec_name property.

GH Mediacloud, Grover Menacho
on 9/2/13, 3:09 AM

Grover Menacho

--Grover Menacho--
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 8/31/13, 11:23 AM

You forgot the _rec_name. You have to add it when you are not using 'name' column.

class logistic_charge(osv.osv):
_columns = {
    'field_name': fields.char(....),

I'm sure that you created the logistic_charge object, so add the _rec_name before columns with the name of one of your fields, for example here i have 'field_name' maybe you have other fields. The field that you want to display is the _rec_name.

hai..Grover . I am new in python . so will you please mention how it is to be implemented in my py file. Where _rec_name should be placed, it is a field in the table.

on 9/2/13, 3:34 AM

answer updated

GH Mediacloud, Grover Menacho
on 9/2/13, 1:32 PM

Hello Grover now it solves the problem in my question. But an another problem is in my first field "from" the actual value will be displayed that i entered in the first form. This value should be also displayed in the another fields.

on 9/11/13, 4:49 AM
On 9/2/13, 1:05 PM

For example : class mylibrary_author(osv.osv):

_name = 'mylibrary.author'
_columns = {
    'firstname': fields.char('FirstName',size=64),
    'lastname': fields.char('LastName',size=64),
    'book_ids': fields.one2many('mylibrary.book','author_id','Books'),
Abhishek H Menon
On 9/3/13, 8:38 AM

You can override the name_get method in your model to get the answer. Just try that.

On 9/3/13, 8:59 AM

I don't want to create another topic because my problem is the same. I've tried your solutions, this is what I have so far:

class open_classB(osv.osv):
    _name = "open.classB"
    _rec_name = 'desc'
    _columns = {
        'desc':fields.char("Description:", size = 50, required = True),
class open_classA(osv.osv):
    _name = 'open.classA'
    _columns = {
                'desc_id':fields.many2one('open.classB', 'Description:', 'desc'),

Before what people said here, I didn't have the "_rec_name", and it didn't work also. The items continues to show me like the image on the first post.

wilson zauma
On 3/31/14, 1:46 PM

I use a function and relation with this in my_file.py:

def _buscar_shortname_alm(self, cr, uid, context=None):

    ids = obj.search(cr, uid, [('shortcut', '!=', False),('usage','in',('internal','production'))],
     resultado = obj.read(cr, uid, ids, ['id','shortcut'], context)

    #convertimos a una lista de tuplas
    res = []
    for record in resultado:
        #creamos la tupla interna
        rec = []
        #convertimos a cadena el ID para crear la tupla
        #agregamos a tupla final
     return res

And the _columns put this:

'aux_almacen_orig': fields.selection(_buscar_shortname_alm, type="char",store=True, method=True,size=256, required=True, string="Almacen Origen" ),

Then i put this in my_file.xml

<field name="aux_almacen_orig" />

And finally this is the result. http://(www).orchidshouseperu.com/screenshots/Seleccion_041.png

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 8/31/13, 10:31 AM
Seen: 2312 times
Last updated: 3/16/15, 8:10 AM