I'm still learning how to properly add your own javascript code. I'm trying to add my own stuff into Odoo backend.
I was carefully reading "Building Interface Extensions" guide (https://www.odoo.com/documentation/10.0/howtos/web.html), but it is ether badly inaccurate or completely outdated.
After looking at Odoo official modules like Account, Project, CRM I've coded something like this:
odoo.define('rhp.main', function (require) {
"use strict";
var core = require('web.core');
var _t = core._t;
var _lt = core._lt;
var Widget = require('web.Widget');
var QWeb = core.qweb;
var Explorer = Widget.extend({
init: function(parent, options) {
console.log('Explorer inited');
},
start: function() {
console.log('Explorer started');
},
});
/* NONE OF THESE WORK OK */
//core.view_registry.add('exploreraction', Explorer);
//core.action_registry.add('exploreraction', function() { return new Explorer(); });
core.action_registry.add('exploreraction', 'rhp.main.Explorer');
//odoo.client_actions.add('exploreraction', Explorer);
/* "Main loaded" is successfully printed in console */
console.log("Main loaded");
return {
Explorer: Explorer,
};
});
My module xml data:
<record id="explorer_action" model="ir.actions.client">
<field name="name">Document Explorer</field>
<field name="tag">exploreraction</field>
<field name="target">main</field>
</record>
<menuitem name="Documents" id="main_docs" />
<menuitem name="Document Explorer" id="rhp_explorer" parent="rhp.main_docs" action="rhp.explorer_action"/>
This is my latest code and when I click the menu item nothing happens and I get this popup error:
TypeError: ClientWidget is not a function
Traceback pasted here https://pastebin.com/QLCaLwHC
=========================================
EDIT:
I added the template, like in Vishal Khichadiya's example:
<t t-name="exploreraction" >
<div id="exploreraction_div">
test
</div>
</t>
Action is now added this way:
core.action_registry.add('exploreraction', Explorer);
Now when I navigate to my menu item I'm now getting this error:
TypeError: this.__getterSetterInternalMap is undefined
New traceback here: https://pastebin.com/phrqXFkz
I am not familiar with Bounty and I have solution for this link_to_the_screenshot_of_desired_output. It will work fine.
Create your xml file in /module_name/static/src/xml/your_xml_file.xml and add the following code:
Create your css file in /module_name/static/src/css/your_css_file.css and add the following code:
Create your view's xml file in /module_name/views/your_xml_file_.xml and add the following code :
Add the following codes in manifest.py:
You need to design a Template by your self.
You'll find reference code in odoo it self for create template.
add you template file in manifest file as 'qweb': ["static/src/xml/my_template.xml"]
Examplea Template code:
create assets_backend.xml with your other xml files.
/view/assets_backend.xml --> Here you need to add javasscript file path.
I'm also new to Odoo and JS, and I have tried something and that is given below:
In your /static/src/xml/your_.xml file:
In your /views/your_.xml file:
In manifest.py:
It will work. Please try it.