Odoo Help

0

Explain lambda expression and auto generation of ID

By
Odoo
on 10/15/14, 12:23 AM 2,523 views

  _defaults={
                'loan_id': lambda obj, cr, uid, context: '/',   #what is this line indicates
              }

class lending_info(osv.osv):
    
    _name='lending.info'
   
    _columns={
             
              'loan_id':fields.char('ID',readonly=True),

<openerp>
    <data noupdate="1">

        <!-- Sequences for loan_id -->
        <record id="seq__loan_code_inh1" model="ir.sequence.type">
            <field name="name">Loan ID</field>
            <field name="code">lending.info</field>
        </record>

        <record id="seq_cloan_code_inh2" model="ir.sequence">
            <field name="name">Loan ID</field>
            <field name="code">lending.info</field>
            <field name="prefix">LN</field>
            <field name="padding">2</field>
            
        </record>
    </data>
def create(self, cr, uid, vals, context=None):
        vals['loan_id'] = self.pool.get('ir.sequence').get(cr, uid,'lending.info')   ##what is this line indicates
        return super(lending_info, self).create(cr, uid, vals, context=context)

   

0

Hi,

First lamda expression. lambda is a one kind of function which is known as anonymous function. Function which have no any name.

lambda obj, cr, uid, context: '/'

In this expression there is two part and both are seperate using ":".

1) lambda obj, cr, uid, context 

It defines the function signature. So, here it look likes as simple function without name and "obj, cr, uid, context" are the arguments of that function as like normal function.

2)  '/'  

Here we can give any expression. In above function we have put '/' simple character. It will return when function is called.

So, 'loan_id': lambda obj, cr, uid, context: '/'

In this statement one function is called and it will return '/' (character) and it is assigned to 'loan_id' field.

I hope it is clear now.

Now, we will move on the auto generation of ID.

vals['loan_id'] = self.pool.get('ir.sequence').get(cr, uid,'lending.info')

It is simple that there is one function "get" of the model "ir.sequence" and it is calling over here and it will return the next Id based on the  passed argument. Here main argument is  'leading.info' this is the one of the name for sequences which we have defined.

Give me your feed back that it is helpful to you or you need more information.

Thx...

Odoo
on 10/15/14, 1:30 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.

Register

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)

Stats

Asked: 10/15/14, 12:23 AM
Seen: 2523 times
Last updated: 3/16/15, 8:10 AM