Odoo Help


How to load field value in create method?

Abdullah Sofan
on 12/4/14, 5:33 AM 1,217 views

I want to load a field value (batch_course_name) into a variable ( loadthefield ) inside a create method in order to use it as a prefix to a sequence field (name). I just don't know how to do that. Can you help me?



class intrac_batches(osv.osv):

    def create(self, cr, uid, vals, context=None):
        if not vals:
            vals = {}
        if context is None:
           context = {}

         loadthefield =   what to put here to load the value of the field batch_course_name

        vals['name'] = loadthefield + self.pool.get('ir.sequence').get(cr, uid, 'intrac.batches.number')
        return super(intrac_batches, self).create(cr, uid, vals, context=context)

    _name = 'intrac.batches'
    _columns = {
        'name': fields.char('Batch Number'),

        'batch_course_name': fields.many2one('intrac.courses', 'Course'),





| 5 4 7
Bikaner, India

OpenERP Developer at SunARC Technology

On 12/4/14, 8:08 AM

Using self.pool.get and browse method load many2one field value in create method.

if 'batch_course_name' in vals:
            course_obj = self.pool.get('intrac.courses')
            course_value = course_obj.browse(cr, uid, vals['batch_course_name'])  
            course_name = course_value.name   
            course_name = False
        vals['name'] = course_name + self.pool.get('ir.sequence').get(cr, uid, 'intrac.batches.number')

Abdullah Sofan
On 12/4/14, 10:37 AM

Thanks a billion Parkash

Prakash has mentioned it, although indirectly. You get the value from the form (assuming that it is not readonly) within the vals dictionary, i.e. vals['batch_course_name']. If you want to avoid KeyError, use vals.get('batch_course_name', ''). It will return empty string ('') if batch_course_name is not found.

on 12/4/14, 10:56 AM

You are right Ivan. Thank you both for your great help.

Abdullah Sofan
on 12/5/14, 2:07 AM

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: 12/4/14, 5:33 AM
Seen: 1217 times
Last updated: 3/16/15, 8:10 AM