1

在我的 OpenERP 应用程序中,我有一个我想要理解的 lambda (currency_id):

_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字段
  • 使用浏览命令访问连接的记录

浏览函数的原型为:browse (cr, uid, ids, context=None)。我们将uid作为ids传递给它。为什么我们传递的是 uid 而不是 ids?

res_company表有currency_id字段

然后我假设它使用外键通过 OpenERP 的 ORM 访问它。ORM 是如何知道如何连接到 **res_company字段的?**

类似的问题 在 python 中使用 _defaults 和 lambda 进行 openerp 开发的原因是什么?

4

1 回答 1

1

You are correct: we do want to pass ids to browse. However, in this case uid is the id of the res.users object who is currently logged in. Thus,

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

returns the browse_record object corresponding to the logged in user. This user has a company associated with it (via company_id) which has a currency (currency_id), and we use that currency's id as the default currency for anything this user does.

于 2013-10-22T13:47:29.943 回答