This question has been flagged

I'm trying to call a client action with some JS functions on it, but no success.

My xml:
```
<data>
<record id="some_client_action" model="ir.actions.client">
<field name="name">check action</field>
<field name="tag">tag_test_name</field>
</record>

<menuitem id="menu_test_id"
name="Menu test"
action="some_client_action"
sequence="-100" groups="base.group_user"/>
</data>

<template id="some_template_id">
<t t-name="SomeTemplate">
<p>TEST</p>
</t>
</template>
```
```
odoo.define('my_module.my_js_file', function (require) {
"use strict";

var AbstractAction = require('web.AbstractAction');
var rpc = require('web.rpc');
var core = require('web.core');

var Test_Client = AbstractAction.extend({
template: 'SomeTemplate',

init: function() {
console.log("INIT FUNCTION")
})
core.action_registry.add('tag_test_name', Test_Client);

return Test_Client;
});
```
But when I click on the new menu that I've just created, the fallowing error shows up:
```
Uncaught TypeError: Cannot read property 'on' of undefined
http://localhost:8069/web/content/683-24d55fb/web.assets_common.js:3646
Traceback:
TypeError: Cannot read property 'on' of undefined
at http://localhost:8069/web/content/683-24d55fb/web.assets_common.js:3646:87
at Function._.each._.forEach (http://localhost:8069/web/content/683-24d55fb/web.assets_common.js:12:558)
at Class.on (http://localhost:8069/web/content/683-24d55fb/web.assets_common.js:3646:30)
at Class._startController (http://localhost:8069/web/content/937-e8af9cf/web.assets_backend.js:485:322)
at http://localhost:8069/web/content/937-e8af9cf/web.assets_backend.js:463:25
at http://localhost:8069/web/content/683-24d55fb/web.assets_common.js:802:681
at fire (http://localhost:8069/web/content/683-24d55fb/web.assets_common.js:796:299)
at Object.add [as done] (http://localhost:8069/web/content/683-24d55fb/web.assets_common.js:797:467)
at Array.<anonymous> (http://localhost:8069/web/content/683-24d55fb/web.assets_common.js:802:649)
at Function.each (http://localhost:8069/web/content/683-24d55fb/web.assets_common.js:62
```

And the console shows: INIT FUNCTION

Someone know how can I load the template?
I'm trying to load the template and also bring some information from python code by using rpc. I don't want to bring those information by using something like Qweb, I NEED to use JS.

Avatar
Discard
Best Answer

for the backend(/web) you have to register XML file in qweb section of a manifest file 
ref: https://github.com/odoo/odoo/blob/12.0/addons/web/__manifest__.py#L24

for the frontend(/website) it don't load qweb template implicitly even you define it in qweb section of a manifest file. you have to load it explicitly using loadXML 
ref: https://github.com/odoo/odoo/blob/12.0/addons/payment_stripe/static/src/js/stripe.js#L8

Avatar
Discard