Odoo Help


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.


Inherit Method Get Code and Name with 1 Field [Closed]

on 12/23/14, 9:07 PM 627 views

The Question has been closed

on 01/21/2016 23:17:32

i have 1 field kd_provinsi , i want value of this field are code and name of the form fed.state.

for example : [BDG] Bandung

my code.py


can i inherit method in res.country.state ? i have use this method but its doesnt work

    def prov_get(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        res = []
        for record in self.browse(cr, uid, ids, context=context):
            tit = "[%s] %s" % (record.name, record.code)
            res.append((record.id, tit))
        return res

anyone please help me


Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 12/24/14, 12:07 AM

name_get ORM method needs to be used. (https://doc.odoo.com/6.0/developer/2_5_Objects_Fields_Methods/methods/#osv.osv.osv.name_get)

    def name_get(self, cr, uid, ids, context=None):
        if not ids:
            return []
        if isinstance(ids, (int, long)):
                    ids = [ids]
        reads = self.read(cr, uid, ids, ['name', 'code'], context=context)
        res = []
        for record in reads:
            name = record['name']
            if record['code']:
                name = record['code'] + ' ' + name
            res.append((record['id'], name))
        return res

Also, check this question: https://www.odoo.com/forum/help-1/question/using-name-get-how-to-shows-two-different-display-values-2589

About This Community

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

Question tools

1 follower(s)


Asked: 12/23/14, 9:07 PM
Seen: 627 times
Last updated: 1/21/16, 11:17 PM