odoo 8中的方法读取声明
Method read declaration in odoo 8
在 openerp ,
data = self.read(cr, uid, ids, [], context=context)[0]
上面在odoo 8中的等效语句是什么?当我使用以下语句时,我得到了错误的结果。
data = self.with_context(context).browse(self.ids)[0]
我是 odoo 8 的新手,请帮助我...
这是 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
。
希望这对您有所帮助。
很多时候我很懒,就用 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
或类似的装饰。
在 openerp ,
data = self.read(cr, uid, ids, [], context=context)[0]
上面在odoo 8中的等效语句是什么?当我使用以下语句时,我得到了错误的结果。
data = self.with_context(context).browse(self.ids)[0]
我是 odoo 8 的新手,请帮助我...
这是 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
。
希望这对您有所帮助。
很多时候我很懒,就用 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
或类似的装饰。