yezyilomo / odoo-rest-api

Module which expose Odoo as a REST API
MIT License
209 stars 169 forks source link

calling model function #33

Closed bluemix closed 4 years ago

bluemix commented 4 years ago

I hope to update README.md to include how we can call the model's function.

I saw the controller.py file, and it has a

    @http.route(
        '/object/<string:model>/<string:function>', 
        type='json', auth='user', methods=["POST"], csrf=False)
    def call_model_function(self, model, function, **post):
        args = []
        kwargs = {}
        if "args" in post:
            args = post["args"]
        if "kwargs" in post:
            kwargs = post["kwargs"]
        model = request.env[model]
        result = getattr(model, function)(*args, **kwargs)
        return result

Thanks for your great repo/solution.

yezyilomo commented 4 years ago

Thanks @bluemix that would be very helpful, please do.

bluemix commented 4 years ago

has been updated and pull requested.