コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
2479 ビュー

Hi,

I'm using Odoo ONLINE and I need to add the possibility for a user to upload files from a Survey.

It's seems that we can't use Odoo Apps to satisfy the quest but maybe we can counter this situation by collecting the file's input datas with a JS script and send it to store the files in the ir.attachments module and link his ID to the corresponding survey module.


IS IT POSSIBLE TO CREATE A NEW RECORD FROM A JS FILE ? IF SO, HOW ?


Yours faithfully,

RANDRIATAVY Mandresy

アバター
破棄
最善の回答

Yes, you can call python function with js rpc query and you can pass arguments to the python function.

Example :

rpc.query({
model: 'your.model,
method: 'your_function_name',
args: [agr1, arg2],
}).then(function(result) {

//after success

});

アバター
破棄
著作者

Thanks you I’ll try

最善の回答

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

アバター
破棄
著作者

Thanks for the detailed answer, sounds Aravind was right too.

関連投稿 返信 ビュー 活動
0
7月 24
656
12
1月 16
35080
1
2月 24
1439
0
7月 23
1554
1
6月 23
1346