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

problem in my module with field many2one.

By
charlesraj
on 8/31/13, 10:31 AM 2,083 views

hi.

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'),          

        }
logistic_detail()

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
2

Grover Menacho

--Grover Menacho--
2523
| 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):
_name='logistic.charge'
...
_rec_name='field_name'
_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.

charlesraj
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.

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

For example : class mylibrary_author(osv.osv):

_name = 'mylibrary.author'
_rec_name='lastname'
_columns = {
    'firstname': fields.char('FirstName',size=64),
    'lastname': fields.char('LastName',size=64),
    'book_ids': fields.one2many('mylibrary.book','author_id','Books'),
}
1
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.

0
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):

    obj=self.pool.get('stock.location')
    ids = obj.search(cr, uid, [('shortcut', '!=', False),('usage','in',('internal','production'))],
        order='shortcut') 
     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
        rec.append(str(record['id']))
        rec.append(record['shortcut'])
        #agregamos a tupla final
        res.append(tuple(rec))
     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

0
karlos
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),
    }
open_classB()
class open_classA(osv.osv):
    _name = 'open.classA'
    _columns = {
                 'notes':fields.text('Notes:'),
                'desc_id':fields.many2one('open.classB', 'Description:', 'desc'),
               }
open_classA()

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.

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

1 follower(s)

Stats

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