context 這是一個上下文,運用很靈活 得到整個context self.context_get()
self.env['res.users'].context_get() 得到context里面對應的值 得到flag的值 self.env.context.get('flag',False)
修改context里面的對應的值 self.with_context({'flag': False}) 或 self.with_context(flag=True) 單一時 或 ctx = dict(context or {}) ctx['flag']=False self.with_context(ctx)
保證context的字典類型 context = dict(context or {})
復制context c = context.copy() 主要改變部分值,帶到其它函數中
自己構造context context = {'flag':Fasle,'lang':'zh_cn'}
常規用法
帶入函數中
if part.lang:
self = self.with_context(lang=part.lang)
product = self.env['product.product'].browse(product)
------
return self.with_context(ctx).write({'invoice_line': []})
記住,用了 with_context
視圖中引入
context model="ir.actions.act_window"時 {"search_default_my_export_list":1}
代表 搜索時 my_expert_list 值為1 對於 search_default_是系統的前置標識