2013-10-21 117 views
1

在我的OpenERP應用程序,我有我試圖理解一個lambda(currency_id):分解一個OpenERP的拉姆達

_defaults = { 
     'display_type': True, 
     'journal_ids': [], 
     'target_move': False, 
     'currency_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.currency_id.id, 
    } 

到目前爲止,我的理解是這樣做的:

  • 啓動與表res_users,其具有COMPANY_ID字段
  • 使用瀏覽命令訪問交流onnected記錄

瀏覽函數具有的原型:瀏覽(CR,UID,IDS,上下文=無)。我們通過uid作爲ID爲什麼我們要通過uid而不是id?

res_company表具有currency_id場。

然後我假設它使用外鍵通過OpenERP的ORM訪問它。 怎樣的ORM知道如何連接到** res_company場**

類似問題 what is the reason of using _defaults and lambda in python for openerp development?

回答

1

你是正確的:我們確實希望IDS傳遞給browse。然而,在這種情況下,uidres.users對象的ID,它是當前登錄的。因此,

self.pool.get('res.users').browse(cr, uid, uid, c)

返回對應於登錄的用戶的的對象browse_record。該用戶有一個與之關聯的公司(通過company_id),該公司有一個貨幣(currency_id),我們使用該貨幣的id作爲該用戶所做任何事情的默認貨幣。

+0

感謝您的明確答覆。 – ardochhigh