Showing posts with label use of lambda in openerp 7.0. Show all posts
Showing posts with label use of lambda in openerp 7.0. Show all posts

Monday, 24 December 2012

Use of lambda in OpenERP 7.0


                                                                                                                    Pinakin Nayi
                                                                                                                    OpenERP , Gandhinagar, India
                                                                                                                   
Different use of lambda in OpenERP 7.0
In OpenERP we are using a lambda function, here i described some of function that all are normally use, that may be useful to you also.
- Map your ids using lambda :
    ids = map(lambda x: x[0], self.cr.fetchall())

- Get date using lambda
    'date2': lambda *a: time.strftime('%Y-%m-%d')
   
- Get Company id using lambda
    'company_id': lambda self,cr,uid,c:    
    self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
   
- Get user id using lambda
    'user_id': lambda self, cr, uid, context=None: uid,
   
- Get start and end date using lambda
    'date_start': lambda *a: time.strftime('%Y-01-01'),
    'date_stop': lambda *a: time.strftime('%Y-12-31'),
   
- Get Currency id using lambda
    'currency_id': lambda self,cr,uid,c:self.pool.get('res.users').browse(cr, uid, uid,
c).company_id.currency_id.id,
   
- Get month and year using lambda
    'month': lambda *a: time.gmtime()[1],
    'year': lambda *a: time.gmtime()[0],
   
    'month': lambda *a: datetime.date.today().month,
    'year': lambda *a: datetime.date.today().year,

...Enjoy...