odoo 使用restfultAPI调用模型中的方法
模块中的说明文档没有提怎样使用API调用模型中的方法,,这里根据代码做一下讲解:
代码如下,路由设置如下:
_routes = ["/api/", "/api//", "/api///"] @validate_token @type="auth="none", methods=["PATCH"], csrf=False) def patch(self, model=None, id=None, action=None, **payload): """.""" try: _id = int(id) except Exception as e: return invalid_response( "invalid object id", "invalid literal %s for id with base " % id ) try: record = request.env[model].sudo().search([("id", "=", _id)]) _callable = action in [ method for method in dir(record) if callable(getattr(record, method)) ] if record and _callable: # action is a dynamic variable. getattr(record, action)() else: return invalid_response( "missing_record", "record object with id %s could not be found or %s object has no method %s" % (_id, model, action), 404, ) except Exception as e: return invalid_response("exception", e, 503) else: return valid_response("record %s has been successfully patched" % record.id)
从中可以看到,需要使用PATCH请求才能实现调用,并且url地址的格式:/api///
懂得,原来世界如此简单!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。