Odoo 如何使用context

2021-10-10 09:09:40 字數 2586 閱讀 8118

"partner_id" string=

"customer"

widget=

"res_partner_many2one"

context=

""groups=

"base.group_no_one"

/>

context 這是乙個上下文,運用很靈活:

self.context_get(

)

self.env.context.get(

'flag'

,false

)

self.with_context(

) 或

self.with_context(flag=

true

) 單一時 或

ctx =

dict

(context or

)

ctx[

'flag']=

false

self.with_context(ctx)

context =

dict

(context or

)

c = context.copy(

)

主要改變部分值,帶到其它函式中

context =

if part.lang:       

self = self.with_context(lang=part.lang)

product = self.env[

'product.product'

].browse(product)--

----

return self.with_context(ctx)

.write(

)

記住,用了 with_context

context   model=

"ir.actions.act_window"時

代表 搜尋時my_expert_list值為1

對於search_default_是系統的前置標識

設定值:獲取表單中的字段:【欄位1、欄位2】

self.with_context(

)

獲取值:

self._context.get(

'欄位1'

)

案例:

@api.multi

def_compute_price_rule

(self, products_qty_partner, date=

false

, uom_id=

false):

""" low-level method - mono pricelist, multi products

returns: dict

if date in context: date of the pricelist (%y-%m-%d)

:param products_qty_partner: list of typles products, quantity, partner

:param datetime date: validity date

:param id uom_id: intermediate unit of measure

"""self.ensure_one()if

not date:

date = self._context.get(

'date'

)or fields.date.context_today(self)

ifnot uom_id and self._context.get(

'uom'):

uom_id = self._context[

'uom'

]if uom_id:

# rebrowse with uom if given

products =

[item[0]

.with_context(uom=uom_id)

for item in products_qty_partner]

products_qty_partner =

[(products[index]

, data_struct[1]

, data_struct[2]

)for index, data_struct in

enumerate

(products_qty_partner)

]else

: products =

[item[0]

for item in products_qty_partner]

ifnot products:

return

odoo 開發 context 上下文的用法

context 這是乙個上下文,運用很靈活 得到整個context self.context get self.env res.users context get 得到context裡面對應的值 得到flag的值 self.env.context.get flag false 修改context裡面...

odoo8開發筆記 context上下文

context 這是乙個上下文,運用很靈活 得到整個context self.context get self.env res.users context get 得到context裡面對應的值 得到flag的值 self.env.context.get flag false 修改context裡面...

odoo 使用xp系統訪問odoo頁面

最近部署完odoo服務,客戶使用xp 系統訪問odoo頁面,會出現不能進入主介面,直接卡在登入頁面 正常情況下使用原生的odoo模組,使用xp系統訪問不會有這樣的問題,但是安裝了某些高階的三方模組,裡邊使用了某些高階的css和js語法,但是xp 系統不能安裝最新版本的瀏覽器 比如谷歌 會導致某些高階...