Odoo Help

Welcome!

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.

0

Explain lambda expression and auto generation of ID

By
Odoo
on 10/15/14, 12:23 AM 2,066 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

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 10/15/14, 12:54 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

1 follower(s)

Stats

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