Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
5 Odpowiedzi
7737 Widoki

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.

Awatar
Odrzuć

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

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.

Najlepsza odpowiedź

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.

Awatar
Odrzuć
Autor

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.

answer updated

Autor

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.

Najlepsza odpowiedź

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'),
}
Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć