在 openerp 中,
data = self.read(cr, uid, ids, [], context=context)[0]
odoo 8 中的上述等同声明是什么。当我使用下面的陈述时,我得到了错误的结果。
data = self.with_context(context).browse(self.ids)[0]
我是 odoo 8 的新手,请帮助我...
答案 0 :(得分:2)
我常常很懒,只是使用V7 api。它仍然可以正常工作。
@api.v8
def function_i_want_to_edit_that_uses_v8_api(self):
# omg where are my cr and uid objects
# oh... i can just smuggle :-P
data = self.browse(self._cr, self._uid, self._ids, context=self._context)
但这也应该有效:
@api.v8
def function_i_want_to_edit_that_uses_v8_api(self):
data = self.browse(self._ids)
也许唯一的问题是缺少_
?还要确保您使用它的任何功能都是启用v8的,例如。用@api.v8
或类似的装饰。
答案 1 :(得分:0)
以下是 odoo v7 中浏览和阅读方法的示例,该方法从按钮调用。
def call_button(self, cr, uid, ids, context=None):
if not context: context = {}
for rec in self.browse(cr, uid, ids, context=context):
print rec.name
'''or '''
for rec in self.read(cr, uid, ids, context=context):
print rec.get('name')
如果你需要在 odoo v8 中编写相同的方法,你可以这样写,
@api.one
def call_button(self):
print self # which will return you a record set using you can directly access fields and method of that model
print self.read() # which will return you a list of dictionary
如果您想传递上下文,可以在您的环境中使用with_context
。
希望这会有所帮助。