This question has been flagged
1 Reply
7171 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)

   

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

Thx...