Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
3535 Vizualizări

Hi ,im on odoo 17, i want to call a controller method from "import_action.js" but i have this error : 

TypeError: this._rpc is not a function
    at ImportAction.handleImport (http://localhost:8069/web/assets/2ac37e4/web.assets_web.min.js:16212:142)

js : 
if (!isTest && res.ids.length) {
this.notification.add(_t("%s records successfully imported", res.ids.length), {
type: "success"
});
var self = this;
this._rpc({
route: '/bp/imported_checklists',
params: { checklist_records: res.ids }
}).then(function () {
self.exit(res.ids);
});
}


py:

@http.route('/bp/imported_checklists', website=True, auth='public', csrf=False)
def get_data(self, **kw):
res_ids = kw.get('res_ids')
if res_ids:
query_1 = """SELECT id FROM bp_cdc WHERE imported_checklist=True ORDER BY id LIMIT 1"""
http.request.env.cr.execute(query_1)
result_query_1 = http.request.env.cr.fetchone()
if result_query_1:
cdc_id = result_query_1[0]
query_2 = """UPDATE bp_checklist SET checklist_id=%s WHERE id IN %s"""
http.request.env.cr.execute(query_2, (cdc_id, tuple(res_ids)))
query_3 = """UPDATE bp_cdc SET imported_checklist=False WHERE id IN %s"""
http.request.env.cr.execute(query_3,cdc_id)
return {'success': True, 'message': 'Checklist updated successfully'}
else:
return {'error': 'No CDC record with imported_checklist=True found'}
else:
return {'error': 'No res_ids provided'}  

Imagine profil
Abandonează
Cel mai bun răspuns

$.ajax({

                url: "/your/controller",

                data: {'key' :value},

                cache: false,

                dataType:'json',

                success: function(data){ console.log(data) }

});

Try this method.

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

Please refer to our blog given below to understand how to call controller from js

How to Call Controller Method from Javascript


Hope it helps

Imagine profil
Abandonează
Cel mai bun răspuns

You can try this

Imagine profil
Abandonează

# my_module/controllers/main.py

from odoo import http

from odoo.http import request

class MyController(http.Controller):

@http.route('/my_module/get_data', type='json', auth='public', methods=['POST'], csrf=False)

def get_data(self):

# Sample data to return

data = {'message': 'Hello from Odoo Controller!'}

return data
Source: https://t-rexgame.io

Cel mai bun răspuns

You can take a look at https://github.com/odoo/odoo/blob/b9f0f3676a9409a991ff8bd3d06ba4ace8d567e8/addons/hr_attendance/static/src/components/attendance_menu/attendance_menu.js#L36

Just search the source code of odoo 17 and you will find a lot of these

Hope this help sir.


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
4
mai 25
8601
2
dec. 24
5990
3
apr. 24
5482
1
ian. 24
3605
0
iun. 21
3103