Hi,
It is possible to create a record from a js file. There are two ways to do it.
You can use rpc.query or ajax.jsonRpc.
Using rpc.query, you can define a model and a method inside the model and pass arguments as required to it. The method will be triggered and you can get the value returned by the python function in the .then method of js.
Example
var rpc = require('web.rpc');
rpc.query({
model: 'your_model',
method: 'your_function',
args: [arguments],
}).then(function(result) {
// result will have the value returned from python function.
});
Using ajax.jsonRpc, you can define a route to which the call will be passed. The route will be of type json.
var ajax = require('web.ajax');
ajax.jsonRpc('/route_name',
'call',{'arg_1': arg_1_value, 'arg_2': arg_2_value})
.then(function (result) {
// result will have the value returned from the python controller.
});
In python,
@route(['/route_name'], type='json', auth='your_authentication')
def route_name(self, **kwargs):
return True
Regards